使用此函数来覆盖使用 IMGUI 绘制 SettingsProvider 标题。这允许您在标题旁边添加自定义的 UI(比如工具栏按钮)。AssetSettingsProvider 使用此机制来显示“添加到预设”和“帮助”按钮。
using UnityEditor; using UnityEngine; using UnityEngine.UIElements; using EditorStyles = UnityEditor.EditorStyles;
class SimpleIMGUISettingsProvider : SettingsProvider { SerializedObject m_Settings; const string k_MyCustomSettingsPath = "Assets/Editor/MyCustomSettings.asset"; public SimpleIMGUISettingsProvider(string path, SettingsScope scope = SettingsScope.User) : base(path, scope) {}
public override void OnGUI(string searchContext) { // Use IMGUI to display UI: EditorGUILayout.PropertyField(m_Settings.FindProperty("m_Number"), new GUIContent("My Number")); EditorGUILayout.PropertyField(m_Settings.FindProperty("m_SomeString"), new GUIContent("Some string")); m_Settings.ApplyModifiedPropertiesWithoutUndo(); }
public override void OnTitleBarGUI() { // This button appears right after the Title of the currently selected SettingsProvider: if (GUILayout.Button("Help!", EditorStyles.miniButton)) { Debug.Log("You are on your own."); } } }