Skip to content

Instantly share code, notes, and snippets.

@soraphis
Last active September 20, 2017 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soraphis/03de57199bf09a69178170460c009292 to your computer and use it in GitHub Desktop.
Save soraphis/03de57199bf09a69178170460c009292 to your computer and use it in GitHub Desktop.
A small editor extension to add additional text informations into the Inspectors TextFields
using UnityEngine;
namespace Assets.Soraphis.MiniScripts {
public class AdditionalTextAttribute : PropertyAttribute {
public readonly string Text;
public AdditionalTextAttribute(string text) {
Text = text;
}
}
}
using UnityEditor;
using UnityEngine;
/*
* usage: simply put a Attribute in front of your variables like this:
* [AdditionalText("Pixel")]public float MinimumDragDistance = 20;
* - use at own risk for variables that are not rendered in textfields (you'll might get multiple texts over each other)
*/
namespace Assets.Soraphis.MiniScripts.Editor {
[CustomPropertyDrawer(typeof(AdditionalTextAttribute))]
public class AdditionalTextDrawer : PropertyDrawer {
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
//base.OnGUI(position, property, label);
EditorGUI.PropertyField(position, property, label);
var style = new GUIStyle(EditorStyles.label);
style.alignment = TextAnchor.MiddleRight;
style.normal.textColor = Color.gray;
var attrib = attribute as AdditionalTextAttribute;
GUI.Label(position, attrib.Text, style);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment