Unity3d Mecanim Animation System learning Note (10): Resource loading related to Mecanim animations

Source: Internet
Author: User

Resource loading is an essential point of knowledge, so here's how the Mecanim animation resources are packaged and loaded.

Note that the Assetbundle packaging strategy for unity4.x and unity5.x is different, and this note is packaged based on the assetbundle of unity4.x.

We generally use FBX type model and animation file, and animation file storage generally have two cases, one is all the animation and models are stored together into a file, there is another case is the model of a single file and animation of a separate file. Here we'll take a look at both of them.

The resources used are unity3d and the two types of animation resources taken from a textbook, and the corresponding animator Controller is created for their animations.

The case where the model animations are stored in a file

An FBX file preserves the model, bones, and animations, such as:

The following is the configured animator Controller:

It should be noted that the official does not provide an interface for setting up the animator controller for animator, so we have to load the configured Gameobject system as a prefab.

Resources loading
 1 using Unityengine; 2 using System.Collections;     3 4 public class Allinoneresourcesload:monobehaviour 5 {6 private Animator _animator; 7 8 void Start () 9 {Ten Gameobject go = resources.load<gameobject> ("Allinone/constructorprefab"); Gameobject man = Instantiate (GO) as gameobject;13 _animator = man. Getcomponent<animator> ();}15-void Ongui () + () (GUI. button (new Rect (0, 0, +), "Idle")) (_animator). Setbool ("Walk", false); _animator. Setbool ("Run", false);}23 if (GUI. button (new Rect (0, +, +), "Walk")) (_animator). Setbool ("Walk", true); _animator. Setbool ("Run", false);}28 if (GUI. button (new Rect (0, +, +), "Run")), {_animator. Setbool ("Walk", false); _animator. Setbool ("Run", true);}33 if (GUI. Button (New Rect (300, 0, 100), "Jump") (_animator). Settrigger ("Jump"); 36}37}38}
Assetbundle Loading Package
1 using Unityengine; 2 using Unityeditor; 3  4 public class Createallinoneab 5 {6     [MenuItem ("Tool/createallinoneab")] 7     private static void Create () 8< c5/>{9         buildpipeline.buildassetbundle (null, new[]10             {                 Assetdatabase.loadassetatpath ("assets/ Resources/allinone/constructorprefab.prefab ", typeof (Gameobject))             },13             Application.streamingassetspath + "/allinone.assetbundle",             buildassetbundleoptions.collectdependencies | Buildassetbundleoptions.completeassets | buildassetbundleoptions.uncompressedassetbundle,15             buildtarget.standalonewindows64);     }17}
Load
 1 using Unityengine; 2 using System.Collections;     3 4 public class Allinoneassetbundleload:monobehaviour 5 {6 private Animator _animator; 7 8 void Start () 9 {Assetbundle Assetbundle = assetbundle.createfromfile (Application.streamingassetspath + "/AllInOne.assetbundl E "); Gameobject go = Assetbundle.load (" Constructorprefab ", typeof (Gameobject)) as Gameobject;13 Ga Meobject mans = Instantiate (GO) as gameobject;15 _animator = man. Getcomponent<animator> ();}17-void Ongui (), (GUI. button (new Rect (0, 0, +), "idle")) {_animator. Setbool ("Walk", false); _animator. Setbool ("Run", false);}25 if (GUI. button (new Rect (0, +, +), "Walk")) (_animator). Setbool ("Walk", true); _animator. Setbool ("Run", false);}30 if (GUI.             button (new Rect (0, 32, +), "Run")) 31}_animator. Setbool ("Walk", false); _animator. Setbool ("Run", true);}35 if (GUI. button (new Rect (0, +, +), "Jump")) (_animator). Settrigger ("Jump"); 38}39}40}
The case where model animations are stored separately

Another scenario is that the model and animation are stored in multiple FBX files, such as the following model files:

Although there is a take 001 animation, but in fact we do not use the animation, but instead use the following only save the animation of the FBX file:

The following is the configured animator Controller:

In addition to not providing an interface to set up the animator controller, it is not possible to increase the deletion of an animated clip at run time, so we typically pack all of the dependencies together and package them all in the final analysis, or just a prepared prefab.

From this point of view, whether or not to split the animation is the ultimate way to use the same.

Resources loading
 1 using Unityengine; 2 using System.Collections; 3 4 public class Resourcesload:monobehaviour 5 {6 Private A Nimator _animator; 7 8 void Start () 9 {Gameobject go = resources.load<gameobject> ("Zombienurse/zombienurseprefab"); Gameobject man = Instantiate (go) as gameobject;13 _animator = man. Getcomponent<animator> ();}15-void Ongui () + () (GUI. button (new Rect (0, 0, +), "Idle")) (_animator). Setbool ("Run", false);}22 if (GUI. button (new Rect (0, +, +), "Run")) (_animator). Setbool ("Run", true);}26 if (GUI. button (new Rect (0, +, +), "attack")), {_animator. Settrigger ("attack");}30 if (GUI. button (new Rect (0, +,), "Dead")) (_animator). Settrigger ("dead");}34}35} 
Assetbundle Loading Package
1 using Unityeditor; 2 using Unityengine; 3  4 public class Createab 5 {6     [MenuItem ("Tool/createab")] 7     private static void Create () 8     {9         Build Pipeline.buildassetbundle (NULL, new[]10             {                 Assetdatabase.loadassetatpath ("Assets/resources/zombienurse /zombienurseprefab.prefab ", typeof (Gameobject))             },13             Application.streamingassetspath +"/ Ab.assetbundle ",             buildassetbundleoptions.collectdependencies | Buildassetbundleoptions.completeassets | buildassetbundleoptions.uncompressedassetbundle,15             buildtarget.standalonewindows64);     }17}
Load
 1 using Unityengine; 2 using System.Collections;         3 4 public class Assetbundleload:monobehaviour 5 {6 private Animator _animator; 7 8 void Start () 9 {10         Assetbundle Assetbundle = assetbundle.createfromfile (Application.streamingassetspath + "/AB.assetbundle"); 11 12  Gameobject go = Assetbundle.load ("Zombienurseprefab", typeof (Gameobject)) as gameobject;13 gameobject man = Instantiate (GO) as gameobject;15 _animator = man. Getcomponent<animator> ();}17-void Ongui (), (GUI. button (new Rect (0, 0, +), "idle")) {_animator. Setbool ("Run", false);}24 if (GUI. button (new Rect (0, +, +), "Run")) (_animator). Setbool ("Run", true);}28 if (GUI. button (new Rect (0, +, +), "attack")), {_animator. Settrigger ("attack");}32 if (GUI.     button (new Rect (0, 33, +), "dead"))    {_animator. Settrigger ("dead"); 35}36}37}

Unity3d Mecanim Animation System learning Note (10): Resource loading related to Mecanim animations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.