// MIT License - Copyright (c) 2026 wallstop // Full license text: https://github.com/wallstop/unity-helpers/blob/main/LICENSE namespace WallstopStudios.UnityHelpers.Utils { using System; /// /// Attribute to control intelligent pool purging behavior for a specific type. /// /// /// /// Apply this attribute to types that should opt-out of or customize intelligent pool purging. /// This attribute is checked when determining the effective purge configuration for a type. /// /// /// The attribute takes precedence over global settings but can be overridden by explicit /// type-specific configuration via or /// . /// /// /// /// /// [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false)] public sealed class PoolPurgePolicyAttribute : Attribute { /// /// Gets whether intelligent purging is enabled for this type. /// public bool Enabled { get; } /// /// Gets the custom idle timeout in seconds, or null to use defaults. /// public float? IdleTimeoutSeconds { get; } /// /// Gets the minimum number of items to retain, or null to use defaults. /// public int? MinRetainCount { get; } /// /// Gets the warm retain count for active pools, or null to use defaults. /// Active pools (accessed within ) keep this many items warm /// to avoid cold-start allocations. /// public int? WarmRetainCount { get; } /// /// Creates a new pool purge policy attribute. /// /// Whether intelligent purging is enabled for this type. /// /// Optional warm retain count for active pools. Active pools keep this many items warm /// to avoid cold-start allocations. If not specified, uses global defaults. /// public PoolPurgePolicyAttribute(bool enabled, int warmRetainCount = -1) { Enabled = enabled; IdleTimeoutSeconds = null; MinRetainCount = null; WarmRetainCount = warmRetainCount >= 0 ? warmRetainCount : null; } /// /// Creates a new pool purge policy attribute with custom settings. /// /// Whether intelligent purging is enabled for this type. /// Custom idle timeout in seconds. /// /// Optional warm retain count for active pools. Active pools keep this many items warm /// to avoid cold-start allocations. If not specified, uses global defaults. /// public PoolPurgePolicyAttribute( bool enabled, float idleTimeoutSeconds, int warmRetainCount = -1 ) { Enabled = enabled; IdleTimeoutSeconds = idleTimeoutSeconds; MinRetainCount = null; WarmRetainCount = warmRetainCount >= 0 ? warmRetainCount : null; } /// /// Creates a new pool purge policy attribute with custom settings. /// /// Whether intelligent purging is enabled for this type. /// Custom idle timeout in seconds. /// Minimum number of items to retain. /// /// Optional warm retain count for active pools. Active pools keep this many items warm /// to avoid cold-start allocations. If not specified, uses global defaults. /// public PoolPurgePolicyAttribute( bool enabled, float idleTimeoutSeconds, int minRetainCount, int warmRetainCount = -1 ) { Enabled = enabled; IdleTimeoutSeconds = idleTimeoutSeconds; MinRetainCount = minRetainCount; WarmRetainCount = warmRetainCount >= 0 ? warmRetainCount : null; } } }