Skip to content

Commit 0ab97ae

Browse files
committed
drawer fully working
1 parent 83d3ac7 commit 0ab97ae

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

Editor/DropDrawer.cs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,59 @@
22
using System.Collections.Generic;
33
using UnityEngine;
44
using BigasTools.Rpg;
5+
using BigasMath;
56

67
using UnityEditor;
78
namespace BigasTools.Editor{
89
[CustomPropertyDrawer(typeof(Drop))]
910
[CanEditMultipleObjects]
1011
public class DropDrawer : PropertyDrawer
1112
{
13+
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
14+
{
15+
return base.GetPropertyHeight(property, label) + 150;
16+
}
1217
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
1318
{
1419
EditorGUI.BeginProperty(position, label, property);
1520

16-
var item = new Rect(position.x, position.y, position.width, position.height);
17-
var itemName = new Rect(position.x, position.y + 50, 50, 20);
21+
var item = new Rect(position.x + 50, position.y, 80, 20);
22+
var chance = new Rect(position.x + 50, position.y + 30, 50, 20);
23+
var itemName = new Rect(position.x, position.y + 10, 50, 20);
24+
var itemIcon = new Rect(position.x + 10, position.y + 30, 32, 32);
25+
var itemChance = new Rect(position.x, position.y + 60, 120, 20);
26+
27+
var indent = EditorGUI.indentLevel;
28+
EditorGUI.indentLevel = 0;
29+
1830

1931
EditorGUI.PropertyField(item, property.FindPropertyRelative("item"), GUIContent.none);
32+
EditorGUI.PropertyField(chance, property.FindPropertyRelative("chance"), GUIContent.none);
33+
34+
var c = property.FindPropertyRelative("chance").intValue;
35+
if(c!=0){
36+
EditorGUI.LabelField(itemChance, $"{BMathPercentage.GetPercentageFromFloat(1, c)}% (1/{c})");
37+
}
38+
39+
EditorGUI.DrawRect(itemName, Color.red);
40+
2041

2142
var p = property.FindPropertyRelative("item");
2243
var data = p.objectReferenceValue as ScriptableObject;
2344
if(data!=null){
24-
SerializedObject obj = new SerializedObject(data);
45+
SerializedObject obj = new SerializedObject(data);
2546
var name = obj.FindProperty("itemName");
47+
var texture = obj.FindProperty("sprite");
2648
EditorGUI.LabelField(itemName, name.stringValue);
49+
var a = AssetPreview.GetAssetPreview(texture.objectReferenceValue);
50+
if(a!=null){
51+
EditorGUI.DrawPreviewTexture(itemIcon, AssetPreview.GetAssetPreview(texture.objectReferenceValue));
52+
}
2753
}
54+
55+
EditorGUI.indentLevel = indent;
56+
57+
EditorGUI.EndProperty();
2858
}
2959
}
3060
}

Editor/InputProfileDrawer.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
[CustomPropertyDrawer(typeof(InputProfile))]
1010
public class InputProfileDrawer : PropertyDrawer
1111
{
12+
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
13+
{
14+
return base.GetPropertyHeight(property, label);
15+
}
1216
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
1317
{
1418
EditorGUI.BeginProperty(position, label, property);

Samples/EntityExamples.unity

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,4 +707,8 @@ MonoBehaviour:
707707
m_Script: {fileID: 11500000, guid: c33aa35226c7ef8459c14419ba3f25a3, type: 3}
708708
m_Name:
709709
m_EditorClassIdentifier:
710+
itemDrop:
711+
item: {fileID: 11400000, guid: b27eeae83168bce49ba810731a0200b5, type: 2}
712+
chance: 4
713+
roll: 12
710714
entityToSpawn: {fileID: 4739109322253644523, guid: 0a001269a7880c74bb4ce4d03dd45397, type: 3}

Tests/Runtime/ItemTest.asset

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ MonoBehaviour:
1212
m_Script: {fileID: 11500000, guid: 8fafe0fcb32c6904593545c59b3e1c2e, type: 3}
1313
m_Name: ItemTest
1414
m_EditorClassIdentifier:
15-
itemName: Item
15+
itemName: Boots
1616
description: Base Description
1717
quantity: 1
18-
sprite: {fileID: 0}
18+
sprite: {fileID: 21300000, guid: 36c9a9aa373ab764cb4dba23cdc4c675, type: 3}

0 commit comments

Comments
 (0)