Created
June 25, 2019 10:44
-
-
Save tjukic/7fa57c2771fc86b04fa3f86dff672618 to your computer and use it in GitHub Desktop.
sprite preview
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