NpcFaceShapeChanger.cs 932 B

1234567891011121314151617181920212223242526272829303132333435
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using WebTools.Customizes.Behaviours;
  5. public class NpcFaceShapeChanger : MonoBehaviour
  6. {
  7. [System.Serializable]
  8. public struct ShapeStruct
  9. {
  10. public BlendShapeType blendShapeType;
  11. public string blendShapeName;
  12. }
  13. [SerializeField]
  14. private List<ShapeStruct> shapes;
  15. [SerializeField]
  16. private List<Transform> targets;
  17. private List<BlendMesh> blends;
  18. private void OnEnable()
  19. {
  20. if (blends == null)
  21. {
  22. blends = new List<BlendMesh>();
  23. foreach (Transform target in targets)
  24. blends.AddRange(target.GetComponentsInChildren<BlendMesh>(true));
  25. }
  26. foreach(ShapeStruct shape in shapes)
  27. foreach (BlendMesh blend in blends)
  28. blend.SetBlendShapeWeight(shape.blendShapeType, shape.blendShapeName, 100);
  29. }
  30. }