Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [CustomPropertyDrawer(typeof(TestSprite))]
- public class TestSpriteDrawer : PropertyDrawer
- {
- public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
- {
- float spriteHeight = 130f;
- float restHeight = EditorGUI.GetPropertyHeight(property, label, true);
- return spriteHeight + restHeight;
- }
- public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
- {
- EditorGUI.BeginProperty(position, label, property);
- SerializedProperty spriteProp = property.FindPropertyRelative("mySpriteTest");
- Rect spriteRect = new Rect(position.x, position.y, 128, 128);
- Object newSprite = EditorGUI.ObjectField(spriteRect, spriteProp.objectReferenceValue, typeof(Sprite), false);
- if (newSprite != spriteProp.objectReferenceValue)
- {
- spriteProp.objectReferenceValue = newSprite;
- }
- Sprite sprite = spriteProp.objectReferenceValue as Sprite;
- if (sprite != null)
- {
- Texture2D texture = AssetPreview.GetAssetPreview(sprite);
- if (texture != null) GUI.DrawTexture(spriteRect, texture, ScaleMode.ScaleToFit);
- }
- float offsetY = spriteRect.yMax + 4f;
- Rect restRect = new Rect(position.x, offsetY, position.width, position.height - offsetY);
- EditorGUI.PropertyField(restRect, property, label, true);
- EditorGUI.EndProperty();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment