示例#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();
     }
 }
示例#3
0
        public void StopListening(GraphStack stack)
        {
            stack.GetElementData <Data>(this).isListening = false;

            if (stack.TryEnterParentElement(this))
            {
                nest.graph.StopListening(stack);
                stack.ExitParentElement();
            }
        }
示例#4
0
        public void StartListening(GraphStack stack)
        {
            if (stack.TryEnterParentElement(this))
            {
                nest.graph.StartListening(stack);
                stack.ExitParentElement();
            }

            stack.GetElementData <Data>(this).isListening = true;
        }