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

EditorGUI.PropertyField

Declaration

public static bool PropertyField(Rect position, SerializedProperty property, bool includeChildren = false);
public static bool PropertyField(Rect position, SerializedProperty property, GUIContent label, bool includeChildren = false);

Параметры

Параметр Описание
должность Прямоугольник на экране, который будет использоваться для поля свойства.
свойство SerializedProperty для создания поля.
метка Необязательная метка для использования. Если не указано, используется метка самого свойства. Используйте GUIContent.none, чтобы не отображать метку вообще.
includeChildren Если true, свойство, включая дочерей рисуется; в противном случае только сам контроллер (например, только foldout, но ничего под ним).

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

логическое True, если свойство имеет дочерей и расширено, а includeChildren установлено на false; в противном случае false.

Описание

Используйте это для создания поля для SerializedProperty в Редакторе.

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

//Attach a script like this to the GameObject you would like to have a custom Editor window.

using UnityEngine;

public class MyScript : MonoBehaviour { public int myInt = 90; }
//Create a folder and name it “Editor” and place this second script within it. To do this right click within the Assets directory and go to Create>Folder
//Ensure you insert your first script’s name as a parameter in the CustomEditor e.g. [CustomEditor(typeof(MyScript))]

using UnityEngine; using UnityEditor;

// Custom Editor using SerializedProperties. // Make sure to put the name of the script on your GameObject in here [CustomEditor(typeof(MyScript))] // Automatic handling of multi-object editing, undo, and Prefab overrides. [CanEditMultipleObjects]

public class EditorGUIPropertyField : Editor { SerializedProperty m_IntProperty;

void OnEnable() { // Fetch the objects from the MyScript script to display in the inspector m_IntProperty = serializedObject.FindProperty("myInt"); }

public override void OnInspectorGUI() { //The variables and GameObject from the GameObject script are displayed in the Inspector and have the appropriate label EditorGUI.PropertyField(new Rect(0, 300, 500, 30), m_IntProperty, new GUIContent("Int : "));

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