实现根据不同类型,在检视面板中展示不同的参数。
实体类:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CustomTest :MonoBehaviour {
public enum TestMode
{
first,
second,
third
}
public TestMode myMode;
public GameObject ObjectA;
public GameObject ObjectB;
public GameObject ObjectC;
}
自定义编辑器类:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(CustomTest))]
public class CustomTestEditor : Editor {
public override void OnInspectorGUI()
{
CustomTest test = (CustomTest) target;
test.myMode = (CustomTest.TestMode) EditorGUILayout.EnumPopup("MyMode", test.myMode);
EditorGUILayout.Space();
switch (test.myMode)
{
case CustomTest.TestMode.first:
test.ObjectA = (GameObject) EditorGUILayout.ObjectField("A",test.ObjectA,typeof(GameObject),true);
break;
case CustomTest.TestMode.second:
test.ObjectB = (GameObject)EditorGUILayout.ObjectField("B", test.ObjectB, typeof(GameObject), true);
break;
case CustomTest.TestMode.third:
test.ObjectC = (GameObject)EditorGUILayout.ObjectField("C", test.ObjectC, typeof(GameObject), true);
break;
default:
break;
}
}
}
效果如下: