[Daily development of Unity3D] Loading analysis of different directories of Unity3D Resources

Recommended reading

Hello everyone, I am a Buddhist engineer ☆The Quiet Little Magic Dragon☆ . I update Unity development skills from time to time. If you find it useful, please remember to click three times.

I. Introduction

xdm, Happy National Day. I will study for a while and share a little bit of knowledge with everyone.

ResourcesEveryone should be familiar with the directory. This is a special folder of Unity3D, used to load files.

When building a project, Resourcesall resources and objects in the directory are merged into a serialized file that contains metadata and index information. The index contains a serialized lookup tree that is used to convert the name of a given object. Resolves to its appropriate file GUID and local ID. In this way, it AssetBundleis somewhat similar to .

ResourcesIt is very simple to use, just put the file Resourcesin the folder and then use Resourcesl.Loadload, for example:

void Start()
{
    
    
	Resources.Load("Test");
}

Of course, there are many points to pay attention to when loading, such as backslashes, file types, file suffixes, increased startup time and build time of the application, and the inability to incrementally update, etc.

However, what we are going to discuss today is Resourcesthe loading of folders in different directories.

2. ResourcesLoading in different directories

2-1. Explain before starting

You may ask, Resourcescan it be loaded in other directories? ResourcesWhy put it in different directories?

①Folders Resourcescan also be used in other directories. EditorSimilar to folders, it will be fine if placed in other directories. As long as the file name is this, it can be loaded.

②Why should we put them in different directories? Because if there are multiple colleagues working together on a project, it is inconvenient to manage all the files in the root directory Resourcesbecause we don’t know if other files in this folder are useful. Don't even dare to delete it.

ResourcesCloser to home, how to load files in different directories ?

Resources2-1. Loading in different directories

For example, if two colleagues, H and Z, develop the same project and are responsible for developing different scenarios, they each create their own folder in the root directory, and then create a directory under the folder, for example: Scripts in their own folder
Insert image description here
. In the folder, create a new script ReLoadTest.cs. Double-click to open the script and edit the code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ReLoadTest : MonoBehaviour
{
    
    
    // Start is called before the first frame update
    void Start()
    {
    
    
        string info = Resources.Load<TextAsset>("loadZ").text;
        Debug.Log(info);
    }

    // Update is called once per frame
    void Update()
    {
    
    

    }
}

Create a loadZ.txt file and type in any content:
Insert image description here
Run the program:
Insert image description here
I can also load the contents of the Resources folder in other directories (note the name of the loaded file):

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ReLoadTest : MonoBehaviour
{
    
    
    // Start is called before the first frame update
    void Start()
    {
    
    
        string info = Resources.Load<TextAsset>("loadH").text;
        Debug.Log(info);
    }

    // Update is called once per frame
    void Update()
    {
    
    

    }
}

operation result:
Insert image description here

3. Postscript

If you find this article useful, don't forget to click "Follow" to avoid getting lost and continue to share more useful articles about Unity.


Your likes are support for the blogger. If you have any questions, please leave a message:

The blogger’s homepage has contact information.

The blogger also has many treasure articles waiting for you to discover:

Column direction Introduction
Unity3D develops small games Mini game development tutorial Share some small games developed using the Unity3D engine and share some tutorials on making small games.
Unity3D from entry to advanced getting Started Get inspiration from self-study Unity, summarize the route of learning Unity from scratch, and have knowledge of C# and Unity.
Unity3D UGUI UGUI A full analysis of Unity's UI system UGUI, starting from the basic controls of UGUI, and then comprehensively teaching the principles and use of UGUI.
Reading data in Unity3D file reading Use Unity3D to read txt documents, json documents, xml documents, csv documents, and Excel documents.
Unity3D data collection data collection Array collection: Knowledge sharing on data collections such as arrays, Lists, dictionaries, stacks, and linked lists.
Unity3D VR/AR (virtual simulation) development virtual reality Summarize the common virtual simulation needs of bloggers and explain them with cases.
Unity3D plug-in plug-in Mainly share some plug-in usage methods used in Unity development, plug-in introduction, etc.
Daily development of Unity3D daily records Mainly used by bloggers in daily development, including methods and techniques, development ideas, code sharing, etc.
Unity3D daily BUG daily records Record the bugs and pitfalls encountered during project development using the Unity3D editor so that future generations can have some reference.

Guess you like

Origin blog.csdn.net/q764424567/article/details/133496005