Skip to content

Commit a3b570d

Browse files
committed
added label
1 parent 9e0bcfc commit a3b570d

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

Editor/Attributes/LabelDrawer.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
4+
namespace Lachee.Attributes.Editor
5+
{
6+
[CustomPropertyDrawer(typeof(LabelAttribute))]
7+
public class LabelDrawer : PropertyDrawer
8+
{
9+
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
10+
{
11+
LabelAttribute attr = (LabelAttribute)attribute;
12+
EditorGUI.PropertyField(position, property, attr.label, true);
13+
}
14+
}
15+
}

Editor/Attributes/LabelDrawer.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using UnityEngine;
3+
4+
namespace Lachee.Attributes
5+
{
6+
/// <summary>
7+
/// Makes object readonly in the editor.
8+
/// </summary>
9+
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Class | AttributeTargets.Struct, Inherited = true)]
10+
public class LabelAttribute : PropertyAttribute
11+
{
12+
/// <summary>
13+
/// The label and tooltip for the property.
14+
/// </summary>
15+
public GUIContent label;
16+
17+
/// <summary>
18+
/// Creates a label
19+
/// </summary>
20+
/// <param name="label">The name of the property</param>
21+
/// <param name="tooltip">The tooltip for the property</param>
22+
public LabelAttribute(string label, string tooltip = "")
23+
{
24+
this.label = new GUIContent(label, tooltip);
25+
}
26+
27+
/// <summary>
28+
/// Creates a new label from the GUIContent
29+
/// </summary>
30+
/// <param name="content"></param>
31+
public LabelAttribute(GUIContent content)
32+
{
33+
this.label = content;
34+
}
35+
}
36+
}

Runtime/Attributes/LabelAttribute.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)