/// <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)); }
private IEnumerator UpdateCoroutine() { while (isActiveAndEnabled && IsUpdateCallbackRegistered) { yield return(updateWait); Send(ActorEvent.Singleton <ActorUpdateEvent>().Init(Time.deltaTime)); } updateCoroutine = null; }
/// <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)); }
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)); } }
/// <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>())); }