OVRLipSyncContextTextureFlip.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using UnityEngine;
  3. public class OVRLipSyncContextTextureFlip : MonoBehaviour
  4. {
  5. private void Start()
  6. {
  7. this.lipsyncContext = base.GetComponent<OVRLipSyncContextBase>();
  8. if (this.lipsyncContext == null)
  9. {
  10. Debug.Log("LipSyncContextTextureFlip.Start WARNING: No lip sync context component set to object");
  11. }
  12. }
  13. private void Update()
  14. {
  15. if (this.lipsyncContext != null && this.material != null)
  16. {
  17. OVRLipSync.Frame currentPhonemeFrame = this.lipsyncContext.GetCurrentPhonemeFrame();
  18. if (currentPhonemeFrame != null)
  19. {
  20. for (int i = 0; i < currentPhonemeFrame.Visemes.Length; i++)
  21. {
  22. this.oldFrame.Visemes[i] = this.oldFrame.Visemes[i] * this.smoothing + currentPhonemeFrame.Visemes[i] * (1f - this.smoothing);
  23. }
  24. this.SetVisemeToTexture();
  25. }
  26. }
  27. }
  28. private void SetVisemeToTexture()
  29. {
  30. int num = -1;
  31. float num2 = 0f;
  32. for (int i = 0; i < this.oldFrame.Visemes.Length; i++)
  33. {
  34. if (this.oldFrame.Visemes[i] > num2)
  35. {
  36. num = i;
  37. num2 = this.oldFrame.Visemes[i];
  38. }
  39. }
  40. if (num != -1 && num < this.Textures.Length)
  41. {
  42. Texture texture = this.Textures[num];
  43. if (texture != null)
  44. {
  45. this.material.SetTexture("_MainTex", texture);
  46. }
  47. }
  48. }
  49. public Material material;
  50. public Texture[] Textures = new Texture[OVRLipSync.VisemeCount];
  51. public float smoothing;
  52. private OVRLipSyncContextBase lipsyncContext;
  53. private OVRLipSync.Frame oldFrame = new OVRLipSync.Frame();
  54. }