Would it be possible and is it a good idea? [Loading prefabs by name]
Hi,
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 searchdirectory "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. using
AssetDatabase.LoadAllAssetsAtPathand assign it by decoded String path as enum name.
6). 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.