此属性在检查器中是否已展开?
具有子属性(例如数组、自定义可序列化结构体或自定义可序列化类)的序列化属性可以在检查器中展开或折叠,以显示或隐藏其子属性。以下示例在用户展开 Quaternion 属性时在检查器中显示一条说明。
using UnityEditor; using UnityEngine;
[CustomPropertyDrawer(typeof(Quaternion))] public class QuaternionDrawer : PropertyDrawer { public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { // use the default property height, which takes into account the expanded state return EditorGUI.GetPropertyHeight(property); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // draw the default property editor EditorGUI.PropertyField(position, property, label, true);
// display a warning to discourage users from manually editing child properties on a quaternion if (property.isExpanded) { position.height = EditorGUIUtility.singleLineHeight; position.xMin += EditorGUIUtility.labelWidth; EditorGUI.HelpBox(position, "Editing quaternions manually is inadvisable.", MessageType.Warning); } } }
在展开四元数属性时显示一条消息。
请注意,此标志的值在具有相同属性路径和目标类型的序列化属性的所有实例之间共享。例如,在检查器中折叠特定组件的特定属性将使该组件类型的其他所有实例的相同属性在检查器中折叠。