[CustomEditor(typeof(MyScript))]
public class MyScriptEditor : Editor
{
// the index of selected option
private int index;
public override void OnInspectorGUI()
{
// the index of selected option
index = EditorGUILayout.Popup(index, new string[] { "Option1", "etc" });
}
}
[CustomEditor(typeof(MyScript))]
public class MyScriptEditor : Editor
{
// the serialized fields of the varibles you wanna change
SerialiedProperty var1, var2, var3; // ...etc.
// the index of selected option
private int index;
private void Awake()
{
var1 = serializedObject.FindProperty("var1");
var2 = serializedObject.FindProperty("var2");
var3 = serializedObject.FindProperty("var2"); // the string is the name of your field
}
public override void OnInspectorGUI()
{
// the index of selected option
index = EditorGUILayout.Popup(index, new string[] { "Option1", "etc" });
object yourVal;
switch (index)
{
case 0:
yourVal = EditorGUILayout.FloatField(yourVal);
break;
/*
and etc,
you create the field in inspector you want for eevery index
but tbh, that's a bad idea to do so
*/
}
serializedObject.ApplyModifiedProperties();
}
}
1条答案
按热度按时间bis0qfac1#
您可以编写自定义检查器或使用枚举
并将字段添加到MonoBehaviour中
会变成那样
艰难而漫长的路
这里有一个例子
您可以找到更多的here和here。
编辑:
就像你在评论里问的