Unity 6.3
0 онлайн 67 гостей 3 в системе
Вход

EditorGUILayout.PropertyField

Declaration

public static bool PropertyField(SerializedProperty property, params GUILayoutOption[] options);
public static bool PropertyField(SerializedProperty property, GUIContent label, params GUILayoutOption[] options);
public static bool PropertyField(SerializedProperty property, bool includeChildren, params GUILayoutOption[] options);
public static bool PropertyField(SerializedProperty property, GUIContent label, bool includeChildren, params GUILayoutOption[] options);

Параметры

Параметр Описание
свойство SerializedProperty для создания поля.
метка Необязательная метка для использования. Если не указано, используется метка самого свойства. Используйте GUIContent.none, чтобы не отображать метку вообще.
includeChildren Если true, свойство, включая дочерей рисуется; в противном случае только сам контроллер (например, только foldout, но ничего под ним).
варианты Необязательный список параметров компоновки, задающих дополнительные свойства раскладки. Любые переданные здесь значения переопределяют настройки, заданные style.
Дополнительные ресурсы: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.

Возвращаемое значение

логическое True, если свойство имеет дочерей, расширено, и includeChildren установлено на false; в противном случае false. Вы можете использовать его для определения isExpanded состояние свойства и при необходимости настроить отображение дочерних элементов.

Описание

Создайте поле для SerializedProperty.

Используйте это, когда вы хотите настроить внешний вид параметров для GameObject в 2000 году Inspector. Используйте это для создания полей для Свойств Сериализации. Дополнительная информация об изменении Редактора доступна в Editor раздел.

Дополнительные ресурсы: SerializedProperty, SerializedObject.

//The scripts below show how to use a propertyField to change your editor.
//Attach this first script to the GameObject that you would like to control. Add code in this script for any of the actions you require.

using UnityEngine;

public class MyGameObjectScript : MonoBehaviour { public int m_MyInt = 75; public Vector3 m_MyVector = new Vector3(20, 1, 0); public GameObject m_MyGameObject; }
//This next script shows how to call upon variables from the "MyGameObject" Script (the first script) to make custom fields in the Inspector for these variables.

using UnityEngine; using UnityEditor;

// Custom Editor using SerializedProperties. // Automatic handling of multi-object editing, undo, and Prefab overrides. [CustomEditor(typeof(MyGameObjectScript))] [CanEditMultipleObjects] public class EditorGUILayoutPropertyField : Editor { SerializedProperty m_IntProp; SerializedProperty m_VectorProp; SerializedProperty m_GameObjectProp;

void OnEnable() { // Fetch the objects from the GameObject script to display in the inspector m_IntProp = serializedObject.FindProperty("m_MyInt"); m_VectorProp = serializedObject.FindProperty("m_MyVector"); m_GameObjectProp = serializedObject.FindProperty("m_MyGameObject"); }

public override void OnInspectorGUI() { //The variables and GameObject from the MyGameObject script are displayed in the Inspector with appropriate labels EditorGUILayout.PropertyField(m_IntProp, new GUIContent("Int Field"), GUILayout.Height(20)); EditorGUILayout.PropertyField(m_VectorProp, new GUIContent("Vector Object")); EditorGUILayout.PropertyField(m_GameObjectProp, new GUIContent("Game Object"));

// Apply changes to the serializedProperty - always do this at the end of OnInspectorGUI. serializedObject.ApplyModifiedProperties(); } }