20 internal static void InitStatic()
22 CUI.OnDispose += () => ActiveAnimations.Clear();
25 public static HashSet<CUIAnimation> ActiveAnimations =
new();
29 internal static void UpdateAllAnimations(
double time)
37 public bool Debug {
get;
set; }
38 public static float StartLambda = 0.0f;
39 public static float EndLambda = 1.0f;
42 private object target;
61 if (
Blocked || active == value)
return;
64 if (active) ActiveAnimations.Add(
this);
65 else ActiveAnimations.Remove(
this);
75 get => 1.0 /
Speed * Timing.Step;
78 double steps = value / Timing.Step;
83 public double ReverseDuration
85 get => 1.0 / (BackSpeed ?? 0) * Timing.Step;
88 double steps = value / Timing.Step;
89 BackSpeed = 1.0 / steps;
104 public double Speed {
get;
set; } = 0.01;
105 public double? BackSpeed {
get;
set; }
110 public bool Repeat {
get;
set; }
119 public object EndValue {
get;
set; }
121 private string property;
122 private Action<object> setter;
123 private Type propertyType;
137 public event Action<CUIDirection> OnStop;
146 customInterpolate = value;
150 private Func<float, object> customInterpolate;
151 private Func<float, object> interpolate;
153 public Action<object> Convert<T>(Action<T> myActionT)
155 if (myActionT ==
null)
return null;
156 else return new Action<object>(o => myActionT((T)o));
160 private void UpdateSetter()
167 CUI.Warning($
"CUIAnimation couldn't find {Property} in {Target}");
171 propertyType = pi.PropertyType;
173 interpolate = customInterpolate ?? ((l) => CUIInterpolate.Interpolate[propertyType].Invoke(
StartValue, EndValue, l));
177 if (propertyType == typeof(
float))
179 setter = Convert<float>(pi.GetSetMethod()?.CreateDelegate<Action<float>>(
Target));
182 if (propertyType == typeof(Color))
184 setter = Convert<Color>(pi.GetSetMethod()?.CreateDelegate<Action<Color>>(
Target));
193 public void Start() => Active =
true;
226 private void UpdateState()
245 public void ApplyValue()
247 if (interpolate ==
null)
return;
248 object value = interpolate.Invoke((
float)
Lambda);
249 setter?.Invoke(value);
252 public void Step(
double time)
257 if (Debug) LogStatus();
260 public void LogStatus() => CUI.Log($
"Active:{Active} Direction:{Direction} Lambda:{Lambda}");