// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2023 Kybernetik // using UnityEngine; #if UNITY_EDITOR using Animancer.Editor; using UnityEditor; #endif namespace Animancer { /// [Editor-Conditional] /// A which draws itself rather than needing a separate . /// /// https://kybernetik.com.au/animancer/api/Animancer/SelfDrawerAttribute /// [System.Diagnostics.Conditional(Strings.UnityEditor)] public abstract class SelfDrawerAttribute : PropertyAttribute { /************************************************************************************************************************/ #if UNITY_EDITOR /************************************************************************************************************************/ /// [Editor-Only] Can the GUI for the `property` be cached? public virtual bool CanCacheInspectorGUI(SerializedProperty property) => true; /// [Editor-Only] Calculates the height of the GUI for the `property`. public virtual float GetPropertyHeight(SerializedProperty property, GUIContent label) => AnimancerGUI.LineHeight; /// [Editor-Only] Draws the GUI for the `property`. public abstract void OnGUI(Rect area, SerializedProperty property, GUIContent label); /************************************************************************************************************************/ #endif /************************************************************************************************************************/ } } #if UNITY_EDITOR namespace Animancer.Editor { /// [Editor-Only] Draws the GUI for a field. /// https://kybernetik.com.au/animancer/api/Animancer.Editor/SelfDrawerDrawer /// [CustomPropertyDrawer(typeof(SelfDrawerAttribute), true)] public class SelfDrawerDrawer : PropertyDrawer { /************************************************************************************************************************/ /// Casts the . public SelfDrawerAttribute Attribute => (SelfDrawerAttribute)attribute; /************************************************************************************************************************/ /// Calls . public override bool CanCacheInspectorGUI(SerializedProperty property) => Attribute.CanCacheInspectorGUI(property); /************************************************************************************************************************/ /// Calls . public override float GetPropertyHeight(SerializedProperty property, GUIContent label) => Attribute.GetPropertyHeight(property, label); /************************************************************************************************************************/ /// Calls . public override void OnGUI(Rect area, SerializedProperty property, GUIContent label) => Attribute.OnGUI(area, property, label); /************************************************************************************************************************/ } } #endif