OVRLipSyncContext.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using UnityEngine;
  3. [RequireComponent(typeof(AudioSource))]
  4. public class OVRLipSyncContext : OVRLipSyncContextBase
  5. {
  6. public override void Init()
  7. {
  8. base.Init();
  9. }
  10. private void Update()
  11. {
  12. this.micSensitivity = GameMain.Instance.LipSyncMgr.Variable.MicSensitivity;
  13. this.audioMute = GameMain.Instance.LipSyncMgr.Variable.Mute;
  14. this.micVolume = GameMain.Instance.LipSyncMgr.Variable.MicVolume;
  15. }
  16. private void OnAudioFilterRead(float[] data, int channels)
  17. {
  18. if (OVRLipSync.IsInitialized() != OVRLipSync.Result.Success || this.audioSource == null)
  19. {
  20. return;
  21. }
  22. for (int i = 0; i < data.Length; i++)
  23. {
  24. data[i] *= this.micSensitivity;
  25. }
  26. lock (this)
  27. {
  28. if (base.Context != 0u)
  29. {
  30. OVRLipSync.Flags flags = OVRLipSync.Flags.None;
  31. if (this.delayCompensate)
  32. {
  33. flags |= OVRLipSync.Flags.DelayCompensateAudio;
  34. }
  35. OVRLipSync.Frame frame = base.Frame;
  36. OVRLipSync.ProcessFrameInterleaved(base.Context, data, flags, frame);
  37. }
  38. }
  39. if (this.audioMute)
  40. {
  41. for (int j = 0; j < data.Length; j++)
  42. {
  43. data[j] *= 0f;
  44. }
  45. }
  46. else
  47. {
  48. for (int k = 0; k < data.Length; k++)
  49. {
  50. data[k] *= this.micVolume;
  51. }
  52. }
  53. }
  54. [SerializeField]
  55. private float micSensitivity = 10f;
  56. [SerializeField]
  57. private bool audioMute;
  58. [SerializeField]
  59. private float micVolume;
  60. [SerializeField]
  61. [Header("遅延対応")]
  62. private bool delayCompensate = true;
  63. }