-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSpritePropertyDrawer.cs
More file actions
43 lines (36 loc) · 1.16 KB
/
SpritePropertyDrawer.cs
File metadata and controls
43 lines (36 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using UnityEngine;
using UnityEditor;
[CustomPropertyDrawer(typeof(Sprite))]
public class SpritePropertyDrawer : PropertyDrawer
{
private const float textSize = 70;
public override float GetPropertyHeight(SerializedProperty property, GUIContent labelN)
{
if (property.objectReferenceValue != null)
{
return textSize;
}
else
{
return base.GetPropertyHeight(property, labelN);
}
}
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 = textSize;
position.height = textSize;
prop.objectReferenceValue = EditorGUI.ObjectField(position, prop.objectReferenceValue, typeof(Sprite), false);
}
else
{
EditorGUI.PropertyField(position, prop, true);
}
EditorGUI.EndProperty();
}
}