So I've been delving into mecanim a bit more, Ryan has some new animations for me to look at but i'll be lagging behind a bit on that - need to nail down some blending between combat and non combat camera mode here.
One aspect that seems to be taken care of is the ability to trap state transitions (start and end). This is a huge help because it means that reloads/pickups/firing/etc... can all have a state guard changed at the very start or finish of them, which allows me to keep things in sync fairly well. I'm still seeing some slop in that you can get stuck in a state of Firing - so working out these bugs before deploying a new webplayer. The resulting code for tonights herculean struggle with Mecanim looks as follows:
Basically the approach here is to poll for the current and next animation states. Since the mecanim API does not expose names, we use the name hashes. I've added a little "rules" string array that takes and maps all the events on the RHS to the name on the LHS. Normally this code will generate method names per state, something like:
Pistol_Draw = OnPistol_DrawStart( ) & OnPistol_DrawEnd( ).
You simply define those methods in one of the target transforms scripts and it will catch the event and away you go.
This can become quite onerous however with the number of state combinations you'll need to track, so the "rules" array lets you map multiple events to the same basic "name".
For example, if you go with :
Draw=Pistol_Draw,Rifle_Draw
The string above maps two states, Pistol_Draw and Rifle_Draw to a single method, Draw. Now in the target transforms script you can use the following:
OnDrawStart( ) & OnDrawEnd( ).
So far it's working well and supplements the other mecanim event library i'm using.
Anyhow, lots and lots of code refactoring and testing left to do here, getting swappable weapons in place started out easy enough but it soon became obvious if I wanted to minimize the amount of code and simplify things, some core framework was needed. I think that's over with now, it's just a matter of refining transitions and such ... and of course getting the updated animations in place :).
No comments:
Post a Comment