InspectorElement.FillDefaultInspector
Declaration
public static void FillDefaultInspector(UIElements.VisualElement container, SerializedObject serializedObject, Editor editor);Параметры
| Параметр | Описание |
|---|---|
| контейнер | Родители VisualElement |
| serializedObject | SerializedObject для проверки |
| редактор | Текущий редактор |
Описание
Добавление полей свойств инспектора по умолчанию в контейнер VisualElement.
В следующем примере показано, как заполнить контейнер полями инспектора по умолчанию. Полный пример см. в Создание по умолчанию 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);Параметры
| Параметр | Описание |
|---|---|
| контейнер | Родители VisualElement. |
| serializedObject | SerializedObject для проверки. |
| редактор | Текущий используемый редактор. |
| propertiesToExclude | Свойства, исключаемые при заполнении Inspector. Свойства с именами, соответствующими ,SerializedProperty.name,, пропускаются. |
Описание
Добавление полей свойств инспектора по умолчанию в контейнер VisualElement.
В следующем примере показано, как заполнить контейнер по умолчанию полями Inspector. Полный пример см. в Создание по умолчанию 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; } }
В следующем примере показано, как заполнить контейнер по умолчанию полями Inspector, исключая определенное свойство, которое отображается как Слайдер.
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; } }