Game Development Reference
In-Depth Information
Coroutines
A coroutine can suspend its execution in one frame, then pick up and continue executing the
next frame, over any length of frames. When you call another function from within Update() or
FixedUpdate() functions, the function you call is run from start to finish each frame. At a 60fps frame
rate, this means the function is also called and executed 60 times per second. Often you don't need
a function called every frame, though you would like it run periodically. In comparison, a function
called every tenth of a second, which is still plenty fast for many game tasks, is called six times less
at 10 calls per second. This significant increase in efficiency can be achieved using coroutines.
Mecanim Optimization Tips
As with scripts, Unity's Scripting Reference provides general guidelines for making your Mecanim
animations more efficient (Table 12-1 ). Most of these go beyond the degree of difficulty covered in
this topic, but having this information available can help you with character design whether you are
creating them yourself or working with an artist.
Use hashes instead of strings to query the Animator.
Implement a small AI Layer to control the Animator. You can make it provide
simple callbacks for OnStateChange, onTransitionBegin, and so forth.
Use State tags to easily match your AI state machine to the Mecanim state
machine.
Use additional curves to simulate Events.
Use additional curves to mark up your animations (e.g., in conjunction with
target matching).
Runtime optimizations:
Always optimize animations by setting the animator's Culling Mode to Based on
Renderers, and disable the skinned mesh renderer's Update When Offscreen
property. This way animations won't be updated when the character is not visible.
An additional good practice in animation is using hash IDs. When working with
the animator, the use of hash identifiers is an optimizing method whereby names
of states and parameters are assigned to integers. The use of integers instead of
strings in turn reduces processing overhead.
If you are interested in digging deeper into Mecanim optimization, you can find more information in
the Unity Manual, http://docs.unity3d.com/Manual/MecanimPeformanceandOptimization.html .
 
Search WWH ::




Custom Search