Пример #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();
                    }
                }
            }
        }
Пример #2
0
        public override void StopListening(GraphStack stack)
        {
            base.StopListening(stack);

            T currentVoidEvent = Flow.FetchValue <T>(_event, stack.ToReference());

            currentVoidEvent?.Unregister(_eventRaisedHandler);
        }
Пример #3
0
        public override void StopListening(GraphStack stack)
        {
            base.StopListening(stack);
            var data      = stack.GetElementData <Data>(this);
            var reference = stack.ToReference();
            Action <string, string> handler = (_storyOptionsName, eventName) => TriggerOption(reference, _storyOptionsName, eventName);

            data.handler = handler;
            dh           = handler;
        }
Пример #4
0
        public override void StartListening(GraphStack stack)
        {
            //m_machine = stack.machine;
            m_graphReference = stack.ToReference();

            if (startOn && AttemptRegister(Flow.New(graphReference)))
            {
                base.StartListening(stack);
            }
        }
Пример #5
0
    public void StartListening(GraphStack stack)
    {
        var data = stack.GetElementData<Data>(this);
        if (data.UpdateAction != null) return;

        var reference = stack.ToReference();
        data.UpdateAction = args => OnUpdate(reference);

        var hook = new EventHook(EventHooks.Update, stack.machine);
        EventBus.Register(hook, data.UpdateAction);
    }
        public override void StartListening(GraphStack stack)
        {
            base.StartListening(stack);
            var graphReference = stack.ToReference();

            var pi          = Flow.FetchValue <PlayerInput>(Target, graphReference);
            var inputAction = Flow.FetchValue <InputAction>(InputAction, graphReference);

            if (inputAction == null)
            {
                return;
            }
            m_Action = pi
                ? pi.actions.FindAction(inputAction.id)
                : inputAction.actionMap != null ? inputAction : null;
        }
Пример #7
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;
        }
Пример #8
0
        public override void StartListening(GraphStack stack)
        {
            base.StartListening(stack);

            Flow flow         = Flow.New(stack.ToReference());
            T    currentEvent = flow.GetValue <T>(_event);

            _eventRaisedHandler = (value) =>
            {
                flow.Invoke(trigger);
                _currentValue = value;
            };

            if (currentEvent)
            {
                currentEvent.Unregister(_eventRaisedHandler);
                currentEvent.Register(_eventRaisedHandler);
            }
        }
Пример #9
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;
        }
Пример #10
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);
                }
            }
        }