public override bool DrawField(ref object obj, plyBlock fieldOfBlock) { bool ret = (obj == null); InventoryItemBaseFieldData target = obj == null ? new InventoryItemBaseFieldData() : obj as InventoryItemBaseFieldData; if (GUILayout.Button((target.item == null) ? "(No item selected)" : target.item.name, EditorStyles.objectField)) { var picker = InventoryItemPicker.Get(); picker.Show(InventoryEditorUtil.GetItemDatabase(true, false)); picker.OnPickObject += (item) => { target.item = item; GUI.changed = true; ed.ForceSerialise(); ed.Repaint(); }; } obj = target; return(ret); }
public plyStatsEditor(string name, EditorWindow window) { this.name = name; this.window = window; this.requiresDatabase = true; resultList = new ReorderableList(attributes, typeof(plyGameAttributeDatabaseModel), false, true, false, false); resultList.drawHeaderCallback += rect => { var r = rect; r.width = 40; r.x += 15; // Little offset on the start EditorGUI.LabelField(r, "Show"); var r2 = rect; r2.width -= 50; r2.width /= 3; r2.x += 50; EditorGUI.LabelField(r2, "Display name"); r2.x += r2.width; EditorGUI.LabelField(r2, "Category"); r2.x += r2.width; EditorGUI.LabelField(r2, "Formatter"); }; //resultList.elementHeight = 30; resultList.drawElementCallback += (rect, index, active, focused) => { rect.height = 16; rect.y += 2; if (index >= InventoryEditorUtil.selectedDatabase.plyAttributes.Length) { return; } var stat = InventoryEditorUtil.selectedDatabase.plyAttributes[index]; var r2 = rect; r2.width -= 50; r2.width /= 3; r2.width -= 10; r2.x += 50; var r = rect; r.width = 40; r.x += 15; stat.show = EditorGUI.Toggle(r, stat.show); GUI.enabled = stat.show; if (index >= 0 && index <= attributresStrings.Length) { EditorGUI.LabelField(r2, attributresStrings[index]); } r2.x += r2.width; r2.x += 10; stat.category = EditorGUI.TextField(r2, stat.category); r2.x += r2.width; r2.x += 10; stat.formatter = InventoryEditorUtil.SimpleObjectPicker <CharacterStatFormatterBase>(r2, "", stat.formatter, false, false); GUI.enabled = true; if (GUI.changed) { EditorUtility.SetDirty(InventoryEditorUtil.selectedDatabase); } }; }