diff options
author | chai <chaifix@163.com> | 2022-07-02 18:23:46 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2022-07-02 18:23:46 +0800 |
commit | f0f1d830651f3737030e258dc86b42a37baa1bca (patch) | |
tree | 386946c608ec02094c81253872e890615e0c3807 /JamHelper/Assets/Scripts/Smooth-Motion-in-Unity/InterpolationFactorController.cs | |
parent | e7e9156b0e4d180f8f9e291eb5ccfb08847e6269 (diff) |
* change directory
Diffstat (limited to 'JamHelper/Assets/Scripts/Smooth-Motion-in-Unity/InterpolationFactorController.cs')
-rw-r--r-- | JamHelper/Assets/Scripts/Smooth-Motion-in-Unity/InterpolationFactorController.cs | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/JamHelper/Assets/Scripts/Smooth-Motion-in-Unity/InterpolationFactorController.cs b/JamHelper/Assets/Scripts/Smooth-Motion-in-Unity/InterpolationFactorController.cs deleted file mode 100644 index efb96f3..0000000 --- a/JamHelper/Assets/Scripts/Smooth-Motion-in-Unity/InterpolationFactorController.cs +++ /dev/null @@ -1,58 +0,0 @@ -using UnityEngine; - -[DisallowMultipleComponent] -[DefaultExecutionOrder(ORDER_EXECUTION)] -public class InterpolationFactorController : MonoBehaviour -{ - public const int ORDER_EXECUTION = -1000; - - private static InterpolationFactorController Instance; - private float[] _lastFixedUpdates = new float[2]; - private int _lastIndex; - - public static float Factor { get; private set; } - - private void Awake() - { - if (Instance) - { - Destroy(this); - Debug.LogWarning($"The '{typeof(InterpolationFactorController).Name}' is a singleton!"); - return; - } - - Instance = this; - Factor = 1; - } - - private void Start() - { - _lastFixedUpdates = new float[2] { Time.fixedTime, Time.fixedTime }; - _lastIndex = 0; - } - - private void FixedUpdate() - { - _lastIndex = NextIndex(); - _lastFixedUpdates[_lastIndex] = Time.fixedTime; - } - - private void Update() - { - float lastTime = _lastFixedUpdates[_lastIndex]; - float prevTime = _lastFixedUpdates[NextIndex()]; - - if (lastTime == prevTime) - { - Factor = 1; - return; - } - - Factor = (Time.time - lastTime) / (lastTime - prevTime); - } - - private int NextIndex() - { - return (_lastIndex == 0) ? 1 : 0; - } -} |