Documentation

Unity Engine


User Manual

Script Reference

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.
Read time 4 minutesLast updated 4 days ago

Definition

Warning
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, _Attribute

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