public class ProfilerTest : MonoBehaviour
{
public bool ShowArray = true;
public int[] IntArr;
public int IntValue;
}
[CustomEditor(typeof(ProfilerTest))]
public class ProfilerTestEditor : Editor
{
private ProfilerTest _target { get => target as ProfilerTest; }
private SerializedProperty _intValue;
private SerializedProperty _intArray;
private void OnEnable()
{
_intValue = serializedObject.FindProperty("IntValue");
_intArray = serializedObject.FindProperty("IntArr");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
_target.ShowArray = EditorGUILayout.Toggle("显示Int数组",_target.ShowArray);
if (_target.ShowArray)
{
EditorGUILayout.PropertyField(_intArray, new GUIContent("Int数组"));
}
else
{
EditorGUILayout.PropertyField(_intValue, new GUIContent("Int数值"));
}
serializedObject.ApplyModifiedProperties();
}
}