Advertisement
Guest User

Untitled

a guest
Jun 30th, 2019
654
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using UnityEditor;
  3.  
  4. [CustomPropertyDrawer(typeof(Sprite))]
  5. public class SpritePropertyDrawer : PropertyDrawer
  6. {
  7.     public override float GetPropertyHeight(SerializedProperty property, GUIContent labelN)
  8.     {
  9.         if (property.objectReferenceValue != null)
  10.         {
  11.             return _texSize;
  12.         }
  13.         else
  14.         {
  15.             return base.GetPropertyHeight(property, labelN);
  16.         }
  17.     }
  18.  
  19.     private const float _texSize = 70;
  20.  
  21.    
  22.  
  23.     public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
  24.     {
  25.         EditorGUI.BeginProperty(position, label, prop);
  26.  
  27.         if (prop.objectReferenceValue != null && !prop.hasMultipleDifferentValues)
  28.         {
  29.             position.width = EditorGUIUtility.labelWidth;
  30.             GUI.Label(position, prop.displayName);
  31.  
  32.             position.x += position.width;
  33.             position.width = _texSize;
  34.             position.height = _texSize;
  35.  
  36.             prop.objectReferenceValue = EditorGUI.ObjectField(position, prop.objectReferenceValue, typeof(Sprite), false);
  37.         }
  38.         else
  39.         {
  40.             EditorGUI.PropertyField(position, prop, true);
  41.         }
  42.  
  43.         EditorGUI.EndProperty();
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement