EditorIKPose.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace RootMotion.FinalIK
  5. {
  6. [CreateAssetMenu(fileName = "Editor IK Pose", menuName = "Final IK/Editor IK Pose", order = 1)]
  7. public class EditorIKPose : ScriptableObject
  8. {
  9. public Vector3[] localPositions = new Vector3[0];
  10. public Quaternion[] localRotations = new Quaternion[0];
  11. public bool poseStored
  12. {
  13. get
  14. {
  15. return localPositions.Length > 0;
  16. }
  17. }
  18. public void Store(Transform[] T)
  19. {
  20. localPositions = new Vector3[T.Length];
  21. localRotations = new Quaternion[T.Length];
  22. for (int i = 1; i < T.Length; i++)
  23. {
  24. localPositions[i] = T[i].localPosition;
  25. localRotations[i] = T[i].localRotation;
  26. }
  27. }
  28. public bool Restore(Transform[] T)
  29. {
  30. if (localPositions.Length != T.Length)
  31. {
  32. Debug.LogError("Can not restore pose (unmatched bone count). Please stop the solver and click on 'Store Default Pose' if you have made changes to character hierarchy.");
  33. return false;
  34. }
  35. for (int i = 1; i < T.Length; i++)
  36. {
  37. T[i].localPosition = localPositions[i];
  38. T[i].localRotation = localRotations[i];
  39. }
  40. return true;
  41. }
  42. }
  43. }