using System; using UnityEditor; using UnityEngine; namespace TriInspector.Utilities { internal static class ScriptAttributeUtilityProxy { private static Func _getHandler; public static PropertyHandlerProxy GetHandler(SerializedProperty property) { if (_getHandler == null) { _getHandler = TriReflectionUtilities .GetUnityEditorTypeByName("ScriptAttributeUtility") .CompileStaticMethod("GetHandler"); } return new PropertyHandlerProxy(_getHandler(property)); } } public readonly struct PropertyHandlerProxy { private static Func _hasPropertyDrawerProperty; private static Func _getHeightMethod; private static Func _onGuiMethod; private readonly object _self; internal PropertyHandlerProxy(object self) { _self = self; } // ReSharper disable once InconsistentNaming public bool hasPropertyDrawer { get { if (_hasPropertyDrawerProperty == null) { _hasPropertyDrawerProperty = TriReflectionUtilities .GetUnityEditorTypeByName("PropertyHandler") .CompileInstanceProperty("hasPropertyDrawer"); } return _hasPropertyDrawerProperty(_self); } } public float GetHeight( SerializedProperty property, GUIContent label, bool includeChildren) { if (_getHeightMethod == null) { _getHeightMethod = TriReflectionUtilities .GetUnityEditorTypeByName("PropertyHandler") .CompileInstanceMethod("GetHeight"); } return _getHeightMethod(_self, property, label, includeChildren); } public bool OnGUI( Rect position, SerializedProperty property, GUIContent label, bool includeChildren) { if (_onGuiMethod == null) { _onGuiMethod = TriReflectionUtilities .GetUnityEditorTypeByName("PropertyHandler") .CompileInstanceMethod("OnGUI"); } return _onGuiMethod(_self, position, property, label, includeChildren); } } }