- Home /
Question by
eookog · Jul 24, 2017 at 07:33 AM ·
editorinspectorstructcustomeditor
Change variable in inspector depending on enum using struct
First of all, my english is bad. sorry :(
This is what I want to serialize in inspector.
public class TouchGameInfo : MonoBehaviour {
public InfoPerGame[] hi;
}
[System.Serializable]
public struct GameInfo
{
public TouchGameType TouchType;
public int Count;
public float Seconds;
public EasyTouch.SwipeDirection Direction;
}
[System.Serializable]
public struct InfoPerGame
{
public int GameNumber;
public float Timer;
public GameInfo[] Info;
}
And this is my editor script
[CustomEditor(typeof(GameInfo)) , CanEditMultipleObjects]
public class InspectorTest : Editor {
public SerializedProperty
type_Prop,
count_Prop,
seconds_Prop,
direction_Prop;
void OnEnable()
{
type_Prop = serializedObject.FindProperty("TouchType");
count_Prop = serializedObject.FindProperty("Count");
seconds_Prop = serializedObject.FindProperty("Seconds");
direction_Prop = serializedObject.FindProperty("Direction");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.PropertyField(type_Prop);
TouchGameType pdpd = (TouchGameType)type_Prop.enumValueIndex;
switch(pdpd)
{
case TouchGameType.Tap :
EditorGUILayout.PropertyField(count_Prop, new GUIContent("Count"));
break;
case TouchGameType.Hold :
EditorGUILayout.PropertyField(seconds_Prop, new GUIContent("Seconds"));
break;
case TouchGameType.Swipe :
EditorGUILayout.PropertyField(direction_Prop, new GUIContent("Direction"));
break;
}
serializedObject.ApplyModifiedProperties();
}
}
I want variables( Count, Seconds, Direction in GameInfo) are show just only one of them depends on TouchType in GameInfo.
But somehow, I dunno why (maybe [System.Serializable]?), It shows all of my property in inspector.
The thing that I want to do is possible in Unity 5.4 ?
inspector in my dream be like :
Hi
*Size : 1 *Element 0 *Game Number : 1 *Timer : 2.5 *Info *Size : 1 *Element 0 *Touch Type : Hold *Seconds : 1.5
like this .... help plz
Comment