RootMotionDeltaCompensation.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Spine.Unity;
  2. using UnityEngine;
  3. namespace Spine.Unity.Examples {
  4. public class RootMotionDeltaCompensation : MonoBehaviour {
  5. [SerializeField] protected SkeletonRootMotionBase rootMotion;
  6. public Transform targetPosition;
  7. public int trackIndex = 0;
  8. public bool adjustX = true;
  9. public bool adjustY = true;
  10. public float minScaleX = -999;
  11. public float minScaleY = -999;
  12. public float maxScaleX = 999;
  13. public float maxScaleY = 999;
  14. public bool allowXTranslation = false;
  15. public bool allowYTranslation = true;
  16. void Start () {
  17. if (rootMotion == null)
  18. rootMotion = this.GetComponent<SkeletonRootMotionBase>();
  19. }
  20. void Update () {
  21. AdjustDelta();
  22. }
  23. void OnDisable () {
  24. if (adjustX)
  25. rootMotion.rootMotionScaleX = 1;
  26. if (adjustY)
  27. rootMotion.rootMotionScaleY = 1;
  28. if (allowXTranslation)
  29. rootMotion.rootMotionTranslateXPerY = 0;
  30. if (allowYTranslation)
  31. rootMotion.rootMotionTranslateYPerX = 0;
  32. }
  33. void AdjustDelta () {
  34. Vector3 toTarget = targetPosition.position - this.transform.position;
  35. rootMotion.AdjustRootMotionToDistance(toTarget, trackIndex, adjustX, adjustY,
  36. minScaleX, maxScaleX, minScaleY, maxScaleY,
  37. allowXTranslation, allowYTranslation);
  38. }
  39. }
  40. }