Version: 2022.3
public void OnTitleBarGUI ();

描述

使用此函数通过 IMGUI 来重载 SettingsProvider 的标题绘制。因此您可以在标题旁边添加自定义 UI(例如工具栏按钮)。AssetSettingsProvider 使用此机制来显示“add to preset”和“help”按钮。

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."); } } }