public static SelectionPopup ShowModal(Rect r) { if (totalSelection.Count == 0) { return(null); } SelectionPopup popup = CreateInstance <SelectionPopup>(); popup.ShowAsDropDown(new Rect(r.position, Vector2.zero), r.size); originalPosition = r.position; return(popup); }
static void OnSceneGUI(SceneView sceneView) { Event e = Event.current; if (e.type != EventType.Used && e.control && e.isMouse && e.button == 1) { switch (e.rawType) { case EventType.MouseDown: mouseRightIsDownWithoutDrag = true; break; case EventType.MouseDrag: mouseRightIsDownWithoutDrag = false; break; } //The actual CTRL+RIGHT-MOUSE functionality if (mouseRightIsDownWithoutDrag && e.rawType == EventType.MouseUp) { var allOverlapping = GetAllOverlapping(e.mousePosition); List <SelectionItem> totalSelection = SelectionPopup.totalSelection; totalSelection.Clear(); foreach (var overlapping in allOverlapping) { GameObject gO = overlapping; //Check whether the parents of a rect transform have a disabled canvas in them. if (gO.transform is RectTransform rectTransform) { var canvas = rectTransform.GetComponentInParent <Canvas>(); if (canvas != null) { if (!canvas.enabled) { continue; } bool canvasInParentsEnabled = true; while (canvas != null) { Transform parent = canvas.transform.parent; if (parent != null) { canvas = parent.GetComponentInParent <Canvas>(); if (canvas == null || canvas.enabled) { continue; } canvasInParentsEnabled = false; } break; } if (!canvasInParentsEnabled) { continue; } } } Component[] cS = gO.GetComponents <Component>(); GUIContent[] icons = new GUIContent[cS.Length - 1]; for (var i = 1; i < cS.Length; i++) { if (cS[i] == null) { icons[i - 1] = GUIContent.none; continue; } //Skip the Transform component because it's always the first object icons[i - 1] = new GUIContent(AssetPreview.GetMiniThumbnail(cS[i]), ObjectNames.NicifyVariableName(cS[i].GetType().Name)); } totalSelection.Add(new SelectionItem(gO, icons)); } Vector2 selectionPosition = e.mousePosition; float xOffset; //Screen-rect limits offset if (selectionPosition.x + width > sceneView.position.width) { xOffset = -width; } else { xOffset = 0; } int value = Mathf.CeilToInt(((selectionPosition.y + height * totalSelection.Count) - sceneView.position.height + 10) / height); SelectionPopup.scrollPosition = Mathf.Max(0, value); SelectionPopup popup = SelectionPopup.ShowModal( new Rect( sceneView.position.x + e.mousePosition.x + xOffset, sceneView.position.y + e.mousePosition.y + height * 1.5f, width, height * totalSelection.Count + 1 + 5 * 2 ) ); if (popup == null) { e.Use(); return; } e.alt = false; mouseRightIsDownWithoutDrag = false; SelectionPopup.RefreshSelection(); e.Use(); } } }
static void OnSceneGUI(SceneView sceneView) { Event e = Event.current; if (e.type != EventType.Used && e.control && e.isMouse && e.button == 1) { switch (e.rawType) { case EventType.MouseDown: mouseRightIsDownWithoutDrag = true; break; case EventType.MouseDrag: mouseRightIsDownWithoutDrag = false; break; } //The actual CTRL+RIGHT-MOUSE functionality if (mouseRightIsDownWithoutDrag && e.rawType == EventType.MouseUp) { SelectionPopup.isShiftSelection = e.shift; SelectionPopup.totalSelection = GetAllOverlapping(e.mousePosition).ToArray(); SelectionPopup.icons = new Texture2D[SelectionPopup.totalSelection.Length][]; SelectionPopup.iconsOffsets = new float[SelectionPopup.totalSelection.Length]; SelectionPopup.iconsOffsetTargets = new float[SelectionPopup.totalSelection.Length]; for (var t = 0; t < SelectionPopup.totalSelection.Length; t++) { GameObject gO = SelectionPopup.totalSelection[t]; Component[] cS = gO.GetComponents <Component>(); Texture2D[] icons = new Texture2D[cS.Length - 1]; for (var i = 1; i < cS.Length; i++) { //Skip the Transform component because it's always the first object icons[i - 1] = AssetPreview.GetMiniThumbnail(cS[i]); } SelectionPopup.icons[t] = icons; SelectionPopup.iconsOffsets[t] = 0; SelectionPopup.iconsOffsetTargets[t] = 0; } Vector2 selectionPosition = e.mousePosition; float xOffset; //Screen-rect limits offset if (selectionPosition.x + width > sceneView.position.width) { xOffset = -width; } else { xOffset = 0; } int value = Mathf.CeilToInt(((selectionPosition.y + height * SelectionPopup.totalSelection.Length) - sceneView.position.height + 10) / height); SelectionPopup.scrollPosition = Mathf.Max(0, value); SelectionPopup popup = SelectionPopup.ShowModal( new Rect( sceneView.position.x + e.mousePosition.x + xOffset, sceneView.position.y + e.mousePosition.y + height / 2f, width, height * SelectionPopup.totalSelection.Length + 1 ) ); if (popup == null) { e.Use(); return; } e.alt = false; mouseRightIsDownWithoutDrag = false; SelectionPopup.RefreshSelectionHash(); e.Use(); } } }