Ejemplo n.º 1
0
    public static DatabaseListView ShowWindow()
    {
        if (_instance == null)
        {
            // "Get existing open window or if none, make a new one:" says documentation.
            // But if called after script reloads a second instance will be opened! => Custom singleton required.
            DatabaseListView window = GetWindow <DatabaseListView>();
            window.titleContent = new GUIContent("DB List");
            _instance           = window;
            _instance.InitStyles();
            window.Show();
        }
        else
        {
            _instance.Focus();
        }

        return(_instance);
    }
Ejemplo n.º 2
0
    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);
    }
Ejemplo n.º 3
0
    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);
    }
Ejemplo n.º 4
0
 private void Awake()
 {
     _instance = this;
 }
Ejemplo n.º 5
0
 // Set instance on reloading the window, else it gets lost after script reload (due to PlayMode changes, ...).
 public DatabaseListView()
 {
     _instance = this;
 }