예제 #1
0
        private void OnBoxSelection(object sender, BoxSelectionArgs e)
        {
            Bounds  selectionBounds = m_selectionComponent.BoxSelection.SelectionBounds;
            Vector2 min             = ManualUVRenderer.WorldToUV(Window.Camera.ScreenToWorldPoint(selectionBounds.min));
            Vector2 max             = ManualUVRenderer.WorldToUV(Window.Camera.ScreenToWorldPoint(selectionBounds.max));

            switch (m_tool.Mode)
            {
            case ProBuilderToolMode.Vertex:
                m_uvEditor.SelectVertices(uv => (min.x <= uv.x && min.y <= uv.y && uv.x <= max.x && uv.y <= max.y) ? 0 : 1, false, !SelectMultipleAction());
                break;

            case ProBuilderToolMode.Face:
                m_uvEditor.SelectFaces(uv => (min.x <= uv.x && min.y <= uv.y && uv.x <= max.x && uv.y <= max.y) ? 0 : 1, false, !SelectMultipleAction());
                break;

            default:
                m_uvEditor.SelectEdges((uv0, uv1) => PBMath.Intersects(min, max, uv0, uv1) ? 0 : 1, false, !SelectMultipleAction());
                break;
            }

            m_uvEditor.RefreshPivotPoint();
        }
예제 #2
0
        private void Update()
        {
            if (!IsWindowActive)
            {
                return;
            }

            RuntimeTools tools = Editor.Tools;

            if (tools.ActiveTool != null && tools.ActiveTool != m_selectionComponent.BoxSelection)
            {
                return;
            }

            if (tools.IsViewing)
            {
                return;
            }

            if (!m_selectionComponent.Selection.Enabled)
            {
                return;
            }

            Vector3 v1       = Window.Camera.ScreenToWorldPoint(Window.Pointer.ScreenPoint);
            Vector3 v2       = Window.Camera.ScreenToWorldPoint(Window.Pointer.ScreenPoint + Vector2.up * 20);
            float   uvMargin = (v1 - v2).sqrMagnitude / (ManualUVRenderer.Scale * ManualUVRenderer.Scale);

            if (SelectAction())
            {
                Vector2 hitPoint;
                if (Raycast(out hitPoint))
                {
                    switch (m_tool.Mode)
                    {
                    case ProBuilderToolMode.Vertex:
                        m_uvEditor.SelectVertices(uv =>
                        {
                            float sqDistance = (uv - hitPoint).sqrMagnitude;
                            if (sqDistance > uvMargin)
                            {
                                return(float.PositiveInfinity);
                            }
                            return(sqDistance);
                        }, true, !SelectMultipleAction());
                        break;

                    case ProBuilderToolMode.Face:
                        m_uvEditor.SelectFaces(uv =>
                        {
                            float sqDistance = (uv - hitPoint).sqrMagnitude;
                            if (sqDistance > uvMargin)
                            {
                                return(float.PositiveInfinity);
                            }
                            return(sqDistance);
                        }, true, !SelectMultipleAction());
                        break;

                    default:
                        m_uvEditor.SelectEdges((uv0, uv1) =>
                        {
                            float sqDistance = PBMath.SqDistanceTo(uv0, uv1, hitPoint);
                            if (sqDistance > uvMargin)
                            {
                                return(float.PositiveInfinity);
                            }
                            return(sqDistance);
                        }, true, !SelectMultipleAction());
                        break;
                    }
                }

                m_uvEditor.RefreshPivotPoint();
            }
        }