Click to visit the official website Resources class
The Resources class allows objects such as resources to be looked up and accessed.
The function provides access to all assets in a folder named " ResourcesResources.Load
" located anywhere in the Assets folder . can existmany"Resources" folder, each folder is checked when loading objects.
To reclaim the resource's memory when it is no longer needed, you can use Resources.UnloadUnusedAssets .
**Note:** The Resources folder in Assets needs to be created before use. This folder is not created when a new project is created.
using UnityEngine;
public class ResourceLoadStu : MonoBehaviour
{
GameObject cubePrefab;
void Start()
{
// 通过路径加载资源
cubePrefab = Resources.Load<GameObject>("Cube");
Instantiate(cubePrefab);
}
}
● static functions
function | describe |
---|---|
FindObjectsOfTypeAll | Returns a list of all objects of type T. |
InstanceIDToObject | Convert an instance ID to an object reference. |
InstanceIDToObjectList | Convert an array of instance IDs to a list of object references. |
Load | Loads an asset of the requested type stored at path in the Resources folder. |
LoadAll | Loads all resources in the folder located at path in the Resources folder, or loads a file located there. |
LoadAsync | Asynchronously loads the resource stored at path in the Resources folder. |
UnloadAsset | Unloads the resource to be unloaded from memory. |
UnloadUnusedAssets | Unload unused resources. |