123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- using System;
- using UnityEngine;
- public class OVRLipSyncContextMorphTarget : MonoBehaviour
- {
- public void Init(Maid maid)
- {
- if (this.skinnedMeshRenderer == null)
- {
- Debug.Log("LipSyncContextMorphTarget.Start WARNING: Please set required public components!");
- }
- this.lipsyncContext = base.GetComponent<OVRLipSyncContextBase>();
- if (this.lipsyncContext == null)
- {
- Debug.Log("LipSyncContextMorphTarget.Start WARNING: No phoneme context component set to object");
- return;
- }
- this.TargetMaid = maid;
- this.lipsyncContext.Smoothing = this.SmoothAmount;
- }
- private void Update()
- {
- if (!this.lipsyncContext)
- {
- return;
- }
- OVRLipSync.Frame currentPhonemeFrame = this.lipsyncContext.GetCurrentPhonemeFrame();
- if (currentPhonemeFrame == null)
- {
- return;
- }
- if (this.TargetMaid)
- {
- this.SetMaidKuchiPaku(currentPhonemeFrame);
- }
- else if (this.skinnedMeshRenderer != null)
- {
- this.SetVisemeToMorphTarget(currentPhonemeFrame);
- }
- }
- private void SetMaidKuchiPaku(OVRLipSync.Frame frame)
- {
- if (GameMain.Instance.CharacterMgr.IsBusy())
- {
- return;
- }
- this.TargetMaid.body0.Face.morph.boLipSync = true;
- this.TargetMaid.body0.Face.morph.LipSync1 = 0f;
- this.TargetMaid.body0.Face.morph.LipSync2 = 0f;
- this.TargetMaid.body0.Face.morph.LipSync3 = 0f;
- int num = 0;
- float num2 = -1f;
- for (int i = 0; i < OVRLipSync.VisemeCount; i++)
- {
- if (frame.Visemes[i] > 0.001f)
- {
- if (frame.Visemes[i] > num2 && i != 0)
- {
- num2 = frame.Visemes[i];
- num = i;
- }
- if (this.m_blendMorph)
- {
- this.TargetMaid.body0.Face.morph.LipSync1 += GameMain.Instance.LipSyncMgr.GetMorphData(i).LipSync1 * frame.Visemes[i];
- this.TargetMaid.body0.Face.morph.LipSync2 += GameMain.Instance.LipSyncMgr.GetMorphData(i).LipSync2 * frame.Visemes[i];
- this.TargetMaid.body0.Face.morph.LipSync3 += GameMain.Instance.LipSyncMgr.GetMorphData(i).LipSync3 * frame.Visemes[i];
- }
- }
- }
- if (!this.m_blendMorph)
- {
- this.TargetMaid.body0.Face.morph.LipSync1 = GameMain.Instance.LipSyncMgr.GetMorphData(num).LipSync1 * frame.Visemes[num];
- this.TargetMaid.body0.Face.morph.LipSync2 = GameMain.Instance.LipSyncMgr.GetMorphData(num).LipSync2 * frame.Visemes[num];
- this.TargetMaid.body0.Face.morph.LipSync3 = GameMain.Instance.LipSyncMgr.GetMorphData(num).LipSync3 * frame.Visemes[num];
- }
- this.m_nViseme = (OVRLipSync.Viseme)num;
- }
- private void SetVisemeToMorphTarget(OVRLipSync.Frame frame)
- {
- for (int i = 0; i < this.VisemeToBlendTargets.Length; i++)
- {
- if (this.VisemeToBlendTargets[i] != -1)
- {
- this.skinnedMeshRenderer.SetBlendShapeWeight(this.VisemeToBlendTargets[i], frame.Visemes[i] * 100f);
- }
- }
- }
- public SkinnedMeshRenderer skinnedMeshRenderer;
- public Maid TargetMaid;
- public int[] VisemeToBlendTargets = new int[OVRLipSync.VisemeCount];
- public bool enableVisemeSignals;
- public int[] KeySendVisemeSignal = new int[10];
- public int SmoothAmount = 100;
- [SerializeField]
- [Header("口パクを複数ブレンドするか")]
- private bool m_blendMorph = true;
- private OVRLipSyncContextBase lipsyncContext;
- [SerializeField]
- private OVRLipSync.Viseme m_nViseme;
- }
|