예제 #1
0
        public void ProcessDropInsertion(int insertionIndex)
        {
            if (Event.current.type == EventType.DragPerform)
            {
                var draggedItem = (DraggedListItem)DragAndDrop.GetGenericData(DraggedListItem.TypeName);

                if (draggedItem.sourceListAdaptor == this)
                {
                    Move(draggedItem.index, insertionIndex);
                }
                else
                {
                    if (CanDrop(draggedItem.item))
                    {
                        metadata.Insert(insertionIndex, draggedItem.item);

                        itemAdded?.Invoke(draggedItem.item);

                        draggedItem.sourceListAdaptor.Remove(draggedItem.index);
                        selectedList = this;

                        draggedItem.sourceListAdaptor.parentInspector.SetHeightDirty();
                        parentInspector.SetHeightDirty();
                    }
                }

                GUI.changed = true;
                Event.current.Use();
            }
        }
예제 #2
0
        public override void DrawItem(Rect position, int index)
        {
            LudiqGUI.Inspector(metadata[index], position, GUIContent.none);

            var item = this[index];

            var controlID = GUIUtility.GetControlID(FocusType.Passive);

            switch (Event.current.GetTypeForControl(controlID))
            {
            case EventType.MouseDown:
                // Exclude delete button from draggable position
                var draggablePosition = ReorderableListGUI.CurrentItemTotalPosition;
                draggablePosition.xMax = position.xMax + 2;

                if (Event.current.button == (int)MouseButton.Left && draggablePosition.Contains(Event.current.mousePosition))
                {
                    selectedList = this;
                    selectedItem = item;

                    if (alwaysDragAndDrop || Event.current.alt)
                    {
                        GUIUtility.hotControl  = controlID;
                        mouseDragStartPosition = Event.current.mousePosition;
                        Event.current.Use();
                    }
                }

                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == controlID)
                {
                    GUIUtility.hotControl = 0;

                    if (Vector2.Distance(mouseDragStartPosition, Event.current.mousePosition) >= MouseDragThreshold)
                    {
                        DragAndDrop.PrepareStartDrag();
                        DragAndDrop.objectReferences = new UnityObject[0];
                        DragAndDrop.paths            = new string[0];
                        DragAndDrop.SetGenericData(DraggedListItem.TypeName, new DraggedListItem(this, index, item));
                        DragAndDrop.StartDrag(metadata.path);
                    }

                    Event.current.Use();
                }

                break;
            }
        }
예제 #3
0
 public ListInspector(Metadata metadata) : base(metadata)
 {
     adaptor = new MetadataListAdaptor(metadata, this);
 }
예제 #4
0
 public DraggedListItem(MetadataListAdaptor sourceListAdaptor, int index, object item)
 {
     this.sourceListAdaptor = sourceListAdaptor;
     this.index             = index;
     this.item = item;
 }