コード例 #1
0
        public Color32[] BeginPick(out Vector2Int texSize, Renderer[] renderers = null)
        {
            if (renderers == null)
            {
                renderers = FindObjectsOfType <Renderer>();
            }

            Canvas canvas = Window.GetComponentInParent <Canvas>();

            return(BoxSelectionRenderer.Render(Window.Camera, renderers, new Vector2Int(Mathf.RoundToInt(canvas.pixelRect.width), Mathf.RoundToInt(canvas.pixelRect.height)), out texSize));
        }
コード例 #2
0
        private Renderer[] EndPick(Color32[] texPixels, Vector2Int texSize, Renderer[] renderers, Bounds bounds)
        {
            Canvas        canvas      = Window.GetComponentInParent <Canvas>();
            RectTransform sceneOutput = Window.GetComponent <RectTransform>();

            if (sceneOutput.childCount > 0)
            {
                sceneOutput = (RectTransform)Window.GetComponent <RectTransform>().GetChild(0);
            }

            Rect selectionRect = SelectionBoundsToSelectionRect(bounds, canvas, sceneOutput);

            return(BoxSelectionRenderer.PickRenderersInRect(Window.Camera, selectionRect, renderers, texPixels, texSize));
        }
コード例 #3
0
        private IEnumerable <Renderer> PixelPerfectDepthTest(Renderer[] renderers, Bounds bounds)
        {
            Canvas canvas = Window.GetComponentInParent <Canvas>();

            RectTransform sceneOutput = Window.GetComponent <RectTransform>();

            if (sceneOutput.childCount > 0)
            {
                sceneOutput = (RectTransform)Window.GetComponent <RectTransform>().GetChild(0);
            }

            Rect rect = SelectionBoundsToSelectionRect(bounds, canvas, sceneOutput);

            return(BoxSelectionRenderer.PickRenderersInRect(Window.Camera, rect, renderers, Mathf.RoundToInt(canvas.pixelRect.width), Mathf.RoundToInt(canvas.pixelRect.height)));
        }
コード例 #4
0
        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();
            }
        }