-
-
Save rodamn/5219c75dc7ca3bdc97372bfbab2da75b to your computer and use it in GitHub Desktop.
Unity 3D Compact GUI Attribute for Vectors and Quaternions.
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; | |
public class CompactGuiAttribute : PropertyAttribute {} |
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; | |
using UnityEditor; | |
[CustomPropertyDrawer (typeof(CompactGuiAttribute))] | |
public class CompactGuiDrawer : PropertyDrawer | |
{ | |
const float ShrinkLabelAmount = 20f; | |
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) | |
{ | |
float labelWidthCache = EditorGUIUtility.labelWidth; | |
bool wideModeCache = EditorGUIUtility.wideMode; | |
EditorGUIUtility.labelWidth -= ShrinkLabelAmount; | |
EditorGUIUtility.wideMode = true; | |
EditorGUI.PropertyField (position, property, label); | |
EditorGUIUtility.wideMode = wideModeCache; | |
EditorGUIUtility.labelWidth = labelWidthCache; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
USAGE:
CompactGuiAttribute.cs: Save to any non-editor folder or subfolder (e.g. Scripts/)
CompactGuiDrawer.cs: Save to editor folder or subfolder (e.g. Scripts/Editor/)
For any Unity Vector* or Quaternion property, precede with the attribute [CompactGui] as such:
COMPATIBILITY