From 31c51a1b2a71f09c3b151dbaa12b12478969694e Mon Sep 17 00:00:00 2001 From: Alexander Filippov Date: Fri, 8 Jul 2022 21:16:41 +0200 Subject: [PATCH] Added ReadOnlyOnPlayField Attribute. --- Editor/ReadOnlyOnPlayFieldDrawer.cs | 18 ++++++++++++++++++ Editor/ReadOnlyOnPlayFieldDrawer.cs.meta | 3 +++ Runtime/ReadOnlyOnPlayFieldAttribute.cs | 6 ++++++ Runtime/ReadOnlyOnPlayFieldAttribute.cs.meta | 11 +++++++++++ package.json | 2 +- 5 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 Editor/ReadOnlyOnPlayFieldDrawer.cs create mode 100644 Editor/ReadOnlyOnPlayFieldDrawer.cs.meta create mode 100644 Runtime/ReadOnlyOnPlayFieldAttribute.cs create mode 100644 Runtime/ReadOnlyOnPlayFieldAttribute.cs.meta diff --git a/Editor/ReadOnlyOnPlayFieldDrawer.cs b/Editor/ReadOnlyOnPlayFieldDrawer.cs new file mode 100644 index 0000000..d6fa26e --- /dev/null +++ b/Editor/ReadOnlyOnPlayFieldDrawer.cs @@ -0,0 +1,18 @@ +using Runtime; +using UnityEditor; +using UnityEngine; + +namespace Utils +{ + [CustomPropertyDrawer(typeof(ReadOnlyOnPlayFieldAttribute))] + public class ReadOnlyOnPlayFieldDrawer : PropertyDrawer + { + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + var state = Application.isPlaying; + if (state) GUI.enabled = false; + EditorGUI.PropertyField(position, property, label, true); + if (state) GUI.enabled = true; + } + } +} \ No newline at end of file diff --git a/Editor/ReadOnlyOnPlayFieldDrawer.cs.meta b/Editor/ReadOnlyOnPlayFieldDrawer.cs.meta new file mode 100644 index 0000000..7f936ef --- /dev/null +++ b/Editor/ReadOnlyOnPlayFieldDrawer.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 9c45448d04584b318be7490a85ae4681 +timeCreated: 1657132838 \ No newline at end of file diff --git a/Runtime/ReadOnlyOnPlayFieldAttribute.cs b/Runtime/ReadOnlyOnPlayFieldAttribute.cs new file mode 100644 index 0000000..f3ae441 --- /dev/null +++ b/Runtime/ReadOnlyOnPlayFieldAttribute.cs @@ -0,0 +1,6 @@ +using UnityEngine; + +namespace Utils +{ + public class ReadOnlyOnPlayFieldAttribute : PropertyAttribute { } +} \ No newline at end of file diff --git a/Runtime/ReadOnlyOnPlayFieldAttribute.cs.meta b/Runtime/ReadOnlyOnPlayFieldAttribute.cs.meta new file mode 100644 index 0000000..5872885 --- /dev/null +++ b/Runtime/ReadOnlyOnPlayFieldAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 751004c02d9af6559a8f5c714cf58568 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/package.json b/package.json index 35ccb76..38878bd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ru.shazbot.utils", - "version": "4.0.0", + "version": "4.1.0", "displayName": "Utils", "description": "Utility useful for almost any project.", "licensesUrl": "https://git.shazbot.ru/Utils.git/tree/LICENSE.md",