Hi everyone,
I want to make an enum (that contains let’s say the characters list), and once I choose an option another enum will be available for me (that will contain items that the specific character have).
is it possible to do so and show in the inspector?
Hi,
How is this relevant to 2D (graphics) ? Your post would be better suited to some other forum section, like scripting.
The answer to your question is you need to create a custom editor for your component/script, if you want something special like that to happen.
EDIT:
Here’s simplified example that helps you get started:
This would be your Character class, I just made publicly accessible CharacterType which defines a character’s type, and CharacterTime, which would define what item a character would have.
using UnityEngine;
public class Character : MonoBehaviour
{
public enum CharacterType
{
None,
Troll,
Elf,
JunkMonster
}
public enum CharacterItem
{
None,
Sword,
Shield,
RustyCan
}
public CharacterType characterType = CharacterType.None;
public CharacterItem characterItem = CharacterItem.None;
}
Then, you have to make a custom Editor script. My example does not render the other default items the Inspector would contain, so look into that too.
This below will render a blank Inspector with just one enum, which is of type CharacterType. Now, when you select something else than None, my custom editor will show another option, which is that item type:
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(Character))]
public class CharacterEditor : Editor
{
SerializedProperty characterType;
SerializedProperty characterItem;
void OnEnable()
{
characterType = serializedObject.FindProperty("characterType");
characterItem = serializedObject.FindProperty("characterItem");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.PropertyField(characterType);
if ( characterType.enumValueIndex != 0)
{
EditorGUILayout.PropertyField(characterItem);
}
serializedObject.ApplyModifiedProperties();
}
}
Of course this is a bit simple setup - I’m not sure what you’re planning to do, but my example would only allow each Character to have a single item. But anyway, this will probably help you get started with a custom Editor.