Ejemplo n.º 1
0
 private void OnActorEvent(ActorEvent evt)
 {
     if (target != null)
     {
         target.gameObject.SetActive(true);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Called when a callback is registered
        /// </summary>
        /// <param name="eventType">type of event being registered</param>
        protected virtual void OnCallbackRegistered(Type eventType)
        {
            if (eventType == typeof(ActorUpdateEvent))
            {
                flags |= Flags.SendUpdateEvent;
            }
            else if (eventType == typeof(ActorFixedUpdateEvent))
            {
                flags |= Flags.SendFixedUpdateEvent;
            }

            // Start the update coroutine if needed
            if (updateCoroutine == null && isActiveAndEnabled && IsUpdateCallbackRegistered)
            {
                updateCoroutine = StartCoroutine(UpdateCoroutine());
            }

            // Start the fixed coroutine if needed
            if (fixedUpdateCoroutine == null && isActiveAndEnabled && IsFixedUpdateCallbackRegistered)
            {
                fixedUpdateCoroutine = StartCoroutine(FixedUpdateCoroutine());
            }

            Send(ActorEvent.Singleton <CallbackRegisteredEvent>().Init(eventType));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Send an event to the all registered actor components
        /// </summary>
        /// <param name="evt">Event to send</param>
        public void Send(ActorEvent evt)
        {
            if (null == handlers)
            {
                return;
            }

            evt.IsHandled = false;

            // Generate a temporary list of all event handlers for the given event.  This is
            // done to allow the handler table to be modified during a send event
            var eventHandlers = handlersPool.Get();
            var eventType     = evt.GetType();

            foreach (var handler in handlers)
            {
                if (handler.eventType == eventType || handler.eventType == typeof(ActorEvent))
                {
                    eventHandlers.Add(handler);
                }
            }

            // Send the envent to each of the matching event handlers.
            for (var handlerIndex = 0; !evt.IsHandled && handlerIndex < eventHandlers.Count; handlerIndex++)
            {
                var handler = eventHandlers[handlerIndex];
                if (handler.component != null && handler.component.isActiveAndEnabled)
                {
                    handler.callback.Invoke(handler.component, evt);
                }
            }

            eventHandlers.Clear();
            handlersPool.Release(eventHandlers);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Send an event to all handlers on the parent actor
 /// </summary>
 protected void Send(ActorEvent evt)
 {
     if (actor != null)
     {
         actor.Send(evt);
     }
 }
        private void OnActorEvent(ActorEvent evt)
        {
            if (evt.GetType() != _event.Type)
            {
                return;
            }

            AudioManager.Instance.Play(_clip);
        }
Ejemplo n.º 6
0
        private IEnumerator UpdateCoroutine()
        {
            while (isActiveAndEnabled && IsUpdateCallbackRegistered)
            {
                yield return(updateWait);

                Send(ActorEvent.Singleton <ActorUpdateEvent>().Init(Time.deltaTime));
            }

            updateCoroutine = null;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Call to handle an event by callin the handlers callback if available
        /// </summary>
        /// <param name="evt">Event to handle</param>
        internal void HandleEvent(ActorEvent evt)
        {
            var eventType = evt.GetType();

            foreach (var handler in info.handlers)
            {
                if (handler.eventType == eventType)
                {
                    handler.callback.Invoke(this, evt);
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Called when a callback for a given event type is unregistered
        /// </summary>
        /// <param name="eventType">type of event being unregistered</param>
        protected virtual void OnCallbackUnregistered(Type eventType)
        {
            if (eventType == typeof(ActorUpdateEvent))
            {
                flags = HandlesEvent(eventType)?flags:(flags & ~Flags.SendUpdateEvent);
            }
            else if (eventType == typeof(ActorFixedUpdateEvent))
            {
                flags = HandlesEvent(eventType)?flags:(flags & ~Flags.SendFixedUpdateEvent);
            }

            Send(ActorEvent.Singleton <CallbackUnregisteredEvent>().Init(eventType));
        }
Ejemplo n.º 9
0
        private void OnActorEvent(ActorEvent evt)
        {
            if (!showUpdate && evt.GetType() == typeof(ActorUpdateEvent))
            {
                return;
            }
            if (!showFixedUpdate && evt.GetType() == typeof(ActorFixedUpdateEvent))
            {
                return;
            }

            Debug.Log($"{actor.name}: {evt}");
        }
Ejemplo n.º 10
0
        protected virtual void OnDisable()
        {
            if (null == actor)
            {
                return;
            }

            actor.UnregisterComponent(this);

            // Send out a callback unregistered event for each callback that was registered
            foreach (var handler in info.handlers)
            {
                actor.Send(ActorEvent.Singleton <CallbackUnregisteredEvent>().Init(handler.eventType));
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Generate collision event when the collision finishes
 /// </summary>
 /// <param name="other"></param>
 private void OnCollisionExit2D(Collision2D other)
 {
     Send(ActorEvent.Singleton <CollisionExitEvent>().Init(other.gameObject.GetComponent <Actor>()));
 }
Ejemplo n.º 12
0
 public abstract void Invoke(object target, ActorEvent evt);
Ejemplo n.º 13
0
 public static ActorEventType FromEvent(ActorEvent evt) => new ActorEventType
 {
     name = evt.GetType().FullName
 };
Ejemplo n.º 14
0
 public override void Invoke(object target, ActorEvent evt) => _invoke((TTarget)target, (TEvent)evt);