-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from SirLpc/master
Add label width attribute to change fields label width.
- Loading branch information
Showing
4 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
Assets/Editor Toolbox/Editor/Drawers/Regular/LabelWidthAttributeDrawer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Toolbox.Editor.Drawers | ||
{ | ||
[CustomPropertyDrawer(typeof(LabelWidthAttribute))] | ||
public class LabelWidthAttributeDrawer : PropertyDrawerBase | ||
{ | ||
protected override void OnGUISafe(Rect position, SerializedProperty property, GUIContent label) | ||
{ | ||
var previousWidth = EditorGUIUtility.labelWidth; | ||
EditorGUIUtility.labelWidth = Attribute.Width; | ||
EditorGUI.PropertyField(position, property, label, property.isExpanded); | ||
EditorGUIUtility.labelWidth = previousWidth; | ||
} | ||
|
||
private LabelWidthAttribute Attribute => attribute as LabelWidthAttribute; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/Editor Toolbox/Editor/Drawers/Regular/LabelWidthAttributeDrawer.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
Assets/Editor Toolbox/Runtime/Attributes/Regular/LabelWidthAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Diagnostics; | ||
|
||
namespace UnityEngine | ||
{ | ||
/// <summary> | ||
/// Change field label width. | ||
/// <para>Label width</para> | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)] | ||
[Conditional("UNITY_EDITOR")] | ||
public class LabelWidthAttribute : PropertyAttribute | ||
{ | ||
public LabelWidthAttribute(float width = 120) | ||
{ | ||
Width = width; | ||
} | ||
|
||
public float Width { get; private set; } | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/Editor Toolbox/Runtime/Attributes/Regular/LabelWidthAttribute.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.