public DropRect CreateDropRect() { DropRect dropRect = new DropRect(); _dropRects.Add(dropRect); return(dropRect); }
private void DropUpdate() { if (_dropRects.Count == 0) { return; } //_dropRects.ForEach(x => GUI.Box(x.Position, "")); //_dropRects.ForEach(x => x.Childs.ForEach(y => GUI.Box(y, ""))); Event e = Event.current; switch (e.type) { case EventType.DragUpdated: case EventType.DragPerform: case EventType.DragExited: Debug.Log(e.type); break; } switch (e.type) { case EventType.DragUpdated: case EventType.DragPerform: _isDrag = true; Rect dropLine = Rect.zero; for (int i = _dropRects.Count - 1; i >= 0; i--) { DropRect dropRect = _dropRects[i]; if (!dropRect.Position.Contains(e.mousePosition)) { continue; } GUI.Box(dropRect.Position, ""); if (dropRect.Validate == null || dropRect.Validate()) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; int index = -1; for (int l = 0; l < dropRect.Childs.Count; l++) { if (dropRect.Childs[l].Contains(e.mousePosition)) { if (e.mousePosition.y > dropRect.Childs[l].center.y) { index = l + 1 < dropRect.Childs.Count ? l + 1 : -1; } else { index = l; } break; } } if (index >= 0) { dropLine = dropRect.Childs[index]; dropLine.position += new Vector2(4, -1); } else { dropLine = dropRect.Position; dropLine.position += new Vector2(4, dropLine.height - 4); index = dropRect.Childs.Count; } dropLine.width -= 8; dropLine.height = 2; if (e.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); //Debug.Log("Drag"); _isDrag = false; _dropLine = Rect.zero; if (dropRect.Action != null) { dropRect.Action.Invoke(index); } } } break; } if (_dropLine != dropLine) { _dropLine = dropLine; GUI.changed = true; } break; case EventType.DragExited: _isDrag = false; _dropLine = Rect.zero; //ListDrawer.ListDragData = null; break; } if (_isDrag) { GUI.Box(_dropLine, "", Style.ListDropLine); } }