Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public override ActionResult DoAction()
        {
            GameObject     go   = new GameObject();
            PolyShape      poly = go.AddComponent <PolyShape>();
            ProBuilderMesh pb   = poly.gameObject.AddComponent <ProBuilderMesh>();

            pb.CreateShapeFromPolygon(poly.m_Points, poly.extrude, poly.flipNormals);
            EditorUtility.InitObject(pb);

            // Special case - we don't want to reset the grid pivot because we rely on it to set the active plane for
            // interaction, regardless of whether snapping is enabled or not.
            if (ProGridsInterface.SnapEnabled() || ProGridsInterface.GridVisible())
            {
                Vector3 pivot;
                if (ProGridsInterface.GetPivot(out pivot))
                {
                    go.transform.position = pivot;
                }
            }
            MeshSelection.SetSelection(go);
            UndoUtility.RegisterCreatedObjectUndo(go, "Create Poly Shape");
            poly.polyEditMode = PolyShape.PolyEditMode.Path;


            return(new ActionResult(ActionResult.Status.Success, "Create Poly Shape"));
        }
Exemplo n.º 3
0
        public static void MenuCreateCube()
        {
            ProBuilderMesh mesh = ShapeGenerator.GenerateCube(EditorUtility.newShapePivotLocation, Vector3.one);

            UndoUtility.RegisterCreatedObjectUndo(mesh.gameObject, "Create Shape");
            EditorUtility.InitObject(mesh);
        }
        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();
        }
Exemplo n.º 5
0
        static void CreateShape(ShapeType shape)
        {
            var res = ShapeGenerator.CreateShape(shape, EditorUtility.newShapePivotLocation);

            Undo.RegisterCreatedObjectUndo(res.gameObject, $"Create {shape}");
            EditorUtility.InitObject(res);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Create a shape with the last set <see cref="ShapeEditor"/> parameters.
        /// </summary>
        /// <returns>A reference to the <see cref="ProBuilderMesh"/> of the newly created GameObject.</returns>
        public static ProBuilderMesh CreateActiveShape()
        {
            var res = s_ShapeBuilders[PMath.Clamp(s_CurrentIndex, 0, s_ShapeBuilders.Length - 1)].Build();

            Undo.RegisterCreatedObjectUndo(res.gameObject, "Create Shape");
            EditorUtility.InitObject(res);
            return(res);
        }
Exemplo n.º 7
0
        void CreateSelectedShape(bool forceCloseWindow = false)
        {
            var res = m_ShapeBuilders[s_CurrentIndex].Build();

            EditorUtility.InitObject(res);
            ApplyPreviewTransform(res);
            DestroyPreviewObject();

            if (forceCloseWindow || s_CloseWindowAfterCreateShape)
            {
                Close();
            }
        }
        void CreateSelectedShape(bool forceCloseWindow = false)
        {
            var res = s_ShapeBuilders[s_CurrentIndex].Build();

            Undo.RegisterCreatedObjectUndo(res.gameObject, "Create Shape");
            EditorUtility.InitObject(res);
            ApplyPreviewTransform(res);
            DestroyPreviewObject(true);

            if (forceCloseWindow || s_CloseWindowAfterCreateShape)
            {
                Close();
            }
        }
        ShapeState ValidateShape()
        {
            tool.RebuildShape();
            tool.m_ProBuilderShape.pivotGlobalPosition  = tool.m_BB_Origin;
            tool.m_ProBuilderShape.gameObject.hideFlags = HideFlags.None;

            //Finish initializing object and collider once it's completed
            EditorUtility.InitObject(tool.m_ProBuilderShape.mesh);

            DrawShapeTool.s_ActiveShapeIndex.value = Array.IndexOf(EditorShapeUtility.availableShapeTypes, tool.m_ProBuilderShape.shape.GetType());

            DrawShapeTool.SaveShapeParams(tool.m_ProBuilderShape);

            return(NextState());
        }
        ShapeState ValidateShape()
        {
            tool.handleSelectionChange = false;

            tool.RebuildShape();
            tool.m_ProBuilderShape.pivotGlobalPosition  = tool.m_BB_Origin;
            tool.m_ProBuilderShape.gameObject.hideFlags = HideFlags.None;

            EditorUtility.InitObject(tool.m_ProBuilderShape.mesh);

            DrawShapeTool.s_ActiveShapeIndex.value = Array.IndexOf(EditorShapeUtility.availableShapeTypes, tool.m_ProBuilderShape.shape.GetType());
            DrawShapeTool.SaveShapeParams(tool.m_ProBuilderShape);

            // make sure that the whole shape creation process is a single undo group
            var group = Undo.GetCurrentGroup() - 1;

            Selection.activeObject = tool.m_ProBuilderShape.gameObject;
            Undo.CollapseUndoOperations(group);

            return(NextState());
        }
Exemplo n.º 11
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();
                shapeComponent.rotation        = Quaternion.identity;
                shapeComponent.gameObject.name = EditorShapeUtility.GetName(shapeComponent.shape);
                UndoUtility.RegisterCreatedObjectUndo(shapeComponent.gameObject, "Draw Shape");
                EditorUtility.InitObject(shapeComponent.mesh);
                m_IsShapeInit = true;
            }

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

            SceneView.RepaintAll();
        }