// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik // #if UNITY_EDITOR using System; using UnityEngine; namespace Animancer.Editor { /// [Editor-Only] /// with connected to an . /// /// https://kybernetik.com.au/animancer/api/Animancer.Editor/PooledGUIContent public class PooledGUIContent : GUIContent, IDisposable { /************************************************************************************************************************/ /// s and initializes an instance. public static PooledGUIContent Acquire( string text = null, string tooltip = null, Texture image = null) { var item = Pool.Instance.Acquire(); item.text = text; item.tooltip = tooltip; item.image = image; return item; } /// s and initializes an instance. public static PooledGUIContent Acquire( UnityEditor.SerializedProperty property) => Acquire(property.displayName, property.tooltip); /************************************************************************************************************************/ /// . public void Dispose() => Pool.Instance.Release(this); /************************************************************************************************************************/ /// An for . /// https://kybernetik.com.au/animancer/api/Animancer.Editor/Pool public class Pool : ObjectPool { /************************************************************************************************************************/ /// Singleton instance. public static Pool Instance = new(); /************************************************************************************************************************/ /// protected override PooledGUIContent New() => new(); /************************************************************************************************************************/ /// public override PooledGUIContent Acquire() { var content = base.Acquire(); #if UNITY_ASSERTIONS if (!string.IsNullOrEmpty(content.text) || !string.IsNullOrEmpty(content.tooltip) || content.image != null) { throw new UnityEngine.Assertions.AssertionException( $"• {nameof(content.text)} = '{content.text}'" + $"\n• {nameof(content.tooltip)} = '{content.tooltip}'" + $"\n• {nameof(content.image)} = '{content.image}'", $"A {nameof(PooledGUIContent)} is not cleared." + NotResetError); } #endif return content; } /************************************************************************************************************************/ /// public override void Release(PooledGUIContent content) { content.text = null; content.tooltip = null; content.image = null; base.Release(content); } /************************************************************************************************************************/ } /************************************************************************************************************************/ } } #endif