Version: Unity 6.3 Beta (6000.3)
LanguageEnglish
  • C#

InspectorElement.FillDefaultInspector

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public static void FillDefaultInspector(UIElements.VisualElement container, SerializedObject serializedObject, Editor editor);

Parameters

Parameter Description
container The parent VisualElement
serializedObject The SerializedObject to inspect
editor The editor currently used

Description

Adds default inspector property fields under a container VisualElement.

The following example shows how to fill a container with default inspector fields. For a complete example, refer to Create a default Inspector.

using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;

[CreateAssetMenu] public class MyEditorData : ScriptableObject { public string myString; public float myFloat; public string myInt; }

[CustomEditor(typeof(MyEditorData))] public class MyEditor : UnityEditor.Editor { public override VisualElement CreateInspectorGUI() { var root = new VisualElement(); root.Add(new Label("My Custom Inspector")); InspectorElement.FillDefaultInspector(root, serializedObject, this); return root; } }

Declaration

public static void FillDefaultInspector(UIElements.VisualElement container, SerializedObject serializedObject, Editor editor, params string[] propertiesToExclude);

Parameters

Parameter Description
container The parent VisualElement.
serializedObject The SerializedObject to inspect.
editor The Editor currently used.
propertiesToExclude Properties to exclude when populating the Inspector. Properties with name matching SerializedProperty.name are skipped.

Description

Adds default inspector property fields under a container VisualElement.

The following example shows how to fill a container with default Inspector fields. For a complete example, refer to Create a default Inspector.

using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;

[CreateAssetMenu] public class MyEditorData : ScriptableObject { public string myString; public float myFloat; public string myInt; }

[CustomEditor(typeof(MyEditorData))] public class MyEditor : UnityEditor.Editor { public override VisualElement CreateInspectorGUI() { var root = new VisualElement(); root.Add(new Label("My Custom Inspector")); InspectorElement.FillDefaultInspector(root, serializedObject, this); return root; } }

The following example shows how to fill a container with default Inspector fields, excluding a specific property that is displayed as a Slider.

using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;

[CreateAssetMenu] public class MyEditorDataExclude : ScriptableObject { public string myString; public float myFloat; public string myInt; }

[CustomEditor(typeof(MyEditorDataExclude))] public class MyEditorExclude : UnityEditor.Editor { public override VisualElement CreateInspectorGUI() { var root = new VisualElement(); root.Add(new Label("My Custom Inspector"));

var myFloatSlider = new Slider { bindingPath = "myFloat", label = "My Float" }; root.Add(myFloatSlider);

// Draw all properties except "myFloat" InspectorElement.FillDefaultInspector(root, serializedObject, this, "myFloat"); return root; } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961