Background
I've recently reached a bottle neck in my game's code that forced me to completely decouple the logic/networking from the graphics. Thanks to the nature of my board game, I was able to build the following architecture:
Logic update loop:
+--> wait for event -> process event -> dispatch graphic events --+
| |
+-----------------------------------------------------------------+
Graphics update loop:
+--> wait for event -> process event -> wait for animation --+
| |
+------------------------------------------------------------+
Question
From the previous design, tracking animation timing and knowing when they end is crucial, since that marks the end of the third phase in the graphics loop, allowing us to proceed to the next phase.
I'm using Unity, and I am not sure how to go about this. I am using Unity's animation system as well as LeanTween to perform animations on the 2D NGUI level as well as the 3d game scene level.
Proposed Solutions
Solutions that have occurred to me so far are:
Callbacks
Pass on a callback, and make the animation system trigger that callback when the animation finishes. This has proven to be high maintenance and redundant, as I have to manage passing data back and forth maintaining the overall animation state somehow (if multiple animations were triggered).
Global Monitor
Animations register under a global monitor, and I can emit a signal when the monitor becomes empty, triggering the end of the animations phase. I must make sure animations are registered immediately at the beginning of the animation phase, which I should be able to do. I should also maintain a list of animation IDs or a simple "anonymous" counter, which animations increment and decrement. Kinda like manual memory management. I might do this.
Any of those seem viable? Am I overlooking details about this system? Any better alternatives come to mind?