How to find all type assets?

There are several instances of the ArmourType class in my Unity project (these are objects, objects for scripts). I am trying to show them in a dropdown in the inspector, and this works. However i use

List<ArmourType> armourTypes = Resources.FindObjectsOfTypeAll<ArmourType>(); 

to find all of these instances. It only finds objects that are loaded into memory, so sometimes it finds only some of the necessary assets. This is documented, so this is not a mistake, but very annoying from time to time.

So my question is: is there any other way to get all of these assets that return those that are not loaded into memory? Or is there perhaps a way to get Unity to load assets when they are searched for?

Note. I am using Unity5 and C #.

+6
source share
1 answer

Is this what you are looking for?

 string[] guids = AssetDatabase.FindAssets ("t:ArmourType", null); foreach (string guid in guids) { Debug.Log (AssetDatabase.GUIDToAssetPath(guid)); } 

http://docs.unity3d.com/ScriptReference/AssetDatabase.FindAssets.html

AssetDatabase is a script editor. If you want to do a similar thing in the game, place the appropriate scripts in the "Resources" folder (this ensures that they will be included in the assembly, even if they are not connected in the scene) and use:

 Resources.LoadAll<ArmourType>(""); 
+9
source

Source: https://habr.com/ru/post/984872/


All Articles