From 81728d1c53a6af27a577924fdefff17073c30233 Mon Sep 17 00:00:00 2001 From: Jubessin Date: Sat, 15 Apr 2023 17:11:59 -0400 Subject: [PATCH] small patch - closes #7 - closes #12 - added additional RequireTag test - address issue with editor throwing error after compiling changes --- CHANGELOG.md | 10 ++++++ .../ClassAttributeEnforcerEditorWindow.cs | 31 ++++++++++++++++--- Editor/RequireTagClassAttributeEnforcer.cs | 16 ++++++++++ README.md | 2 +- Tests/Runtime/RequireBuiltInTagTest.cs | 7 +++++ Tests/Runtime/RequireBuiltInTagTest.cs.meta | 11 +++++++ package.json | 4 +-- 7 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 Tests/Runtime/RequireBuiltInTagTest.cs create mode 100644 Tests/Runtime/RequireBuiltInTagTest.cs.meta diff --git a/CHANGELOG.md b/CHANGELOG.md index 976ce44..4530d8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.2.1] --- 2023-04-15 + +### Changed + +- RequireTag enforcer now checks if tag is built-in +- added additional test for require tag attribute +- address issue with closing editor window using 'ESC' key +- address issue with editor window throwing error after compiling changes +- update package dependencies + ## [2.2.0] --- 2023-02-21 ### Added diff --git a/Editor/Editor Window/ClassAttributeEnforcerEditorWindow.cs b/Editor/Editor Window/ClassAttributeEnforcerEditorWindow.cs index 88e6bc7..7f0ad9a 100644 --- a/Editor/Editor Window/ClassAttributeEnforcerEditorWindow.cs +++ b/Editor/Editor Window/ClassAttributeEnforcerEditorWindow.cs @@ -15,6 +15,10 @@ internal sealed class ClassAttributeEnforcerEditorWindow : EditorWindow, ICustom { #region Fields + private int? + selectionWindowID, + configurationWindowID; + private Panel panel1, panel2; @@ -127,11 +131,17 @@ void ICustomEditorWindow.RemoveFocusable(Rect rect) { } private void OnGUI() { - HandleEvent(); + HandleEvent(out bool close); + + if (close) + return; + HandleWindow(); - void HandleEvent() + void HandleEvent(out bool close) { + close = false; + var evt = Event.current; if (evt == null) @@ -143,6 +153,8 @@ void HandleEvent() if (evt.keyCode == KeyCode.Escape) { Close(); + + close = true; } } void HandleWindow() @@ -153,8 +165,19 @@ void HandleWindow() BeginWindows(); // Invoke OnPanelGUI on both panels, supplying the rect that will serve as their bounds. - GUI.Window(1, panel1WindowRect, (_) => panel1.OnPanelGUI(panel1Size), "", EditorStyles.inspectorDefaultMargins); - GUI.Window(2, panel2WindowRect, (_) => panel2.OnPanelGUI(panel2Size), "", EditorStyles.inspectorDefaultMargins); + GUI.Window( + selectionWindowID ??= GenerateUniqueSessionID(), + panel1WindowRect, + (_) => panel1.OnPanelGUI(panel1Size), + "", + EditorStyles.inspectorDefaultMargins); + + GUI.Window( + configurationWindowID ??= GenerateUniqueSessionID(), + panel2WindowRect, + (_) => panel2.OnPanelGUI(panel2Size), + "", + EditorStyles.inspectorDefaultMargins); EndWindows(); diff --git a/Editor/RequireTagClassAttributeEnforcer.cs b/Editor/RequireTagClassAttributeEnforcer.cs index 3e331dd..8112ce0 100644 --- a/Editor/RequireTagClassAttributeEnforcer.cs +++ b/Editor/RequireTagClassAttributeEnforcer.cs @@ -169,6 +169,15 @@ private static void OnHierarchyChanged() Utilities.ApplyAttributeToSelectedGameObject(typesWithAttribute, ApplyAttribute); } + private static bool IsBuiltIn(string tag) => + tag == "Untagged" || + tag == "Respawn" || + tag == "Finish" || + tag == "EditorOnly" || + tag == "MainCamera" || + tag == "Player" || + tag == "GameController"; + private static void ApplyAttribute(GameObject gameObject, Attribute attribute) { if (!(attribute is RequireTagAttribute attr)) @@ -177,6 +186,13 @@ private static void ApplyAttribute(GameObject gameObject, Attribute attribute) if (gameObject.tag == attr.tag) return; + if (IsBuiltIn(attr.tag)) + { + gameObject.tag = attr.tag; + + return; + } + var asset = AssetDatabase.LoadAssetAtPath("ProjectSettings/TagManager.asset"); var tagManagerObject = new SerializedObject(asset); diff --git a/README.md b/README.md index 9d36912..e40bf0d 100644 --- a/README.md +++ b/README.md @@ -20,4 +20,4 @@ Unity package used in the development of Ikonoclast projects, containing a set o This package has dependencies. To use this package, add the following to the manifest.json file found under Assets > Packages: -* `"com.ikonoclast.common" : "https://github.com/Jubessin/com.ikonoclast.common.git#3.0.0"` +* `"com.ikonoclast.common" : "https://github.com/Jubessin/com.ikonoclast.common.git#3.1.0"` diff --git a/Tests/Runtime/RequireBuiltInTagTest.cs b/Tests/Runtime/RequireBuiltInTagTest.cs new file mode 100644 index 0000000..9013b9c --- /dev/null +++ b/Tests/Runtime/RequireBuiltInTagTest.cs @@ -0,0 +1,7 @@ +using UnityEngine; + +namespace Ikonoclast.ClassAttributes.Tests +{ + [RequireTag("Player")] + internal class RequireBuiltInTagTest : MonoBehaviour { } +} diff --git a/Tests/Runtime/RequireBuiltInTagTest.cs.meta b/Tests/Runtime/RequireBuiltInTagTest.cs.meta new file mode 100644 index 0000000..7223b26 --- /dev/null +++ b/Tests/Runtime/RequireBuiltInTagTest.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b6f900251dae4554eb6cac19c0b2132e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/package.json b/package.json index 544a576..d7b62f7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "license": "MIT", "unity": "2020.3", - "version": "2.2.0", + "version": "2.2.1", "author": { "name": "Jubessin", "url": "https://github.com/Jubessin" @@ -13,6 +13,6 @@ ], "description": "Unity package used in the development of Ikonoclast projects, containing a set of attributes that can be configured, applied to classes, and enforced when the project loads or the hierarchy changes.", "dependencies": { - "com.ikonoclast.common": "3.0.0" + "com.ikonoclast.common": "3.1.0" } } \ No newline at end of file