Use Resources.load to access resources
or Resources.Load
classes. The following is the method of loading different types of resources: StreamReader
File
Text file:
Sound file:
TextAsset txtAsset = (TextAsset)Resources.Load("textfile", typeof(TextAsset)); string tileFile = txtAsset.text;
<像> Image file:
AudioClip audio = Resources.Load("soundFile", typeof(AudioClip)) as AudioClip;
<个> A single elf:
Texture2D texture = Resources.Load("textureFile", typeof(Texture2D)) as Texture2D;
<频> Video file (unity & gt; = 5.6):
Sprite sprite = Resources.Load("spriteFile", typeof(Sprite)) as Sprite;
<对> Game object prefabricated body:
Sprite[] sprites = Resources.LoadAll<Sprite>("spriteFile");
VideoClip video = Resources.Load("videoFile", typeof(VideoClip)) as VideoClip;
<游戏> Load 3D grid from the prefabricated body of the game:
GameObject prefab = Resources.Load("shipPrefab", typeof(GameObject)) as GameObject;
Resource path precautions
Mesh model = Resources.Load("yourModelFileName", typeof(Mesh)) as Mesh;
The resource path should be relative to the folder in the folder.
MeshFilter modelFromGameObject = Resources.Load("yourGameObject", typeof(MeshFilter)) as MeshFilter; Mesh loadedMesh = modelFromGameObject.sharedMesh;
When specifying the path in the <件> folder, use a positive slope (/) instead of the back slope ().
If you use a subfolder in a folder, use a positive slash to divide the subclase and file name.GameObject loadedObj = Resources.Load("yourGameObject"); GameObject object1 = Instantiate(loadedObj);
Assets
.txt file loading example Resources
Resources
and string formatting. Use the relative path "Resources/Metadata.txt" to be more concise and efficient. The above is the detailed content of How to Access Resources in Unity for HoloLens Development?. For more information, please follow other related articles on the PHP Chinese website!