Makes attribute affect collections instead of their items.
When you apply a PropertyAttribute to a collection, by default Unity applies it to each element of the collection. When applyToCollection is true, the attribute is applied to the collection itself instead.
You can use this in scenarios where the attribute functionality needs to apply to the collection as a whole rather than per element. Some typical scenarios include:
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 : PropertyAttribute { public GreenCollectionDrawerAttribute() : base(true) { } }
[CustomPropertyDrawer(typeof(GreenCollectionDrawerAttribute))] public class GreenCollectionDrawer : PropertyDrawer { public override VisualElement CreatePropertyGUI(SerializedProperty property) { return new PropertyField(property) { style = { backgroundColor = Color.green } }; } }