OVRLipSyncContextMorphTarget.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System;
  2. using UnityEngine;
  3. public class OVRLipSyncContextMorphTarget : MonoBehaviour
  4. {
  5. public void Init(Maid maid)
  6. {
  7. if (this.skinnedMeshRenderer == null)
  8. {
  9. Debug.Log("LipSyncContextMorphTarget.Start WARNING: Please set required public components!");
  10. }
  11. this.lipsyncContext = base.GetComponent<OVRLipSyncContextBase>();
  12. if (this.lipsyncContext == null)
  13. {
  14. Debug.Log("LipSyncContextMorphTarget.Start WARNING: No phoneme context component set to object");
  15. return;
  16. }
  17. this.TargetMaid = maid;
  18. this.lipsyncContext.Smoothing = this.SmoothAmount;
  19. }
  20. private void Update()
  21. {
  22. if (!this.lipsyncContext)
  23. {
  24. return;
  25. }
  26. OVRLipSync.Frame currentPhonemeFrame = this.lipsyncContext.GetCurrentPhonemeFrame();
  27. if (currentPhonemeFrame == null)
  28. {
  29. return;
  30. }
  31. if (this.TargetMaid)
  32. {
  33. this.SetMaidKuchiPaku(currentPhonemeFrame);
  34. }
  35. else if (this.skinnedMeshRenderer != null)
  36. {
  37. this.SetVisemeToMorphTarget(currentPhonemeFrame);
  38. }
  39. }
  40. private void SetMaidKuchiPaku(OVRLipSync.Frame frame)
  41. {
  42. if (GameMain.Instance.CharacterMgr.IsBusy())
  43. {
  44. return;
  45. }
  46. this.TargetMaid.body0.Face.morph.boLipSync = true;
  47. this.TargetMaid.body0.Face.morph.LipSync1 = 0f;
  48. this.TargetMaid.body0.Face.morph.LipSync2 = 0f;
  49. this.TargetMaid.body0.Face.morph.LipSync3 = 0f;
  50. int num = 0;
  51. float num2 = -1f;
  52. for (int i = 0; i < OVRLipSync.VisemeCount; i++)
  53. {
  54. if (frame.Visemes[i] > 0.001f)
  55. {
  56. if (frame.Visemes[i] > num2 && i != 0)
  57. {
  58. num2 = frame.Visemes[i];
  59. num = i;
  60. }
  61. if (this.m_blendMorph)
  62. {
  63. this.TargetMaid.body0.Face.morph.LipSync1 += GameMain.Instance.LipSyncMgr.GetMorphData(i).LipSync1 * frame.Visemes[i];
  64. this.TargetMaid.body0.Face.morph.LipSync2 += GameMain.Instance.LipSyncMgr.GetMorphData(i).LipSync2 * frame.Visemes[i];
  65. this.TargetMaid.body0.Face.morph.LipSync3 += GameMain.Instance.LipSyncMgr.GetMorphData(i).LipSync3 * frame.Visemes[i];
  66. }
  67. }
  68. }
  69. if (!this.m_blendMorph)
  70. {
  71. this.TargetMaid.body0.Face.morph.LipSync1 = GameMain.Instance.LipSyncMgr.GetMorphData(num).LipSync1 * frame.Visemes[num];
  72. this.TargetMaid.body0.Face.morph.LipSync2 = GameMain.Instance.LipSyncMgr.GetMorphData(num).LipSync2 * frame.Visemes[num];
  73. this.TargetMaid.body0.Face.morph.LipSync3 = GameMain.Instance.LipSyncMgr.GetMorphData(num).LipSync3 * frame.Visemes[num];
  74. }
  75. this.m_nViseme = (OVRLipSync.Viseme)num;
  76. }
  77. private void SetVisemeToMorphTarget(OVRLipSync.Frame frame)
  78. {
  79. for (int i = 0; i < this.VisemeToBlendTargets.Length; i++)
  80. {
  81. if (this.VisemeToBlendTargets[i] != -1)
  82. {
  83. this.skinnedMeshRenderer.SetBlendShapeWeight(this.VisemeToBlendTargets[i], frame.Visemes[i] * 100f);
  84. }
  85. }
  86. }
  87. public SkinnedMeshRenderer skinnedMeshRenderer;
  88. public Maid TargetMaid;
  89. public int[] VisemeToBlendTargets = new int[OVRLipSync.VisemeCount];
  90. public bool enableVisemeSignals;
  91. public int[] KeySendVisemeSignal = new int[10];
  92. public int SmoothAmount = 100;
  93. [SerializeField]
  94. [Header("口パクを複数ブレンドするか")]
  95. private bool m_blendMorph = true;
  96. private OVRLipSyncContextBase lipsyncContext;
  97. [SerializeField]
  98. private OVRLipSync.Viseme m_nViseme;
  99. }