OVRLipSyncContextBase.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using UnityEngine;
  3. [RequireComponent(typeof(AudioSource))]
  4. public class OVRLipSyncContextBase : MonoBehaviour
  5. {
  6. public int Smoothing
  7. {
  8. set
  9. {
  10. OVRLipSync.SendSignal(this.context, OVRLipSync.Signals.VisemeSmoothing, value, 0);
  11. }
  12. }
  13. public uint Context
  14. {
  15. get
  16. {
  17. return this.context;
  18. }
  19. }
  20. protected OVRLipSync.Frame Frame
  21. {
  22. get
  23. {
  24. return this.frame;
  25. }
  26. }
  27. public virtual void Init()
  28. {
  29. if (!this.audioSource)
  30. {
  31. this.audioSource = base.GetComponent<AudioSource>();
  32. }
  33. lock (this)
  34. {
  35. if (this.context == 0u && OVRLipSync.CreateContext(ref this.context, this.provider) != OVRLipSync.Result.Success)
  36. {
  37. Debug.Log("OVRPhonemeContext.Start ERROR: Could not create Phoneme context.");
  38. }
  39. }
  40. }
  41. private void OnDestroy()
  42. {
  43. lock (this)
  44. {
  45. if (this.context != 0u && OVRLipSync.DestroyContext(this.context) != OVRLipSync.Result.Success)
  46. {
  47. Debug.Log("OVRPhonemeContext.OnDestroy ERROR: Could not delete Phoneme context.");
  48. }
  49. }
  50. }
  51. public OVRLipSync.Frame GetCurrentPhonemeFrame()
  52. {
  53. return this.frame;
  54. }
  55. public void SetVisemeBlend(int viseme, int amount)
  56. {
  57. OVRLipSync.SendSignal(this.context, OVRLipSync.Signals.VisemeAmount, viseme, amount);
  58. }
  59. public OVRLipSync.Result ResetContext()
  60. {
  61. return OVRLipSync.ResetContext(this.context);
  62. }
  63. public AudioSource audioSource;
  64. public OVRLipSync.ContextProviders provider;
  65. [SerializeField]
  66. private OVRLipSync.Frame frame = new OVRLipSync.Frame();
  67. private uint context;
  68. }