Hello all,
I am designing a pantheon of gods in my current project. To do so I am keeping a list within my game manger singleton which keeps track of all the information on each god within that list; doing this though I’ve ran into a problem— I need that list (which holds a reference to each god as an element) to hold another list within that element to ‘rival gods’ which should reference other gods within that same list.
I’m not sure if this is a problem in design or if I need a certain structure which I haven’t used before. I’ll try to do a little rundown to better explain it…
GameManager Class->Holds reference to PantheonManager->holds List (God being a class in itself which holds another list to ‘rivalGods’ so List as of now)…
I’d rather not use strings (god names) for checking and what not as they’re slow, thought about giving each one an int ID for faster checking but would rather a straight reference to a element in the initial list, is this possible and if so what would be the ideal method for this?
Edit: Hey all, after reading a bit more into this I think I’ve narrowed down what I was looking for originally. [This thread][1] here seems to do the trick, so for future reference if anyone is trying to do something similar to this I would go for this method. Thanks again all!
This could probably be abstracted a bit more as well so the RefreshEnum isn’t tied directly to that specific class…
Code Below
public class MyClass : MonoBehaviour
{
public void RefreshEnum()
{
string enumName = "MyEnum";
string[] enumEntries = new string[myList.Count] as string[];
string filePathAndName = "Assets/Scripts/Enums/" + enumName + ".cs"; //The folder Scripts/Enums/ is expected to exist
for(int i = 0; i < myList.Count; i++)
{
enumEntries _= myList*.myElementName;*_
}
using(StreamWriter streamWriter = new StreamWriter(filePathAndName))
{
streamWriter.WriteLine( "public enum " + enumName );
streamWriter.WriteLine( “{” );
for( int i = 0; i < enumEntries.Length; i++ )
{
string lastItem = (enumEntries.Length == 0) ? null : enumEntries[enumEntries.Length - 1];
if(enumEntries != lastItem)
{
streamWriter.WriteLine( " " + enumEntries + “,” );
}
else
{
streamWriter.WriteLine( " " + enumEntries*);*
}
}
streamWriter.WriteLine( “};” );
}
AssetDatabase.Refresh();
}
} //end class
//then a custom Editor Class, here below…
[CustomEditor(typeof(MyClass))]
public class MyCustomEditor : Editor
{
public override void OnInspectorGUI()
{
DrawDefaultInspector();
MyClass mC = (MyClass)target;
if(GUILayout.Button(“Refresh Enum”))
{
mC.RefreshEnum();
}
}
}
_*[1]: http://answers.unity3d.com/questions/1170350/editorscript-generate-enum-from-string.html*_
