- Home /
Add to enum list from inspector
I want to use an enum to contain values for "flags" which the player can set off by completing parts of the story, quests or interacting with objects in the game. As this list of flags will increase during development I would like to be able to add a flag to the enum from within unity rather than doing by hand.
Please I dont want to change it at runtime I want to edit the actual declaration from within Unity before compilation. It seems that layers work by enums and they can be edited from within unity.
Answer by Drakmyth · Dec 30, 2012 at 08:30 PM
I don't know for sure, but I'm guessing that layers are implemented as a list. If you expose a list (or array, or any other collection type) to the inspector, you can modify its contents directly.
I'm a little new to unity and haven't dealt with transferring data across scenes, but I would place an empty GameObject in the scene to serve as a SceneController and would place a script on this object. This script would contain a Dictionary , then you can access this via scripts with the GetComponent method.
As far as I'm aware, Unity does not currently have a Dictionary inspector, but a quick search suggests that it isn't too difficult to make one. Alternatively, you could expose two lists to the inspector (one for keys, the other for values) then combine them into a dictionary in the script's Start or Awake method.
This isn't really a case for an enum as those merely define a series of constants. Being constants, they cannot be defined at runtime and can't really be used to store data, unless used in combination with a list or dictionary.
I am fairly new to Unity as well, haven't done much with it, the main problem I am having is that I assume C# has the same/similar functionality as C++. Thanks for suggesting the Dictionary, its actually perfect for what I need and its faster than Lists!!! Yay for less slowdowns!!!
Your answer