예제 #1
0
        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);
        }
예제 #2
0
        private void HitTest()
        {
            if (m_rectTransform.sizeDelta.magnitude < 5f)
            {
                return;
            }

            Vector3 center = (m_startMousePosition + Input.mousePosition) / 2;

            center.z = 0.0f;
            Bounds selectionBounds = new Bounds(center, m_rectTransform.sizeDelta);

            HashSet <GameObject> selection = new HashSet <GameObject>();

            Renderer[]    renderers = FindObjectsOfType <Renderer>();
            Collider[]    colliders = FindObjectsOfType <Collider>();
            FilteringArgs args      = new FilteringArgs();

            for (int i = 0; i < renderers.Length; ++i)
            {
                Renderer   r      = renderers[i];
                Bounds     bounds = r.bounds;
                GameObject go     = r.gameObject;
                TrySelect(ref selectionBounds, selection, args, ref bounds, go);
            }
            for (int i = 0; i < colliders.Length; ++i)
            {
                Collider   c      = colliders[i];
                Bounds     bounds = c.bounds;
                GameObject go     = c.gameObject;
                TrySelect(ref selectionBounds, selection, args, ref bounds, go);
            }

            RuntimeSelection.objects = selection.ToArray();
        }
예제 #3
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)
            {
                selection = new HashSet <GameObject>(FilterObjects(filteringArgs, PixelPerfectDepthTest(renderers, SelectionBounds)).Select(rend => rend.gameObject));
            }
            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();
            }
        }
        private void OnBoxSelectionFiltering(object sender, FilteringArgs e)
        {
            if (e.Object == null || !CanSelect)
            {
                e.Cancel = true;
            }

            ExposeToEditor exposeToEditor = e.Object.GetComponent <ExposeToEditor>();

            if (!exposeToEditor || !exposeToEditor.CanEdit)
            {
                e.Cancel = true;
            }
        }
예제 #5
0
파일: BoxSelection.cs 프로젝트: lbm7926/Imp
        private void HitTest()
        {
            if (m_rectTransform.sizeDelta.magnitude < 5f)
            {
                return;
            }

            Vector3 center = (m_startMousePosition + (Vector3)Window.Pointer.ScreenPoint) / 2;

            center.z = 0.0f;
            Bounds selectionBounds = new Bounds(center, m_rectTransform.sizeDelta);

            SelectionBounds = selectionBounds;

            Plane[] frustumPlanes = GeometryUtility.CalculateFrustumPlanes(Window.Camera);

            HashSet <GameObject> selection = new HashSet <GameObject>();

            Renderer[]    renderers = FindObjectsOfType <Renderer>();
            Collider[]    colliders = FindObjectsOfType <Collider>();
            FilteringArgs args      = new FilteringArgs();

            for (int i = 0; i < renderers.Length; ++i)
            {
                Renderer   r      = renderers[i];
                Bounds     bounds = r.bounds;
                GameObject go     = r.gameObject;
                TrySelect(ref selectionBounds, selection, args, ref bounds, go, frustumPlanes);
            }
            for (int i = 0; i < colliders.Length; ++i)
            {
                Collider   c      = colliders[i];
                Bounds     bounds = c.bounds;
                GameObject go     = c.gameObject;
                TrySelect(ref selectionBounds, selection, args, ref bounds, go, frustumPlanes);
            }

            if (Selection != null)
            {
                Selection(this, new BoxSelectionArgs {
                    GameObjects = selection.ToArray()
                });
            }
            else
            {
                Editor.Selection.objects = selection.ToArray();
            }
        }
예제 #6
0
        private Renderer[] Pick(Renderer[] renderers, Bounds bounds, bool filterObjects = true)
        {
            if (renderers == null)
            {
                renderers = FindObjectsOfType <Renderer>();
            }

            IEnumerable <Renderer> selection = PixelPerfectDepthTest(renderers, bounds);

            m_rectTransform.sizeDelta = new Vector2(0, 0);

            if (filterObjects)
            {
                FilteringArgs filteringArgs = new FilteringArgs();
                return(FilterObjects(filteringArgs, selection).ToArray());
            }

            return(selection.ToArray());
        }
 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 TrySelect(ref Bounds selectionBounds, HashSet <GameObject> selection, FilteringArgs args, ref Bounds bounds, GameObject go, Plane[] frustumPlanes)
        {
            if (!GeometryUtility.TestPlanesAABB(frustumPlanes, bounds))
            {
                return;
            }
            bool select;

            if (MethodOverride == BoxSelectionMethod.LooseFitting)
            {
                select = LooseFitting(ref selectionBounds, ref bounds);
            }
            else if (MethodOverride == BoxSelectionMethod.Vertex)
            {
                select = LooseFitting(ref selectionBounds, ref bounds);
                if (select && !selection.Contains(go))
                {
                    select = false;
                    MeshFilter meshFilter = go.GetComponent <MeshFilter>();
                    if (meshFilter != null && meshFilter.sharedMesh != null)
                    {
                        Vector3[] vertices = meshFilter.sharedMesh.vertices;

                        for (int i = 0; i < vertices.Length; ++i)
                        {
                            Vector3 vertex = go.transform.TransformPoint(vertices[i]);
                            vertex   = Window.Camera.WorldToScreenPoint(vertex);
                            vertex.z = 0;
                            if (selectionBounds.Contains(vertex))
                            {
                                select = true;
                                break;
                            }
                        }
                    }
                    else
                    {
                        SkinnedMeshRenderer smr = go.GetComponent <SkinnedMeshRenderer>();

                        if (smr != null && smr.sharedMesh != null)
                        {
                            Mesh bakedMesh = new Mesh();
                            smr.BakeMesh(bakedMesh);

                            Matrix4x4 m = Matrix4x4.TRS(go.transform.localPosition, go.transform.localRotation, Vector3.one);
                            if (smr.transform.parent != null)
                            {
                                m = m * smr.transform.parent.localToWorldMatrix;
                            }

                            Vector3[] vertices = bakedMesh.vertices;

                            for (int i = 0; i < vertices.Length; ++i)
                            {
                                Vector3 vertex = m.MultiplyPoint(vertices[i]);
                                vertex   = Window.Camera.WorldToScreenPoint(vertex);
                                vertex.z = 0;
                                if (selectionBounds.Contains(vertex))
                                {
                                    select = true;
                                    break;
                                }
                            }

                            Destroy(bakedMesh);
                        }
                    }
                }
            }
            else if (MethodOverride == BoxSelectionMethod.BoundsCenter)
            {
                select = BoundsCenter(ref selectionBounds, ref bounds);
            }
            else
            {
                select = TransformCenter(ref selectionBounds, go.transform);
            }

            if (select)
            {
                Filter(selection, args, 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();
            }
        }
예제 #10
0
        private void TrySelect(ref Bounds selectionBounds, HashSet <GameObject> selection, FilteringArgs args, ref Bounds bounds, GameObject go)
        {
            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 (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);
                    }
                }
            }
        }
예제 #11
0
        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);
                    }
                }
            }
        }