Hi,
I’m asking this question because I’m not very familiar with Editor GUI Scripting but I have checked the API and it does not seem impossible.
In Unity, I can write a class with an array of gameobjects. I can drag to it multiple prefabs to assign references. Then I can access references to prefabs in the array and instantiate them at runtime.
I want to make this automatic and in a dictionary.
Namely, would it be possible to make something like below?
- I am in editor mode (not play mode).
- I have a directory like MyPrefabs/Ships and MyPrefabs/Weapons with simple prefabs there.
- I have an input field in a custom inspector where I specify search directory “MyPrefabs” and press a custom button which finds all *.prefab files in this directory.
- I create a text file which is a textfile with a C# enum definition. It is a “flat list” of all prefabs prefixed with directory which looks something like this:
enum AllPrefabs {
WeaponsWeapon1,
WeaponsWeapon2,
…
ShipsSomeShip,
ShipsBigShip
} - I have a class with dictionary of prefabs, mapped by enum AllPrefabs → Gameobject reference for prefab. Then I get each prefab from point 3. and assign it by decoded String path as enum name.
- I have all refences set up, BEFORE runtime, so I don’t need to put everything in Resources folder (or am I wrong?) and now I can do
Gameobject prefab = PrefabManager.getByName(AllPrefabs.WeaponsWeapon1);
Instantiate(prefab, position, rotation);
Would it be possible? It would be the same as assignin it all manually but using a script unless I’m missing something.
Thanks for answering.