I’m trying to create a dropdown menu to select from all possible assets of a type. I have a field for an ArmourType, which is an asset, and there you can select the type. If you click the little circle next to it you get a list of all possible assets to choose from:
I’m now trying to make this a dropdown list. I succeeded, almost:
As you can see, it is a dropdown list. The code for this is:
SerializedProperty serializedArmourType = property.FindPropertyRelative ("_armourType");
ArmourType armourType = serializedArmourType.objectReferenceValue as ArmourType;
List<ArmourType> armourTypes = Resources.FindObjectsOfTypeAll<ArmourType>()
.OrderBy(a=>a.Name)
.ToList();
int typeIndex = armourTypes.IndexOf(armourType);
typeIndex = EditorGUI.Popup(typeRect, typeIndex, armourTypes.Select(a => a.Name).ToArray());
serializedArmourType.objectReferenceValue = armourTypes[typeIndex];
But because I use FindObjectsOfTypeAll
I only get the assets that are loaded into memory, not all possible ones. You can see only 4 show up in my dropdown list. If I go and open the folder where the assets are stored, and select them all so they are loaded into memory, and then go back to the dropdown list, they do all show up.
So is there a way to fix this? Perhaps a way to get them to be loaded when I look for them? Or an easier or better way of making such a dropdown list?
Note: I do not want to use enums. I’ve come to dislike enums. They still have their purpose, but what I’m trying to do is not one of those. So changing it to an enum is no solution for the dropdown menu. I say this because this is the only solution I found googling
Thanks!