Last active
September 20, 2017 18:23
-
-
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
This file contains hidden or 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
using UnityEngine; | |
namespace Assets.Soraphis.MiniScripts { | |
public class AdditionalTextAttribute : PropertyAttribute { | |
public readonly string Text; | |
public AdditionalTextAttribute(string text) { | |
Text = text; | |
} | |
} | |
} |
This file contains hidden or 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
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