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(); }
protected override void EndState() { tool.RebuildShape(); UndoUtility.RegisterCreatedObjectUndo(tool.currentShapeInOverlay.gameObject, "Draw Shape"); tool.m_LastShapeCreated = tool.m_ProBuilderShape; tool.m_ProBuilderShape = null; }
public static void MenuCreateCube() { ProBuilderMesh mesh = ShapeGenerator.GenerateCube(EditorUtility.newShapePivotLocation, Vector3.one); UndoUtility.RegisterCreatedObjectUndo(mesh.gameObject, "Create Shape"); EditorUtility.InitObject(mesh); }
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(); }