Skip to content

Commit

Permalink
TagFieldAttribute
Browse files Browse the repository at this point in the history
  • Loading branch information
oleghcp committed Apr 27, 2024
1 parent b41a749 commit 54a6d5b
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Code/Editor/Drawers/Attributes/LayerFieldDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
{
if (EditorUtilityExt.GetFieldType(this).GetTypeCode() != TypeCode.Int32)
{
EditorGui.ErrorLabel(position, label, $"Use {nameof(LayerFieldAttribute)} with int.");
EditorGui.ErrorLabel(position, label, $"Use {nameof(LayerFieldAttribute)} with {nameof(Int32)}.");
return;
}

Expand Down
23 changes: 23 additions & 0 deletions Code/Editor/Drawers/Attributes/TagFieldDrawer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using OlegHcp.CSharp;
using OlegHcp.Inspector;
using UnityEditor;
using UnityEngine;

namespace OlegHcpEditor.Drawers.Attributes
{
[CustomPropertyDrawer(typeof(TagFieldAttribute))]
internal class TagFieldDrawer : AttributeDrawer<TagFieldAttribute>
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (EditorUtilityExt.GetFieldType(this).GetTypeCode() != TypeCode.String)
{
EditorGui.ErrorLabel(position, label, $"Use {nameof(TagFieldAttribute)} with {nameof(String)}.");
return;
}

property.stringValue = EditorGUI.TagField(position, label, property.stringValue);
}
}
}
11 changes: 11 additions & 0 deletions Code/Editor/Drawers/Attributes/TagFieldDrawer.cs.meta

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

8 changes: 8 additions & 0 deletions Code/Runtime/OlegHcp/Inspector/TagFieldAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;
using UnityEngine;

namespace OlegHcp.Inspector
{
[AttributeUsage(AttributeTargets.Field)]
public sealed class TagFieldAttribute : PropertyAttribute { }
}
11 changes: 11 additions & 0 deletions Code/Runtime/OlegHcp/Inspector/TagFieldAttribute.cs.meta

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

0 comments on commit 54a6d5b

Please sign in to comment.