public override Guid Inspect(string label, Guid value, object parent, DatabaseInspector inspectorWindow, InspectableDatabaseLinkAttribute link) { using (new HorizontalScope()) { GUILayout.Label(label, GUILayout.Width(width)); var valueEntry = DatabaseInspector.CultCache.Get(value); using (var h = new HorizontalScope(GUI.skin.box)) { GUILayout.Label((valueEntry as INamedEntry)?.EntryName ?? valueEntry?.ID.ToString() ?? $"Drag and drop: {DatabaseListView.FormatTypeName(link.EntryType.Name)}"); if (h.rect.Contains(Event.current.mousePosition) && (Event.current.type == EventType.DragUpdated || Event.current.type == EventType.DragPerform)) { var guid = (Guid)DragAndDrop.GetGenericData("Item"); var dragEntry = DatabaseInspector.CultCache.Get(guid); var dragValid = dragEntry != null && link.EntryType.IsInstanceOfType(dragEntry) && dragEntry != valueEntry; if (Event.current.type == EventType.DragUpdated) { DragAndDrop.visualMode = dragValid ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected; } else if (Event.current.type == EventType.DragPerform) { if (dragValid) { DragAndDrop.AcceptDrag(); GUI.changed = true; return(guid); } } } if (GUILayout.Button("-", GUILayout.Width((EditorGUIUtility.singleLineHeight - 3) * 2), GUILayout.Height(EditorGUIUtility.singleLineHeight - 3))) { return(Guid.Empty); } } } return(value); }
public override DatabaseLink <T> Inspect(string label, DatabaseLink <T> value, object parent, DatabaseInspector inspectorWindow) { if (value == null) { value = new DatabaseLink <T>(); } if (!string.IsNullOrEmpty(label)) { GUILayout.BeginHorizontal(); GUILayout.Label(label, GUILayout.Width(width)); } var valueEntry = value.Value; using (var h = string.IsNullOrEmpty(label) ? new HorizontalScope() : new HorizontalScope(GUI.skin.box)) { GUILayout.Label((valueEntry as INamedEntry)?.EntryName ?? valueEntry?.ID.ToString() ?? $"Drag and drop: {DatabaseListView.FormatTypeName(typeof(T).Name)}"); if (h.rect.Contains(Event.current.mousePosition) && (Event.current.type == EventType.DragUpdated || Event.current.type == EventType.DragPerform)) { var guid = (Guid)DragAndDrop.GetGenericData("Item"); var dragEntry = DatabaseInspector.CultCache.Get(guid); var dragValid = dragEntry is T && dragEntry != valueEntry; 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.LinkID = guid; return(value); } } } if (value.LinkID != Guid.Empty) { if (GUILayout.Button("-", GUILayout.Width((EditorGUIUtility.singleLineHeight - 3) * 2), GUILayout.Height(EditorGUIUtility.singleLineHeight - 3))) { value.LinkID = Guid.Empty; } } } if (!string.IsNullOrEmpty(label)) { GUILayout.EndHorizontal(); } return(value); }