FKOffset.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace RootMotion.Demos
  5. {
  6. // Adds simple FK rotation offset to bones.
  7. public class FKOffset : MonoBehaviour
  8. {
  9. [System.Serializable]
  10. public class Offset
  11. {
  12. [HideInInspector] public string name;
  13. public HumanBodyBones bone;
  14. public Vector3 rotationOffset;
  15. private Transform t;
  16. public void Apply(Animator animator)
  17. {
  18. if (t == null) t = animator.GetBoneTransform(bone);
  19. if (t == null) return;
  20. t.localRotation *= Quaternion.Euler(rotationOffset);
  21. }
  22. }
  23. public Offset[] offsets;
  24. private Animator animator;
  25. private void Start()
  26. {
  27. animator = GetComponent<Animator>();
  28. }
  29. private void LateUpdate()
  30. {
  31. foreach (Offset offset in offsets)
  32. {
  33. offset.Apply(animator);
  34. }
  35. }
  36. private void OnDrawGizmosSelected()
  37. {
  38. foreach (Offset offset in offsets)
  39. {
  40. offset.name = offset.bone.ToString();
  41. }
  42. }
  43. }
  44. }