forked from Deadcows/MyBox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TagAttribute.cs
48 lines (41 loc) · 1.19 KB
/
TagAttribute.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// ----------------------------------------------------------------------------
// Author: Kaynn, Yeo Wen Qin
// https://github.com/Kaynn-Cahya
// Date: 11/02/2019
// ----------------------------------------------------------------------------
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace MyBox
{
public class TagAttribute : PropertyAttribute
{
}
}
#if UNITY_EDITOR
namespace MyBox.Internal
{
[CustomPropertyDrawer(typeof(TagAttribute))]
public class TagAttributeDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (property.propertyType != SerializedPropertyType.String)
{
if (!_checked) Warning(property);
EditorGUI.PropertyField(position, property, label);
return;
}
property.stringValue = EditorGUI.TagField(position, label, property.stringValue);
}
private bool _checked;
private void Warning(SerializedProperty property)
{
Debug.LogWarning(string.Format("Property <color=brown>{0}</color> in object <color=brown>{1}</color> is of wrong type. Expected: String",
property.name, property.serializedObject.targetObject));
_checked = true;
}
}
}
#endif