示例#1
0
        internal void RebuildShape()
        {
            RecalculateBounds();

            if (m_Bounds.size.sqrMagnitude < .01f ||
                Mathf.Abs(m_Bounds.extents.x) < 0.001f ||
                Mathf.Abs(m_Bounds.extents.z) < 0.001f)
            {
                if (m_ProBuilderShape != null &&
                    m_ProBuilderShape.mesh.vertexCount > 0)
                {
                    m_ProBuilderShape.mesh.Clear();
                    m_ProBuilderShape.mesh.Rebuild();
                    ProBuilderEditor.Refresh(true);
                }
                return;
            }

            if (!m_IsShapeInit)
            {
                var shapeComponent = currentShapeInOverlay;
                EditorShapeUtility.CopyLastParams(shapeComponent.shape, shapeComponent.shape.GetType());
                shapeComponent.gameObject.hideFlags         = HideFlags.HideInHierarchy;
                shapeComponent.mesh.renderer.sharedMaterial = EditorMaterialUtility.GetUserMaterial();
                UndoUtility.RegisterCreatedObjectUndo(shapeComponent.gameObject, "Draw Shape");
                m_IsShapeInit = true;
            }

            m_ProBuilderShape.Rebuild(m_Bounds, m_PlaneRotation);
            ProBuilderEditor.Refresh(false);

            SceneView.RepaintAll();
        }
示例#2
0
        public void CreateLastShape()
        {
            var shape = ShapeFactory.Instantiate(DrawShapeTool.activeShapeType, (PivotLocation)DrawShapeTool.s_LastPivotLocation.value).GetComponent <ProBuilderShape>();

            shape.gameObject.name = shape.gameObject.name + "-Copy";
            EditorUtility.InitObject(shape.mesh);
            DrawShapeTool.ApplyPrefsSettings(shape);

            UndoUtility.RegisterCreatedObjectUndo(shape.gameObject, "Create Shape Copy");

            EditorShapeUtility.CopyLastParams(shape.shape, shape.shape.GetType());
            shape.Rebuild(tool.m_Bounds, tool.m_PlaneRotation);

            //Finish initializing object and collider once it's completed
            ProBuilderEditor.Refresh(false);

            tool.m_ProBuilderShape  = null;
            tool.m_LastShapeCreated = shape;

            if (tool.m_DuplicateGO != null)
            {
                GameObject.DestroyImmediate(tool.m_DuplicateGO);
            }

            MeshSelection.SetSelection(shape.gameObject);
        }
        internal void RebuildShape()
        {
            RecalculateBounds();

            if (m_Bounds.size.sqrMagnitude < .01f ||
                Mathf.Abs(m_Bounds.extents.x) < 0.001f ||
                Mathf.Abs(m_Bounds.extents.z) < 0.001f)
            {
                if (m_ShapeComponent.mesh.vertexCount > 0)
                {
                    m_ShapeComponent.mesh.Clear();
                    m_ShapeComponent.mesh.Rebuild();
                    ProBuilderEditor.Refresh(true);
                }
                return;
            }

            if (!m_IsShapeInit)
            {
                EditorShapeUtility.CopyLastParams(m_ShapeComponent.shape, m_ShapeComponent.shape.GetType());
                m_ShapeComponent.gameObject.hideFlags = HideFlags.None;
                UndoUtility.RegisterCreatedObjectUndo(m_ShapeComponent.gameObject, "Draw Shape");
            }

            m_ShapeComponent.Rebuild(m_Bounds, m_PlaneRotation);
            ProBuilderEditor.Refresh(false);

            if (!m_IsShapeInit)
            {
                EditorUtility.InitObject(m_ShapeComponent.mesh);
                m_IsShapeInit = true;
            }

            SceneView.RepaintAll();
        }
