Dowload as PDF

1.2. Event observers

All work with Callbacker Controller usually happens within classes that implement interface IEventObserver. To be more accurate, you need to implement either of two (or both, depending on the situtation) interfaces:

If registration of implementation of interface in the controller is done by hand, then class doesn't have to be inherited from MonoBehaviour. Also, the abstract class MonoCallbackerObserver already implements all necessary interfaces and by inheriting from it, you will get all functions, available to observers. Also, all components available to this type can be added to the list of automatically registered observers in the controllers interface.

  1. ICallbackerEventObserver – this interface lets you to track events of the initialization of the controller and its reset. This interface is the primary one for working with controller. It is assumed that at controllers initialization, implementation of this interface will create and/or get all necessary entities from controller for it to work, and will free them up and at reset.
  1. IAnimatorEventObserver – unlike the first interface, this interface helps to track "raw" events happening in Mecanim Animator. In most cases we recommend to use ICallbackerEventObserver and entities of the controller, but sometimes it could be useful to get unprocessed data.

You can add and delete observers in runtime, for this controller has two methods: AddObserver and RemoveObserver. Due to the pecularities of processing, IAnimatorEventObserver is added and deleted not immediately after calling those methods, but during the next iteration of processing.

A bit more about OnAttach/OnDettach

While methods of IAnimatorEventObserver interface are pretty straightforward – an event happens in animator, observer calls corresponding method; then correct understating of ICallbackerEventObserver can affect how well and comfortably you can use MecanimCallbacker. This observer doesn't give information about events inside the animation, but rather tells when you can begin to subscribe to events of controllers entities, and when you need to unsubscribe and empty cached entities and data (when using pools).

OnAttach is called when controller began to work and is correctly initialized, if this observer was registered in it. If observer was added to already initialized controlled, then this method will be called during the next iteration of the event processing.

OnDetach will be called if observer was deleted from working controller, or if controller was disabled/destroyed/reset.

Methods of IAnimatorEventObserver are pretty straightforward – event happens in animator, observers call corresponding method. Correct understanding of ICallbackerEventObserver, however, is paramount to how correctly and easily you can use MecanimCallbacker. This observer doesn't give information about events inside animator, but rather, notifies when you can start subscribing to events of controller entities, and when you need to unsubscribe and clean cached entities and data (when using pools). So: OnAttach is called when controller started its work and is correctly initialized, if at that moment observer was registered in it. If observer was added to an already initialized controller, then this method will be called during the next iteration of event parsing. OnDetach will be called if observer was deleted from a working controller, or controller was disable/destroyed/reset.

Yes No
0 of 0 users found this section helpful
Suggest Edit