Ejemplo n.º 1
0
        public static void TriggerEventHandler <TArgs>(this GraphStack stack, Func <EventHook, bool> predicate, TArgs args, Func <IGraphParentElement, bool> recurse, bool force)
        {
            Ensure.That(nameof(stack)).IsNotNull(stack);

            GraphReference reference = null;

            foreach (var element in stack.graph.elements)
            {
                if (element is IGraphEventHandler <TArgs> handler)
                {
                    if (reference == null)
                    {
                        reference = stack.ToReference();
                    }

                    if (predicate == null || predicate.Invoke(handler.GetHook(reference)))
                    {
                        if (force || handler.IsListening(reference))
                        {
                            handler.Trigger(reference, args);
                        }
                    }
                }

                if (element is IGraphParentElement parentElement && recurse(parentElement))
                {
                    if (stack.TryEnterParentElementUnsafe(parentElement))
                    {
                        stack.TriggerEventHandler(predicate, args, recurse, force);
                        stack.ExitParentElement();
                    }
                }
            }
        }
 public void StopListening(GraphStack stack)
 {
     if (stack.TryEnterParentElement(this))
     {
         nest.graph.StopListening(stack);
         stack.ExitParentElement();
     }
 }
Ejemplo n.º 3
0
        public void StopListening(GraphStack stack)
        {
            foreach (var unit in units)
            {
                (unit as IGraphEventListener)?.StopListening(stack);
            }

            stack.GetGraphData <FlowGraphData>().isListening = false;
        }
Ejemplo n.º 4
0
        public void StartListening(GraphStack stack)
        {
            stack.GetGraphData <FlowGraphData>().isListening = true;

            foreach (var unit in units)
            {
                (unit as IGraphEventListener)?.StartListening(stack);
            }
        }
Ejemplo n.º 5
0
        public override void StartListening(GraphStack stack)
        {
            base.StartListening(stack);

            var data = stack.GetElementData <Data>(this);

            data.triggered = false;
            data.time      = 0;
        }
Ejemplo n.º 6
0
        public void StopListening(GraphStack stack)
        {
            stack.GetElementData <Data>(this).isListening = false;

            if (stack.TryEnterParentElement(this))
            {
                nest.graph.StopListening(stack);
                stack.ExitParentElement();
            }
        }
Ejemplo n.º 7
0
        public void StartListening(GraphStack stack)
        {
            if (stack.TryEnterParentElement(this))
            {
                nest.graph.StartListening(stack);
                stack.ExitParentElement();
            }

            stack.GetElementData <Data>(this).isListening = true;
        }
Ejemplo n.º 8
0
        public void StopListening(GraphStack stack)
        {
            var activeStates = GetActiveStatesNoAlloc(stack);

            foreach (var state in activeStates)
            {
                (state as IGraphEventListener)?.StopListening(stack);
            }

            activeStates.Free();

            stack.GetGraphData <StateGraphData>().isListening = false;
        }
Ejemplo n.º 9
0
        public void StopListening(GraphStack stack)
        {
            var data = stack.GetElementData <Data>(this);

            if (!data.isListening)
            {
                return;
            }

            var hook = new EventHook(EventHooks.Update, stack.machine);

            EventBus.Unregister(hook, data.update);
            data.update      = null;
            data.isListening = false;
        }
Ejemplo n.º 10
0
        public void StartListening(GraphStack stack)
        {
            var data = stack.GetElementData <Data>(this);

            if (data.isListening)
            {
                return;
            }

            var reference = stack.ToReference();
            var hook      = new EventHook(EventHooks.Update, stack.machine);
            Action <EmptyEventArgs> update = args => TriggerUpdate(reference);

            EventBus.Register(hook, update);
            data.update      = update;
            data.isListening = true;
        }
Ejemplo n.º 11
0
        public virtual void StartListening(GraphStack stack)
        {
            var data = stack.GetElementData <Data>(this);

            if (data.isListening)
            {
                return;
            }

            if (register)
            {
                var            reference = stack.ToReference();
                var            hook      = GetHook(reference);
                Action <TArgs> handler   = args => Trigger(reference, args);
                EventBus.Register(hook, handler);

                data.hook    = hook;
                data.handler = handler;
            }

            data.isListening = true;
        }
Ejemplo n.º 12
0
        private void UpdateTarget(GraphStack stack)
        {
            var data = stack.GetElementData <Data>(this);

            var wasListening = data.isListening;

            var newTarget = Flow.FetchValue <GameObject>(target, stack.ToReference());

            if (newTarget != data.target)
            {
                if (wasListening)
                {
                    StopListening(stack);
                }

                data.target = newTarget;

                if (wasListening)
                {
                    StartListening(stack, false);
                }
            }
        }
Ejemplo n.º 13
0
        public virtual void StopListening(GraphStack stack)
        {
            var data = stack.GetElementData <Data>(this);

            if (!data.isListening)
            {
                return;
            }

            // The coroutine's flow will dispose at the next frame, letting us
            // keep the current flow for clean up operations if needed
            foreach (var activeCoroutine in data.activeCoroutines)
            {
                activeCoroutine.StopCoroutine(false);
            }

            if (register)
            {
                EventBus.Unregister(data.hook, data.handler);
                data.handler = null;
            }

            data.isListening = false;
        }
Ejemplo n.º 14
0
        protected void StartListening(GraphStack stack, bool updateTarget)
        {
            if (updateTarget)
            {
                UpdateTarget(stack);
            }

            var data = stack.GetElementData <Data>(this);

            if (data.target == null)
            {
                return;
            }

            if (UnityThread.allowsAPI)
            {
                if (MessageListenerType != null) // can be null. CustomEvent doesn't need a message listener
                {
                    MessageListener.AddTo(MessageListenerType, data.target);
                }
            }

            base.StartListening(stack);
        }
Ejemplo n.º 15
0
 public GraphStack ToStackPooled()
 {
     return(GraphStack.New(this));
 }
Ejemplo n.º 16
0
 public override void StartListening(GraphStack stack)
 {
     StartListening(stack, true);
 }
Ejemplo n.º 17
0
 public void DisposePreservedStack(GraphStack stack)
 {
     stack.Dispose();
     preservedStacks.Remove(stack);
 }
Ejemplo n.º 18
0
 public void RestoreStack(GraphStack stack)
 {
     this.stack.CopyFrom(stack);
 }