123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- using System.Collections.Generic;
- using UnityEngine;
- namespace Animancer
- {
-
-
-
-
-
-
-
-
-
-
-
- public class TimeSynchronizationGroup : HashSet<object>
- {
-
- private AnimancerComponent _Animancer;
-
-
-
-
-
- public AnimancerComponent Animancer
- {
- get => _Animancer;
- set
- {
- _Animancer = value;
- NormalizedTime = null;
- }
- }
-
-
- public float? NormalizedTime { get; set; }
-
-
- public TimeSynchronizationGroup(AnimancerComponent animancer) => Animancer = animancer;
-
-
-
-
-
- public bool StoreTime(object key) => StoreTime(key, Animancer.States.Current);
-
-
-
- public bool StoreTime(object key, AnimancerState state)
- {
- if (state != null && Contains(key))
- {
- NormalizedTime = state.NormalizedTime;
- return true;
- }
- else
- {
- NormalizedTime = null;
- return false;
- }
- }
-
-
-
-
-
- public bool SyncTime(object key) => SyncTime(key, Time.deltaTime);
-
-
-
-
- public bool SyncTime(object key, float deltaTime) => SyncTime(key, Animancer.States.Current, deltaTime);
-
- public bool SyncTime(object key, AnimancerState state) => SyncTime(key, state, Time.deltaTime);
-
- public bool SyncTime(object key, AnimancerState state, float deltaTime)
- {
- if (NormalizedTime == null ||
- state == null ||
- !Contains(key))
- return false;
-
-
- state.Time = NormalizedTime.Value * state.Length + deltaTime * state.EffectiveSpeed;
- return true;
- }
-
- }
- }
|