Version: 2023.2

PropertyCollectionAttribute

class in UnityEngine

/

继承自:PropertyAttribute

切换到手册

描述

Base class to derive custom property attributes for collections from. Use this to create custom attributes for array and list variables in scripts.

自定义特性可以与自定义 PropertyDrawer 类连接,以控制具有该特性的脚本变量如何在 Inspector 中显示。

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

public class Collection : MonoBehaviour { public int before; [GreenCollectionDrawer] public int[] collection; public int after; }

public class GreenCollectionDrawerAttribute : PropertyCollectionAttribute { }

[CustomPropertyDrawer(typeof(GreenCollectionDrawerAttribute))] public class GreenCollectionDrawer : PropertyDrawer { public override VisualElement CreatePropertyGUI(SerializedProperty property) { return new PropertyField(property) { style = { backgroundColor = Color.green } }; } }

另请参阅:PropertyDrawer 类。

继承的成员

变量

order可选字段,用于指定多个 DecorationDrawer 应采用的绘制顺序。