private HashSet <Renderer> FilterObjects(FilteringArgs filteringArgs, IEnumerable <Renderer> renderers) { HashSet <Renderer> selection = new HashSet <Renderer>(); foreach (Renderer rend in renderers) { if (!selection.Contains(rend)) { if (Filtering != null) { filteringArgs.Object = rend.gameObject; Filtering(this, filteringArgs); if (!filteringArgs.Cancel) { selection.Add(rend); } filteringArgs.Reset(); } else { selection.Add(rend); } } } return(selection); }
private void TrySelect(ref Bounds selectionBounds, HashSet <GameObject> selection, FilteringArgs args, ref Bounds bounds, GameObject go, Plane[] frustumPlanes) { bool select; if (Method == BoxSelectionMethod.LooseFitting) { select = LooseFitting(ref selectionBounds, ref bounds); } else if (Method == BoxSelectionMethod.BoundsCenter) { select = BoundsCenter(ref selectionBounds, ref bounds); } else { select = TransformCenter(ref selectionBounds, go.transform); } if (!GeometryUtility.TestPlanesAABB(frustumPlanes, bounds)) { select = false; } if (select) { if (!selection.Contains(go)) { if (Filtering != null) { args.Object = go; Filtering(this, args); if (!args.Cancel) { selection.Add(go); } args.Reset(); } else { selection.Add(go); } } } }
private void Filter(HashSet <GameObject> selection, FilteringArgs args, GameObject go) { if (!selection.Contains(go)) { if (Filtering != null) { args.Object = go; Filtering(this, args); if (!args.Cancel) { selection.Add(go); } args.Reset(); } else { selection.Add(go); } } }
private void HitTest() { if (m_rectTransform.sizeDelta.magnitude < 25f) { return; } Vector3 center = (m_startMousePosition + (Vector3)Window.Pointer.ScreenPoint) / 2; center.z = 0.0f; Bounds selectionBounds = new Bounds(center, m_rectTransform.sizeDelta); SelectionBounds = selectionBounds; FilteringArgs filteringArgs = new FilteringArgs(); HashSet <GameObject> selection; Renderer[] renderers = FindObjectsOfType <Renderer>(); if (MethodOverride == BoxSelectionMethod.PixelPerfectDepthTest) { Vector2 min = SelectionBounds.min; Vector2 max = SelectionBounds.max; Canvas canvas = Window.GetComponentInParent <Canvas>(); RectTransform sceneOutput = (RectTransform)Window.GetComponent <RectTransform>().GetChild(0); RectTransformUtility.ScreenPointToLocalPointInRectangle(sceneOutput, min, canvas.worldCamera, out min); min.y = sceneOutput.rect.height - min.y; RectTransformUtility.ScreenPointToLocalPointInRectangle(sceneOutput, max, canvas.worldCamera, out max); max.y = sceneOutput.rect.height - max.y; Rect rect = new Rect(new Vector2(Mathf.Min(min.x, max.x), Mathf.Min(min.y, max.y)), new Vector2(Mathf.Abs(max.x - min.x), Mathf.Abs(max.y - min.y))); rect.x += Window.Camera.pixelRect.x; rect.y += canvas.pixelRect.height - (Window.Camera.pixelRect.y + Window.Camera.pixelRect.height); IEnumerable <GameObject> gameObjects = BoxSelectionRenderer.PickObjectsInRect(Window.Camera, rect, renderers, Mathf.RoundToInt(canvas.pixelRect.width), Mathf.RoundToInt(canvas.pixelRect.height)).Select(r => r.gameObject); selection = new HashSet <GameObject>(); foreach (GameObject go in gameObjects) { if (!selection.Contains(go)) { if (Filtering != null) { filteringArgs.Object = go; Filtering(this, filteringArgs); if (!filteringArgs.Cancel) { selection.Add(go); } filteringArgs.Reset(); } else { selection.Add(go); } } } } else { selection = new HashSet <GameObject>(); Plane[] frustumPlanes = GeometryUtility.CalculateFrustumPlanes(Window.Camera); for (int i = 0; i < renderers.Length; ++i) { Renderer r = renderers[i]; Bounds bounds = r.bounds; GameObject go = r.gameObject; TrySelect(ref selectionBounds, selection, filteringArgs, ref bounds, go, frustumPlanes); } } SpriteGizmo[] spriteGizmos = FindObjectsOfType <SpriteGizmo>(); for (int i = 0; i < spriteGizmos.Length; ++i) { SpriteGizmo spriteGizmo = spriteGizmos[i]; bool select = TransformCenter(ref selectionBounds, spriteGizmo.transform); if (select) { Filter(selection, filteringArgs, spriteGizmo.gameObject); } } if (Selection != null) { Selection(this, new BoxSelectionArgs { GameObjects = selection.ToArray() }); } else { Editor.Selection.objects = selection.ToArray(); } }