Created
June 28, 2019 03:06
-
-
Save darktable/7d0198cd183ab44bb68e1f86baf837f2 to your computer and use it in GitHub Desktop.
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
using UnityEngine; | |
using UnityEditor; | |
[CustomPropertyDrawer(typeof(Sprite))] | |
public class SpritePropertyDrawer : PropertyDrawer | |
{ | |
public override float GetPropertyHeight(SerializedProperty property, GUIContent labelN) | |
{ | |
if (property.objectReferenceValue != null) | |
{ | |
return _texSize; | |
} | |
else | |
{ | |
return base.GetPropertyHeight(property, labelN); | |
} | |
} | |
private const float _texSize = 70; | |
public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label) | |
{ | |
EditorGUI.BeginProperty(position, label, prop); | |
if (prop.objectReferenceValue != null) | |
{ | |
position.width = EditorGUIUtility.labelWidth; | |
GUI.Label(position, prop.displayName); | |
position.x += position.width; | |
position.width = _texSize; | |
position.height = _texSize; | |
prop.objectReferenceValue = EditorGUI.ObjectField(position, prop.objectReferenceValue, typeof(Sprite), false); | |
} | |
else | |
{ | |
EditorGUI.PropertyField(position, prop, true); | |
} | |
EditorGUI.EndProperty(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment