public override Dictionary <Guid, float> Inspect(string label, Dictionary <Guid, float> value, object parent, DatabaseInspector inspectorWindow, InspectableDatabaseLinkAttribute attribute) { Space(); LabelField(label, EditorStyles.boldLabel); using (var v = new VerticalScope(GUI.skin.box)) { if (value.Count == 0) { using (new HorizontalScope(DatabaseInspector.ListItemStyle)) { GUILayout.Label("Drag from list to add item"); } } foreach (var ingredient in value.ToArray()) { using (new HorizontalScope(DatabaseInspector.ListItemStyle)) { var entry = DatabaseInspector.CultCache.Get(ingredient.Key); if (entry == null) { value.Remove(ingredient.Key); GUI.changed = true; return(value); } if (entry is INamedEntry named) { GUILayout.Label(named.EntryName); } else { GUILayout.Label(entry.ID.ToString()); } value[ingredient.Key] = DelayedFloatField(value[ingredient.Key], GUILayout.Width(50)); // var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); // GUI.DrawTexture(rect, Icons.Instance.minus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0); if (GUILayout.Button("-", GUILayout.Width((EditorGUIUtility.singleLineHeight - 3) * 2), GUILayout.Height(EditorGUIUtility.singleLineHeight - 3))) { value.Remove(ingredient.Key); } } } if (v.rect.Contains(Event.current.mousePosition)) { var dragData = DragAndDrop.GetGenericData("Item"); var isId = dragData is Guid guid; var dragEntry = isId ? DatabaseInspector.CultCache.Get(guid) : null; var correctType = attribute.EntryType.IsInstanceOfType(dragEntry); if (Event.current.type == EventType.DragUpdated) { DragAndDrop.visualMode = correctType ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected; } else if (Event.current.type == EventType.DragPerform) { if (isId && correctType) { DragAndDrop.AcceptDrag(); value[guid] = 1; GUI.changed = true; } } } } return(value); }
public override List <Guid> Inspect(string label, List <Guid> value, object parent, DatabaseInspector inspectorWindow, InspectableDatabaseLinkAttribute link) { using (var v = new VerticalScope(GUI.skin.box)) { GUILayout.Label(label, EditorStyles.boldLabel); if (value.Count == 0) { using (new HorizontalScope(ListItemStyle)) { GUILayout.Label($"Drag from list to add {link.EntryType.Name}"); } } foreach (var guid in value.ToArray()) { using (new HorizontalScope(ListItemStyle)) { var entry = DatabaseInspector.CultCache.Get(guid); if (entry == null) { value.Remove(guid); GUI.changed = true; } else { GUILayout.Label((entry as INamedEntry)?.EntryName ?? entry.ID.ToString()); // var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); // GUI.DrawTexture(rect, Icons.Instance.minus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0); if (GUILayout.Button("-", GUILayout.Width((EditorGUIUtility.singleLineHeight - 3) * 2), GUILayout.Height(EditorGUIUtility.singleLineHeight - 3))) { value.Remove(guid); } } } } if (v.rect.Contains(Event.current.mousePosition)) { var guid = DragAndDrop.GetGenericData("Item"); var dragObj = DragAndDrop.GetGenericData("Item") is Guid?DatabaseInspector.CultCache.Get((Guid)guid) : null; var dragValid = dragObj != null && link.EntryType.IsInstanceOfType(dragObj) && !value.Contains(dragObj.ID); if (Event.current.type == EventType.DragUpdated) { DragAndDrop.visualMode = dragValid ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected; } else if (Event.current.type == EventType.DragPerform) { if (dragValid) { DragAndDrop.AcceptDrag(); value.Add((Guid)guid); GUI.changed = true; } } } } return(value); }