实现效果
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(BtoolDemo))]//关联之前的脚本
public classBtoolDemoEditor : Editor
{
private SerializedObject test;//序列化
private SerializedProperty m_type, a_int,b_int;//定义类型m_type,变量a,变量b
void OnEnable()
{
test = new SerializedObject(target);
//获取m_type
m_type =test.FindProperty("m_type");
//获取a_int
a_int =test.FindProperty("a_int");
//获取b_int
b_int =test.FindProperty("b_int");
}
public override void OnInspectorGUI()
{
//更新test
test.Update();
//显示m_type
EditorGUILayout.PropertyField(m_type);
//根据类型显示不同内容
if (m_type.enumValueIndex == 0)
{
EditorGUILayout.PropertyField(a_int);
}
else if (m_type.enumValueIndex == 1)
{
EditorGUILayout.PropertyField(b_int);
}
test.ApplyModifiedProperties();//应用于界面
}
}
using UnityEngine;
public class BtoolDemo : MonoBehaviour {
public enum type1
{
a,
b
}
public type1 m_type;
public int a_int;
public int b_int;
网友评论