コード例 #1
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"));
        }
コード例 #2
0
        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"));
        }