文档

Unity Engine

Download Unity

Unity Engine

PropertyCollectionAttribute

Base class to derive custom property attributes for collections from. Use this to create custom attributes for array and list variables in scripts.
阅读时间4 分钟最后更新于 1 个月前

Definition

警告
Deprecated. Derive collection attributes from 'PropertyAttribute' and set its 'applyToCollection' property to 'true'.
[AttributeUsage(AttributeTargets.Field, Inherited = true, AllowMultiple = false)]public abstract class PropertyCollectionAttribute : PropertyAttribute

Remarks

A custom attributes can be hooked up with a custom PropertyDrawer class to control how a script variable with that attribute is shown in the 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 } }; }}
Additional Resources: PropertyDrawer class.

Inheritance

Inherited Members