重写此方法,以针对 ScriptedImporter 创建自己的检视面板 GUI。
若要使 OnInspectorGUI 撤消/重做和取消功能在检视面板中发挥作用,必须调用 ApplyRevertGUI 或覆盖 needsApplyRevert 以返回 false。
使用 ApplyRevertGUI 的 InspectorGUI 示例:
using UnityEditor; using UnityEditor.Experimental.AssetImporters; using UnityEngine;
public class CustomInspector : ScriptedImporterEditor { SerializedProperty myProperty;
public override void OnEnable() { base.OnEnable();
myProperty = serializedObject.FindProperty("m_MyProperty"); }
public override void OnInspectorGUI() { serializedObject.Update();
EditorGUILayout.PropertyField(myProperty);
serializedObject.ApplyModifiedProperties();
ApplyRevertGUI(); } }
用户无法更改任何内容并且不需要 ApplyRevertGUI 的 InspectorGUI 示例:
using UnityEditor; using UnityEditor.Experimental.AssetImporters; using UnityEngine;
public class CustomInspector : ScriptedImporterEditor { SerializedProperty myProperty;
public override void OnEnable() { base.OnEnable();
myProperty = serializedObject.FindProperty("m_MyProperty"); }
protected override bool needsApplyRevert => false;
public override void OnInspectorGUI() { serializedObject.Update();
EditorGUILayout.LabelField(myProperty.displayName, myProperty.stringValue);
serializedObject.ApplyModifiedProperties(); } }