LipSyncController.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using UnityEngine;
  2. using System.Collections;
  3. public class LipSyncController : MonoBehaviour
  4. {
  5. public string targetName;
  6. public Transform nodeA;
  7. public Transform nodeE;
  8. public Transform nodeI;
  9. public Transform nodeO;
  10. public Transform nodeU;
  11. public AnimationCurve weightCurve;
  12. SkinnedMeshRenderer target;
  13. void Start()
  14. {
  15. target = GameObject.Find(targetName).GetComponent<SkinnedMeshRenderer>();
  16. }
  17. float GetWeight(Transform tr)
  18. {
  19. return weightCurve.Evaluate(tr.localPosition.z);
  20. }
  21. void LateUpdate()
  22. {
  23. var total = 100.0f;
  24. var w = total * GetWeight(nodeA);
  25. target.SetBlendShapeWeight(6, w);
  26. total -= w;
  27. w = total * GetWeight(nodeI);
  28. target.SetBlendShapeWeight(7, w);
  29. total -= w;
  30. w = total * GetWeight(nodeU);
  31. target.SetBlendShapeWeight(8, w);
  32. total -= w;
  33. w = total * GetWeight(nodeE);
  34. target.SetBlendShapeWeight(9, w);
  35. total -= w;
  36. w = total * GetWeight(nodeO);
  37. target.SetBlendShapeWeight(10, w);
  38. }
  39. }