Resources of Unity resource management

Resources is a special folder used to store resources loaded at runtime.

Various types of resource files can be placed in the Resources folder, such as textures, models, audio, prefabs, etc., and are generally used to store prefab and texture information.

Resources in this folder and its subfolders can be loaded and accessed through the API.

When we package, Unity will package the folder together, so using Resources will increase the size of our application to a certain extent.

Using Resources, loading resources mainly uses the following two syntaxes:

Resources.Load(string path);

Resources.Load<T>(string path);

Use method one to return an Object type, and use method two to return the specified type T. like:

//加载某种资源
Object obj = Resources.Load("Name");

// 加载纹理
Texture2D texture = Resources.Load<Texture2D>("DirectFileName/textureName");

// 加载预制体
GameObject prefab = Resources.Load<GameObject>("DirectFileName/prefabName");

// 加载音频
AudioClip audioClip = Resources.Load<AudioClip>("DirectFileName/audioName");

Guess you like

Origin blog.csdn.net/mr_five55/article/details/134892823