OVRLipSyncContextBase.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. private OVRLipSync.Frame frame = new OVRLipSync.Frame();
  66. private uint context;
  67. }