示例#1
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;
        }
示例#2
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;
        }
示例#3
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;
        }
示例#4
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);
                }
            }
        }
示例#5
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;
        }
示例#6
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);
        }