In the top tier, State Of Node is “Start.” However, later it becomes “0”, why?
My code:
using UnityEngine;
[System.Serializable]
public enum nodeState {
start, normal, link, end
}
[System.Serializable]
public class ConversationNode {
public nodeState stateOfNode;
public string npcName;
public string text;
public Reply[] replies;
}
[System.Serializable]
public class Reply {
public string text;
public ConversationNode link;
}
SerializableEnum does not show in MonoDevelop, it is not a recognized function.
This is the code given by Scott Webster Portfolio:
public class NewBehaviourScript : MonoBehaviour {
public enum ExampleEnum
{
EE_One,
EE_Two,
EE_Three,
EE_Four
}
[Serializable]
public class ExampleEnumClass : SerializableEnum<ExampleEnum> { }
public ExampleEnumClass m_EnumVariable;
}
Geez, sorry my bad! I tried to get it into my script but now ‘State of Node’ isn’t appearing at all in the inspector. Any idea why? Here is my code integrated with the stuff from the zip file:
using UnityEngine;
[System.Serializable]
public enum nodeState {
start, normal, link, end
}
[System.Serializable]
public class ConversationNode {
public class stateOfNode : SerializableEnum<nodeState> { };
public string npcName;
public string text;
public Reply[] replies;
}
[System.Serializable]
public class Reply {
public string text;
public ConversationNode link;
}
i am sorry that code is a mess but it is something like that will try and get it working later
ya it normally just saves them as ints you need to do the conversion to string manually if that is what you want
the nameof operator was recently added might be usefull for getting names of enums
Well, I am making a conversation asset for my RPG, and I need to have these text values in the inspector. So yes having the strings is required. There must be some way of getting this working without 3rd party code??
using UnityEngine;
[System.Serializable]
public enum nodeState {
start, normal, link, end
}
[System.Serializable]
public class stateOfNode : SerializableEnum<nodeState> { }
[System.Serializable]
public class ConversationNode {
public stateOfNode currentStateOfNode;
public string npcName;
public string text;
public Reply[] replies;
}
[System.Serializable]
public class Reply {
public string text;
public ConversationNode link;
}
It is much better to use ScriptableObjects for many enumerative uses. You can even define additional associated data with each one of them, and drag them into other parts of your game (scenes, prefabs, other ScriptableObjects) however you like. References remain rock solid even if you rename them, reorder them, reorganize them, etc. They are always connected via the meta file GUID.
Collections / groups of ScriptableObjects can also be loaded en-masse with calls such as Resources.LoadAll<T>().
Best of all, Unity already gives you a built-in filterable picker when you click on the little target dot to the right side of a field of any given type… bonus!
I appreciate the advice, I may make use of it elsewhere. But here, for my simple need to serialize a UnityEngine.Rendering.CompareFunction enum, scriptable objects would be a bit overkill.
Just to clarify, my only issue is the Unity Inspector (seemingly infrequently) displaying the enum field as an integer rather than the string name.