示例#4
0
        internal void DuplicatePreview(Vector3 position)
        {
            if (position.Equals(Vector3.positiveInfinity) || !Event.current.isMouse)
            {
                return;
            }

            var pivotLocation = (PivotLocation)s_LastPivotLocation.value;
            var size          = currentShapeInOverlay.size;

            m_Bounds.size = size;

            Vector3 cornerPosition;

            switch (pivotLocation)
            {
            case PivotLocation.FirstCorner:
                cornerPosition  = GetPoint(position);
                m_PlaneRotation = Quaternion.LookRotation(m_PlaneForward, m_Plane.normal);
                m_Bounds.center = cornerPosition + m_PlaneRotation * size / 2f;

                m_BB_Origin         = cornerPosition;
                m_BB_HeightCorner   = m_Bounds.center + m_PlaneRotation * (size / 2f);
                m_BB_OppositeCorner = m_BB_HeightCorner - m_PlaneRotation * new Vector3(0, size.y, 0);
                break;

            case PivotLocation.Center:
            default:
                position         = GetPoint(position);
                cornerPosition   = position - size / 2f;
                cornerPosition.y = position.y;
                m_Bounds.center  = cornerPosition + new Vector3(size.x / 2f, 0, size.z / 2f) + (size.y / 2f) * m_Plane.normal;
                m_PlaneRotation  = Quaternion.LookRotation(m_PlaneForward, m_Plane.normal);

                m_BB_Origin         = m_Bounds.center - m_PlaneRotation * (size / 2f);
                m_BB_HeightCorner   = m_Bounds.center + m_PlaneRotation * (size / 2f);
                m_BB_OppositeCorner = m_BB_HeightCorner - m_PlaneRotation * new Vector3(0, size.y, 0);
                break;
            }

            ProBuilderShape proBuilderShape;

            if (m_DuplicateGO == null)
            {
                var instantiated = ShapeFactory.Instantiate(activeShapeType, ((PivotLocation)s_LastPivotLocation.value));
                proBuilderShape         = instantiated.GetComponent <ProBuilderShape>();
                m_DuplicateGO           = proBuilderShape.gameObject;
                m_DuplicateGO.hideFlags = HideFlags.DontSave | HideFlags.HideInHierarchy;
                ApplyPrefsSettings(proBuilderShape);
                proBuilderShape.GetComponent <MeshRenderer>().sharedMaterial = m_ShapePreviewMaterial;
            }
            else
            {
                proBuilderShape = m_DuplicateGO.GetComponent <ProBuilderShape>();
            }

            EditorShapeUtility.CopyLastParams(proBuilderShape.shape, proBuilderShape.shape.GetType());
            proBuilderShape.Rebuild(m_Bounds, m_PlaneRotation);
            ProBuilderEditor.Refresh(false);
        }
示例#5
0
        internal void DoDuplicateShapePreviewHandle(Vector3 position)
        {
            var evt = Event.current;

            if (evt.type != EventType.Repaint)
            {
                return;
            }

            bool previewShortcutActive = evt.shift && !(evt.control || evt.command);

            if (HandleUtility.nearestControl != m_ControlID || !previewShortcutActive)
            {
                DestroyImmediate(m_DuplicateGO);
                return;
            }

            var pivotLocation = (PivotLocation)s_LastPivotLocation.value;
            var size          = currentShapeInOverlay.size;

            m_Bounds.size = size;
            Vector3 cornerPosition;

            switch (pivotLocation)
            {
            case PivotLocation.FirstCorner:
                cornerPosition  = GetPoint(position);
                m_PlaneRotation = Quaternion.LookRotation(m_PlaneForward, m_Plane.normal);
                m_Bounds.center = cornerPosition + m_PlaneRotation * size / 2f;

                m_BB_Origin         = cornerPosition;
                m_BB_HeightCorner   = m_Bounds.center + m_PlaneRotation * (size / 2f);
                m_BB_OppositeCorner = m_BB_HeightCorner - m_PlaneRotation * new Vector3(0, size.y, 0);
                break;

            case PivotLocation.Center:
            default:
                position         = GetPoint(position);
                cornerPosition   = position - size / 2f;
                cornerPosition.y = position.y;
                m_Bounds.center  = cornerPosition + new Vector3(size.x / 2f, 0, size.z / 2f) + (size.y / 2f) * m_Plane.normal;
                m_PlaneRotation  = Quaternion.LookRotation(m_PlaneForward, m_Plane.normal);

                m_BB_Origin         = m_Bounds.center - m_PlaneRotation * (size / 2f);
                m_BB_HeightCorner   = m_Bounds.center + m_PlaneRotation * (size / 2f);
                m_BB_OppositeCorner = m_BB_HeightCorner - m_PlaneRotation * new Vector3(0, size.y, 0);
                break;
            }

            if (m_DuplicateGO == null)
            {
                var instantiated = ShapeFactory.Instantiate(activeShapeType, ((PivotLocation)s_LastPivotLocation.value));
                var shape        = instantiated.GetComponent <ProBuilderShape>();
                m_DuplicateGO           = shape.gameObject;
                m_DuplicateGO.hideFlags = HideFlags.DontSave | HideFlags.HideInHierarchy;
                ApplyPrefsSettings(shape);
                shape.GetComponent <MeshRenderer>().sharedMaterial = m_ShapePreviewMaterial;

                EditorShapeUtility.CopyLastParams(shape.shape, shape.shape.GetType());
                shape.Rebuild(m_Bounds, m_PlaneRotation, m_BB_Origin);
                ProBuilderEditor.Refresh(false);
            }

            var pivot = GetPoint(position);

            if (pivotLocation == PivotLocation.Center)
            {
                pivot += m_Plane.normal * size.y * .5f;
            }

            m_DuplicateGO.transform.position = pivot;
            m_DuplicateGO.transform.rotation = Quaternion.LookRotation(m_PlaneForward, m_Plane.normal);

            DrawBoundingBox(false);
        }