|
2 | 2 | using System.Collections.Generic; |
3 | 3 | using UnityEngine; |
4 | 4 | using BigasTools.Rpg; |
| 5 | +using BigasMath; |
5 | 6 |
|
6 | 7 | using UnityEditor; |
7 | 8 | namespace BigasTools.Editor{ |
8 | 9 | [CustomPropertyDrawer(typeof(Drop))] |
9 | 10 | [CanEditMultipleObjects] |
10 | 11 | public class DropDrawer : PropertyDrawer |
11 | 12 | { |
| 13 | + public override float GetPropertyHeight(SerializedProperty property, GUIContent label) |
| 14 | + { |
| 15 | + return base.GetPropertyHeight(property, label) + 150; |
| 16 | + } |
12 | 17 | public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) |
13 | 18 | { |
14 | 19 | EditorGUI.BeginProperty(position, label, property); |
15 | 20 |
|
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 | + |
18 | 30 |
|
19 | 31 | 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 | + |
20 | 41 |
|
21 | 42 | var p = property.FindPropertyRelative("item"); |
22 | 43 | var data = p.objectReferenceValue as ScriptableObject; |
23 | 44 | if(data!=null){ |
24 | | - SerializedObject obj = new SerializedObject(data); |
| 45 | + SerializedObject obj = new SerializedObject(data); |
25 | 46 | var name = obj.FindProperty("itemName"); |
| 47 | + var texture = obj.FindProperty("sprite"); |
26 | 48 | 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 | + } |
27 | 53 | } |
| 54 | + |
| 55 | + EditorGUI.indentLevel = indent; |
| 56 | + |
| 57 | + EditorGUI.EndProperty(); |
28 | 58 | } |
29 | 59 | } |
30 | 60 | } |
0 commit comments