diff options
Diffstat (limited to 'JamHelper/Assets/JamUtils/Scripts/Smooth-Motion-in-Unity')
-rw-r--r-- | JamHelper/Assets/JamUtils/Scripts/Smooth-Motion-in-Unity/InterpolationObjectController.cs | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/JamHelper/Assets/JamUtils/Scripts/Smooth-Motion-in-Unity/InterpolationObjectController.cs b/JamHelper/Assets/JamUtils/Scripts/Smooth-Motion-in-Unity/InterpolationObjectController.cs index 9a83fe0..3b6c0de 100644 --- a/JamHelper/Assets/JamUtils/Scripts/Smooth-Motion-in-Unity/InterpolationObjectController.cs +++ b/JamHelper/Assets/JamUtils/Scripts/Smooth-Motion-in-Unity/InterpolationObjectController.cs @@ -1,11 +1,23 @@ +using System;
using System.Collections; using UnityEngine; [DisallowMultipleComponent] [DefaultExecutionOrder(ORDER_EXECUTION)] public class InterpolationObjectController : MonoBehaviour -{ - public const int ORDER_EXECUTION = InterpolationFactorController.ORDER_EXECUTION - 1; +{
+ [Flags]
+ public enum InterpolateType
+ {
+ None,
+ Position = 1,
+ Rotation = 1 << 1,
+ Scale = 1 << 2,
+ } + + public InterpolateType type; + + private const int ORDER_EXECUTION = InterpolationFactorController.ORDER_EXECUTION - 1; private TransformData[] _transforms; private int _index; @@ -44,9 +56,13 @@ public class InterpolationObjectController : MonoBehaviour private void RestoreActualTransform() { var latest = _transforms[_index]; - transform.localPosition = latest.position; - transform.localScale = latest.scale; - transform.localRotation = latest.rotation; + + if((type & InterpolateType.Position) != 0)
+ transform.localPosition = latest.position; + if ((type & InterpolateType.Scale) != 0)
+ transform.localScale = latest.scale; + if ((type & InterpolateType.Rotation) != 0)
+ transform.localRotation = latest.rotation; } private void SaveActualTransform() @@ -58,10 +74,13 @@ public class InterpolationObjectController : MonoBehaviour private void SetInterpolatedTransform() { var prev = _transforms[NextIndex()]; - float factor = InterpolationFactorController.Factor; - transform.localPosition = Vector3.Lerp(prev.position, transform.localPosition, factor); - transform.localRotation = Quaternion.Slerp(prev.rotation, transform.localRotation, factor); - transform.localScale = Vector3.Lerp(prev.scale, transform.localScale, factor); + float factor = InterpolationFactorController.Factor;
+ if ((type & InterpolateType.Position) != 0)
+ transform.localPosition = Vector3.Lerp(prev.position, transform.localPosition, factor);
+ if ((type & InterpolateType.Rotation) != 0)
+ transform.localRotation = Quaternion.Slerp(prev.rotation, transform.localRotation, factor);
+ if ((type & InterpolateType.Scale) != 0)
+ transform.localScale = Vector3.Lerp(prev.scale, transform.localScale, factor); } public void ResetTransforms() |