Version: 2020.1
public void OnGUI (string searchContext);

参数

searchContext Settings 窗口的搜索上下文。用于显示或隐藏相关属性。

描述

使用此函数基于 IMGUI 来绘制 UI。此情况下假设您没有向传递给 OnActivate 函数的 rootElement 添加任何子项。

using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;

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 OnActivate(string searchContext, VisualElement rootElement) { // Called when the user clicks on the MyCustom element in the Settings window. m_Settings = new SerializedObject(AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(k_MyCustomSettingsPath)); }

public override void OnDeactivate() { // User selected another setting or closed the Settings window. m_Settings = null; }

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