forked from Shardstone/trail-into-darkness
34 lines
1.2 KiB
C#
34 lines
1.2 KiB
C#
using UnityEngine;
|
|
|
|
namespace InspectorToolkit {
|
|
public class SuffixAttribute : PropertyAttribute {
|
|
public readonly string suffix;
|
|
|
|
public SuffixAttribute(string suffix) => this.suffix = suffix;
|
|
}
|
|
}
|
|
|
|
#if UNITY_EDITOR
|
|
namespace InspectorToolkit.Internal {
|
|
using UnityEditor;
|
|
|
|
[CustomPropertyDrawer(typeof(SuffixAttribute))]
|
|
public class SuffixDrawer : PropertyDrawer {
|
|
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
|
|
var suffix = new GUIContent(((SuffixAttribute)attribute).suffix);
|
|
var suffixSize = GUI.skin.label.CalcSize(suffix);
|
|
suffixSize.x += GUI.skin.label.margin.left;
|
|
var fieldPosition = position;
|
|
fieldPosition.width -= suffixSize.x;
|
|
var suffixPosition = position;
|
|
suffixPosition.x += fieldPosition.width + GUI.skin.label.margin.left;
|
|
suffixPosition.width = suffixSize.x;
|
|
EditorGUI.PropertyField(fieldPosition, property, label);
|
|
var enabled = GUI.enabled;
|
|
GUI.enabled = false;
|
|
GUI.Label(suffixPosition, suffix);
|
|
GUI.enabled = enabled;
|
|
}
|
|
}
|
|
}
|
|
#endif |