public bool DragObjectEnd(object obj) { bool newDropPosition = false; DropArea drop; if (objectsDropArea.TryGetValue(obj, out drop)) { Event currentEvent = Event.current; if (Event.current != null) { Vector3 mouse = InputHelpers.MouseOnGUI(); if (InputHelpers.MouseDown(0) && CurrentDragObject.CurrentRect.Contains(mouse) && !somethingIsDraggingAlready) { somethingIsDraggingAlready = true; CurrentDragObject.IsDragging = true; CurrentDragObject.Ease = true; CurrentDragObject.t = 0; CurrentDragObject.EaseStartRect = CurrentDragObject.StartRect; CurrentDragObject.EaseEndRect = new Rect( mouse.x - CurrentDragObject.CurrentRect.width / 2f, mouse.y - CurrentDragObject.CurrentRect.height / 2f, CurrentDragObject.CurrentRect.width, CurrentDragObject.CurrentRect.height); } else if (InputHelpers.MouseMoved(0) && CurrentDragObject.IsDragging) { CurrentDragObject.IsDragging = true; CurrentDragObject.t = 0; CurrentDragObject.EaseStartRect = CurrentDragObject.CurrentRect; CurrentDragObject.EaseEndRect = new Rect( mouse.x - CurrentDragObject.CurrentRect.width / 2f, mouse.y - CurrentDragObject.CurrentRect.height / 2f, CurrentDragObject.CurrentRect.width, CurrentDragObject.CurrentRect.height); } else if (InputHelpers.MouseUp(0) && CurrentDragObject.IsDragging) { CurrentDragObject.t = 0; CurrentDragObject.IsDragging = false; somethingIsDraggingAlready = false; CurrentDragObject.Ease = true; DropArea selectedDropArea = null; foreach (DropArea dropArea in GetValidDropAreas(obj.GetType())) { if (dropArea.ContainsMouse() && dropArea.Object == null) { selectedDropArea = dropArea; newDropPosition = true; break; } } if (selectedDropArea != null && selectedDropArea.Object == null) { CurrentDragObject.EaseStartRect = CurrentDragObject.CurrentRect; CurrentDragObject.EaseEndRect = selectedDropArea.Rect; selectedDropArea.Object = obj; CurrentDragObject.DropArea.Object = null; objectsDropArea[obj] = selectedDropArea; CurrentDragObject.DropArea = selectedDropArea; CurrentDragObject.StartRect = CurrentDragObject.DropArea.Rect; } else { CurrentDragObject.EaseStartRect = CurrentDragObject.CurrentRect; CurrentDragObject.EaseEndRect = CurrentDragObject.StartRect; } } } easeDragObject(); dragObjectsInProgress.Pop(); } return(newDropPosition); }
public bool ContainsMouse() { return(Rect.Contains(InputHelpers.MouseOnGUI())); }
public void OnGUI() { for (int i = 0; i < 4; i++) { dragNDrop.DropAreaBegin("A" + i); CustomGUIUtils.DrawBox(dragNDrop.ThisDropArea.Rect, XKCDColors.LightRed); GUI.Label(dragNDrop.ThisDropArea.Rect, dragNDrop.ThisDropArea.ToString()); dragNDrop.DropAreaEnd("A" + i); dragNDrop.DropAreaBegin("B" + i); CustomGUIUtils.DrawBox(dragNDrop.ThisDropArea.Rect, XKCDColors.GreenApple); GUI.Label(dragNDrop.ThisDropArea.Rect, dragNDrop.ThisDropArea.ToString()); dragNDrop.DropAreaEnd("B" + i); dragNDrop.DropAreaBegin("C" + i); CustomGUIUtils.DrawBox(dragNDrop.ThisDropArea.Rect, XKCDColors.LightGreyBlue); GUI.Label(dragNDrop.ThisDropArea.Rect, dragNDrop.ThisDropArea.ToString()); dragNDrop.DropAreaEnd("C" + i); } dragNDrop.DropAreaBegin("D"); CustomGUIUtils.DrawBox(dragNDrop.ThisDropArea.Rect, XKCDColors.LightGreyBlue); GUI.Label(dragNDrop.ThisDropArea.Rect, dragNDrop.ThisDropArea.ToString()); dragNDrop.DropAreaEnd("D"); dragNDrop.DropAreaBegin("inner1"); CustomGUIUtils.DrawBox(dragNDrop.ThisDropArea.Rect, XKCDColors.LightRed); GUI.Label(dragNDrop.ThisDropArea.Rect, dragNDrop.ThisDropArea.ToString()); dragNDrop.DropAreaEnd("inner1"); dragNDrop.DropAreaBegin("inner2"); CustomGUIUtils.DrawBox(dragNDrop.ThisDropArea.Rect, XKCDColors.GreenApple); GUI.Label(dragNDrop.ThisDropArea.Rect, dragNDrop.ThisDropArea.ToString()); dragNDrop.DropAreaEnd("inner2"); foreach (String stri in strings) { dragNDrop.DragObjectBegin(stri); CustomGUIUtils.DrawBox(dragNDrop.CurrentDragObject.CurrentRect, myGrey); GUI.Label(dragNDrop.CurrentDragObject.CurrentRect, stri.ToString()); GUI.DrawTexture(dragNDrop.CurrentDragObject.CurrentRect, DefaultIconSet.Device); dragNDrop.DragObjectEnd(stri); } foreach (object obj in objects) { dragNDrop.DragObjectBegin(obj); if (dragNDrop.CurrentDragObject.IsDragging) { Rect drawRect = dragNDrop.CurrentDragObject.CurrentRect; drawRect.width = drawRect.height = 50; drawRect.x = InputHelpers.MouseOnGUI().x - drawRect.width / 2; drawRect.y = InputHelpers.MouseOnGUI().y - drawRect.height / 2; GUI.DrawTexture(drawRect, DefaultIconSet.Device); } else { CustomGUIUtils.DrawBox(dragNDrop.CurrentDragObject.CurrentRect, myGrey); GUI.Label(dragNDrop.CurrentDragObject.CurrentRect, obj.ToString()); GUI.DrawTexture(dragNDrop.CurrentDragObject.CurrentRect, DefaultIconSet.Device); } dragNDrop.DragObjectEnd(obj); } //foreach (DropArea dropArea in dragNDrop.dropAreas.Values) //{ // if (dropArea.Object != null) // { // if (dropArea.Object.GetType() == typeof(A)) // { // A readA = dropArea.GetObject<A>(); // Debug.Log("A gelesen: " + readA.ToString()); // } // } //} }
/// <summary> /// Checks if the mousposition on GUI is inside of one of the GUIAreas /// </summary> /// <returns></returns> public static bool MouseInsideGUIArea() { return(PointInsideGUIArea(InputHelpers.MouseOnGUI())); }