Skip to content

Commit

Permalink
Merge pull request #13 from Jubessin/2.2.1
Browse files Browse the repository at this point in the history
small patch
  • Loading branch information
Jubessin authored Apr 15, 2023
2 parents 417265d + 81728d1 commit f49b111
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 7 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 27 additions & 4 deletions Editor/Editor Window/ClassAttributeEnforcerEditorWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ internal sealed class ClassAttributeEnforcerEditorWindow : EditorWindow, ICustom
{
#region Fields

private int?
selectionWindowID,
configurationWindowID;

private Panel
panel1,
panel2;
Expand Down Expand Up @@ -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)
Expand All @@ -143,6 +153,8 @@ void HandleEvent()
if (evt.keyCode == KeyCode.Escape)
{
Close();

close = true;
}
}
void HandleWindow()
Expand All @@ -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();

Expand Down
16 changes: 16 additions & 0 deletions Editor/RequireTagClassAttributeEnforcer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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<UnityObject>("ProjectSettings/TagManager.asset");

var tagManagerObject = new SerializedObject(asset);
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
7 changes: 7 additions & 0 deletions Tests/Runtime/RequireBuiltInTagTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using UnityEngine;

namespace Ikonoclast.ClassAttributes.Tests
{
[RequireTag("Player")]
internal class RequireBuiltInTagTest : MonoBehaviour { }
}
11 changes: 11 additions & 0 deletions Tests/Runtime/RequireBuiltInTagTest.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
}
}

0 comments on commit f49b111

Please sign in to comment.