From 7adf517f8aa0b3c7d2169308f5f1fab6518aa517 Mon Sep 17 00:00:00 2001 From: uurha Date: Sat, 29 Jul 2023 00:51:21 +0000 Subject: [PATCH] Merge pull request #64 dev --- .../EditorTools/Helpers/EditorGUIHelpers.cs | 22 +++++++++++++++++++ .../Helpers/EditorGUIHelpers.cs.meta | 3 +++ Editor/EditorTools/Helpers/HideGroup.cs | 12 +++++----- package.json | 2 +- 4 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 Editor/EditorTools/Helpers/EditorGUIHelpers.cs create mode 100644 Editor/EditorTools/Helpers/EditorGUIHelpers.cs.meta diff --git a/Editor/EditorTools/Helpers/EditorGUIHelpers.cs b/Editor/EditorTools/Helpers/EditorGUIHelpers.cs new file mode 100644 index 0000000..e1a076a --- /dev/null +++ b/Editor/EditorTools/Helpers/EditorGUIHelpers.cs @@ -0,0 +1,22 @@ +using System.Reflection; +using Better.Tools.Runtime; +using UnityEditor; +using UnityEngine; + +namespace Better.EditorTools.Helpers +{ + public static class EditorGUIHelpers + { + private static MethodInfo _defaultPropertyField; + public static bool PropertyFieldSafe(Rect position, SerializedProperty property, GUIContent label) + { + if (_defaultPropertyField == null) + { + var type = typeof(EditorGUI); + _defaultPropertyField = type.GetMethod("DefaultPropertyField", BetterEditorDefines.MethodFlags); + } + + return (bool)_defaultPropertyField.Invoke(null, new object[] { position, property, label }); + } + } +} \ No newline at end of file diff --git a/Editor/EditorTools/Helpers/EditorGUIHelpers.cs.meta b/Editor/EditorTools/Helpers/EditorGUIHelpers.cs.meta new file mode 100644 index 0000000..a436e52 --- /dev/null +++ b/Editor/EditorTools/Helpers/EditorGUIHelpers.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 54d3b062d8034e8ab2da5501849cdb95 +timeCreated: 1690589649 \ No newline at end of file diff --git a/Editor/EditorTools/Helpers/HideGroup.cs b/Editor/EditorTools/Helpers/HideGroup.cs index 425d26a..ca4422e 100644 --- a/Editor/EditorTools/Helpers/HideGroup.cs +++ b/Editor/EditorTools/Helpers/HideGroup.cs @@ -1,27 +1,25 @@ -using UnityEngine; +using UnityEditor; +using UnityEngine; namespace Better.EditorTools.Helpers { - public class HideGroup : GUI.Scope + public class HideGroup : EditorGUI.DisabledGroupScope { private readonly Color _color; - private readonly bool _wasEnabled; - public HideGroup(bool satisfied) + public HideGroup(bool satisfied) : base(satisfied) { _color = GUI.color; if (satisfied) { GUI.color = Color.clear; - GUI.enabled = false; } - _wasEnabled = GUI.enabled; } protected override void CloseScope() { + base.CloseScope(); GUI.color = _color; - GUI.enabled = _wasEnabled; } } } \ No newline at end of file diff --git a/package.json b/package.json index f22319f..9b2c198 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "com.uurha.bettereditortools", "displayName": "Better Editor Tools", "description": "Collection of useful tools for Unity Editor", - "version": "1.0.53", + "version": "1.0.55", "unity": "2020.1", "dependencies": { "com.uurha.betterdatastructures": "0.1.0",