There\'s a platform class that contains several movement types. TypeA is AutoMove at initiation between waypoints TypeB is Falling with gravity when a specific bool
You will need to implement your own Custom Inspector. There is Unity's official tutorial on this topic. The custom inspector uses GUI classes, and you will need to check your condition and draw a field if and only if the condition is met.
Here's an example code that I took from Change Inspector Variables Depending On Enum. From this code you will learn how to dynamically get a value of a enum
field from your target class.
~/Assets/PropertyHolder.cs
using System.Collections;
using UnityEngine;
public class PropertyHolder : MonoBehaviour
{
public enum Status { A, B, C };
public Status state;
public int valForAB;
public int valForA;
public int valForC;
public bool controllable;
void Start()
{
}
void Update()
{
}
}
~/Assets/Editor/PropertyHolderEditor.cs
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof (PropertyHolder)), CanEditMultipleObjects]
public class PropertyHolderEditor : Editor
{
public SerializedProperty
state_Prop,
valForAB_Prop,
valForA_Prop,
valForC_Prop,
controllable_Prop;
void OnEnable()
{
// Setup the SerializedProperties
state_Prop = serializedObject.FindProperty("state");
valForAB_Prop = serializedObject.FindProperty("valForAB");
valForA_Prop = serializedObject.FindProperty("valForA");
valForC_Prop = serializedObject.FindProperty("valForC");
controllable_Prop = serializedObject.FindProperty("controllable");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.PropertyField(state_Prop);
PropertyHolder.Status st = (PropertyHolder.Status) state_Prop.enumValueIndex;
switch (st)
{
case PropertyHolder.Status.A:
EditorGUILayout.PropertyField(controllable_Prop, new GUIContent("controllable"));
EditorGUILayout.IntSlider(valForA_Prop, 0, 10, new GUIContent("valForA"));
EditorGUILayout.IntSlider(valForAB_Prop, 0, 100, new GUIContent("valForAB"));
break;
case PropertyHolder.Status.B:
EditorGUILayout.PropertyField(controllable_Prop, new GUIContent("controllable"));
EditorGUILayout.IntSlider(valForAB_Prop, 0, 100, new GUIContent("valForAB"));
break;
case PropertyHolder.Status.C:
EditorGUILayout.PropertyField(controllable_Prop, new GUIContent("controllable"));
EditorGUILayout.IntSlider(valForC_Prop, 0, 100, new GUIContent("valForC"));
break;
}
serializedObject.ApplyModifiedProperties();
}
}
And this is how to check bool & draw only if the condition is met, from Hide/Show properties dynamically in inspector. Modify the boolean checking part to compare the enum
value you found using the above code.
public class MyScript : MonoBehaviour
{
public bool flag;
public int i = 1;
}
[CustomEditor(typeof (MyScript))]
public class MyScriptEditor : Editor
{
void OnInspectorGUI()
{
var myScript = target as MyScript;
myScript.flag = GUILayout.Toggle(myScript.flag, "Flag");
if (myScript.flag)
myScript.i = EditorGUILayout.IntSlider("I field:", myScript.i, 1, 100);
}
}
Combining these two you should get the behaviour you want.