Preliminary finishing and learning Unity3d Resource loading method, estimated to take two days to complete the introductory learning
Unity3d Common Two load resource scenarios:resources.load and assetbundle
Resources.load is to load resources from a assetbundle in the default package.
While the general assetbundle file needs to be created yourself, the runtime dynamically loads and can specify the path and source. In fact, all the static objects in the scene also have such a loading process, but Unity backstage for you to automatically complete
A:resources.load: Use this method to load resources, first need to Create a folder named Resources under the Asset directory , This naming is the way the u3d , and then the resource file is put in,
of course, you can also Resources And, of course, you need to add the appropriate resource path when the code loads, and here's a simple Demo , two presets,
Cube and the Sphere , where Cube placed in Resource in the Prebs in, and Sphere placed in Resources under Directory, the following separately implements the loading of resources.load resources
Using Unityengine;
Using System.Collections;
public class Loadresdemo:monobehaviour {
private string Cubepath = "Prebs/mycubepreb";
private string Spherepath = "Myspherepreb";
void Start () {
Load Resources into memory
Object Cubepreb = Resources.load (Cubepath, typeof (Gameobject));
Using the loaded resource object, instantiate the game object, realize the dynamic loading of the game object.
Gameobject cube = Instantiate (Cubepreb) as Gameobject;
The following is a similar implementation of dynamic instantiation of sphere
Load Resources into memory
Object Spherepreb = Resources.load (Spherepath, typeof (Gameobject));
Using the loaded resource object, instantiate the game object, realize the dynamic loading of the game object.
Gameobject sphere = Instantiate (Spherepreb) as Gameobject;
}
}
Unity3d Resources.load Dynamically loading resources