123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- using System;
- namespace Animancer
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public class ExitEvent : Key, IUpdatable
- {
-
- private Action _Callback;
- private AnimancerNode _Node;
-
-
-
-
-
-
-
-
- public static void Register(AnimancerNode node, Action callback)
- {
- #if UNITY_ASSERTIONS
- AnimancerUtilities.Assert(node != null, "Node is null.");
- AnimancerUtilities.Assert(node.IsValid, "Node is not valid.");
- #endif
- var exit = ObjectPool.Acquire<ExitEvent>();
- exit._Callback = callback;
- exit._Node = node;
- node.Root.RequirePostUpdate(exit);
- }
-
-
- public static bool Unregister(AnimancerPlayable animancer)
- {
- for (int i = animancer.PostUpdatableCount - 1; i >= 0; i--)
- {
- if (animancer.GetPostUpdatable(i) is ExitEvent exit)
- {
- animancer.CancelPostUpdate(exit);
- exit.Release();
- return true;
- }
- }
- return false;
- }
-
-
-
-
- public static bool Unregister(AnimancerNode node)
- {
- var animancer = node.Root;
- for (int i = animancer.PostUpdatableCount - 1; i >= 0; i--)
- {
- if (animancer.GetPostUpdatable(i) is ExitEvent exit &&
- exit._Node == node)
- {
- animancer.CancelPostUpdate(exit);
- exit.Release();
- return true;
- }
- }
- return false;
- }
-
- void IUpdatable.Update()
- {
- if (_Node.IsValid() && _Node.EffectiveWeight > 0)
- return;
- _Callback();
- _Node.Root.CancelPostUpdate(this);
- Release();
- }
-
- private void Release()
- {
- _Callback = null;
- _Node = null;
- ObjectPool.Release(this);
- }
-
- }
- }
|