-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDisplayNameAttribute.cs
More file actions
39 lines (33 loc) · 1006 Bytes
/
DisplayNameAttribute.cs
File metadata and controls
39 lines (33 loc) · 1006 Bytes
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
using System;
using System.Diagnostics;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace Jackey.Utilities.Attributes {
/// <summary>
/// Display a field with a custom name
/// </summary>
[AttributeUsage(AttributeTargets.Field)]
[Conditional("UNITY_EDITOR")]
public sealed class DisplayNameAttribute : PropertyAttribute {
public string Name { get; }
public DisplayNameAttribute(string name) {
Name = name;
}
}
#if UNITY_EDITOR
namespace PropertyDrawers {
[CustomPropertyDrawer(typeof(DisplayNameAttribute))]
public class DisplayNamePropertyDrawer : PropertyDrawer {
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
return EditorGUI.GetPropertyHeight(property, label);
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
label.text = ((DisplayNameAttribute)attribute).Name;
EditorGUI.PropertyField(position, property, label, true);
}
}
}
#endif
}