重写此方法以创建您自己的脚本导入器的检查器 GUI。
为了使 OnInspectorGUI 撤销/重做和取消功能在检查器中正常工作,您必须调用 ApplyRevertGUI 或重写 needsApplyRevert 以返回 false。
使用 ApplyRevertGUI 的检查器 GUI 示例
using UnityEditor; using UnityEditor.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 的检查器 GUI 示例
using UnityEditor; using UnityEditor.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(); } }