1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #pragma warning disable CS0649 // Field is never assigned to, and will always have its default value.
- using UnityEngine;
- namespace Animancer.Examples.FineControl
- {
-
-
-
-
- [AddComponentMenu(Strings.ExamplesMenuPrefix + "Fine Control - Low Update Rate")]
- [HelpURL(Strings.DocsURLs.ExampleAPIDocumentation + nameof(FineControl) + "/" + nameof(LowUpdateRate))]
- public sealed class LowUpdateRate : MonoBehaviour
- {
-
-
-
-
- [SerializeField] private AnimancerComponent _Animancer;
- [SerializeField] private float _UpdatesPerSecond = 10;
- private float _LastUpdateTime;
-
-
-
- private void OnEnable()
- {
- _Animancer.Playable.PauseGraph();
- _LastUpdateTime = Time.time;
- }
- private void OnDisable()
- {
-
-
- if (_Animancer != null && _Animancer.IsPlayableInitialized)
- _Animancer.Playable.UnpauseGraph();
- }
-
- private void Update()
- {
- var time = Time.time;
- var timeSinceLastUpdate = time - _LastUpdateTime;
- if (timeSinceLastUpdate > 1 / _UpdatesPerSecond)
- {
- _Animancer.Evaluate(timeSinceLastUpdate);
- _LastUpdateTime = time;
- }
- }
-
- }
- }
|