예제 #1
0
        public override ActionResult DoAction()
        {
            if (MeshSelection.selectedObjectCount < 2)
            {
                return(new ActionResult(ActionResult.Status.Canceled, "Must Select 2+ Objects"));
            }

            var selected = MeshSelection.top.ToArray();
            List <ProBuilderMesh> res = InternalMeshUtility.CombineObjects(MeshSelection.topInternal);

            if (res != null)
            {
                foreach (var mesh in res)
                {
                    mesh.Optimize();
                    mesh.gameObject.name = "pb-MergedObject" + mesh.id;
                    UndoUtility.RegisterCreatedObjectUndo(mesh.gameObject, "Merge Objects");
                    Selection.objects = res.Select(x => x.gameObject).ToArray();
                }

                // Delete donor objects
                for (int i = 0; i < selected.Length; i++)
                {
                    if (selected[i] != null)
                    {
                        UndoUtility.DestroyImmediate(selected[i].gameObject);
                    }
                }
            }

            ProBuilderEditor.Refresh();

            return(new ActionResult(ActionResult.Status.Success, "Merged Objects"));
        }
예제 #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"));
        }
예제 #3
0
        protected override ActionResult PerformActionImplementation()
        {
            GameObject go     = new GameObject();
            var        bezier = go.AddComponent <BezierShape>();

            go.GetComponent <MeshRenderer>().sharedMaterial = EditorMaterialUtility.GetUserMaterial();
            bezier.Init();
            bezier.Refresh();
            EditorUtility.InitObject(bezier.GetComponent <ProBuilderMesh>());
            MeshSelection.SetSelection(go);
            UndoUtility.RegisterCreatedObjectUndo(go, "Create Bezier Shape");
            bezier.isEditing = true;

            return(new ActionResult(ActionResult.Status.Success, "Create Bezier Shape"));
        }
        protected override ActionResult PerformActionImplementation()
        {
            if (!CanCreateNewPolyShape())
            {
                return(new ActionResult(ActionResult.Status.Canceled, "Canceled Create Poly Shape"));
            }

            GameObject go = new GameObject("PolyShape");

            UndoUtility.RegisterCreatedObjectUndo(go, "Create Poly Shape");
            PolyShape      poly = Undo.AddComponent <PolyShape>(go);
            ProBuilderMesh pb   = Undo.AddComponent <ProBuilderMesh>(go);

            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);
            poly.polyEditMode = PolyShape.PolyEditMode.Path;

            ProBuilderEditor.selectMode = SelectMode.Object;

            m_Tool = ScriptableObject.CreateInstance <PolyShapeTool>();
            ((PolyShapeTool)m_Tool).polygon = poly;
            ToolManager.SetActiveTool(m_Tool);

            Undo.RegisterCreatedObjectUndo(m_Tool, "Open PolyShape Tool");

            MenuAction.onPerformAction         += ActionPerformed;
            ToolManager.activeToolChanging     += LeaveTool;
            ProBuilderEditor.selectModeChanged += OnSelectModeChanged;

            MeshSelection.objectSelectionChanged += OnObjectSelectionChanged;

            return(new ActionResult(ActionResult.Status.Success, "Create Poly Shape"));
        }
        public override ActionResult DoAction()
        {
            if (MeshSelection.selectedObjectCount < 2)
            {
                return(new ActionResult(ActionResult.Status.Canceled, "Must Select 2+ Objects"));
            }

            var            selected    = MeshSelection.top.ToArray();
            ProBuilderMesh currentMesh = MeshSelection.activeMesh;

            UndoUtility.RecordObject(currentMesh, "Merge Objects");
            List <ProBuilderMesh> res = CombineMeshes.Combine(MeshSelection.topInternal, currentMesh);

            if (res != null)
            {
                foreach (var mesh in res)
                {
                    mesh.Optimize();
                    if (mesh != currentMesh)
                    {
                        mesh.gameObject.name = Selection.activeGameObject.name + "-Merged";
                        UndoUtility.RegisterCreatedObjectUndo(mesh.gameObject, "Merge Objects");
                        Selection.objects = res.Select(x => x.gameObject).ToArray();
                    }
                }

                // Delete donor objects if they are not part of the result
                for (int i = 0; i < selected.Length; i++)
                {
                    if (selected[i] != null && res.Contains(selected[i]) == false)
                    {
                        UndoUtility.DestroyImmediate(selected[i].gameObject);
                    }
                }
            }

            ProBuilderEditor.Refresh();

            return(new ActionResult(ActionResult.Status.Success, "Merged Objects"));
        }