Пример #1
0
        public override ActionResult DoAction()
        {
            if (MeshSelection.selectedObjectCount < 1)
            {
                return(ActionResult.NoSelection);
            }

            Object[] objects = new Object[MeshSelection.selectedObjectCount * 2];

            for (int i = 0, c = MeshSelection.selectedObjectCount; i < c; i++)
            {
                objects[i]     = MeshSelection.topInternal[i];
                objects[i + c] = MeshSelection.topInternal[i].transform;
            }

            UndoUtility.RegisterCompleteObjectUndo(objects, "Set Pivot");

            foreach (var mesh in MeshSelection.topInternal)
            {
                TransformUtility.UnparentChildren(mesh.transform);
                mesh.CenterPivot(mesh.selectedIndexesInternal);
                mesh.Optimize();
                TransformUtility.ReparentChildren(mesh.transform);
            }

            ProBuilderEditor.Refresh();

            return(new ActionResult(ActionResult.Status.Success, "Set Pivot"));
        }
Пример #2
0
        public override ActionResult DoAction()
        {
            foreach (ProBuilderMesh pb in MeshSelection.topInternal)
            {
                var existing = pb.GetComponents <EntityBehaviour>();

                // For now just nuke any existing entity types (since there are only two). In the future we should be
                // smarter about conflicting entity types.
                for (int i = 0, c = existing.Length; i < c; i++)
                {
                    Undo.DestroyObjectImmediate(existing[i]);
                }

                var entity = pb.GetComponent <Entity>();

                if (entity != null)
                {
                    Undo.DestroyObjectImmediate(entity);
                }

                if (!pb.GetComponent <Collider>())
                {
                    Undo.AddComponent <MeshCollider>(pb.gameObject);
                }

                if (!pb.GetComponent <Renderer>())
                {
                    Undo.AddComponent <MeshRenderer>(pb.gameObject);
                }

                UndoUtility.RegisterCompleteObjectUndo(pb, "Set Collider");

                Undo.AddComponent <ColliderBehaviour>(pb.gameObject).Initialize();
            }

            int selectionCount = MeshSelection.selectedObjectCount;

            if (selectionCount < 1)
            {
                return(new ActionResult(ActionResult.Status.NoChange, "Set Collider\nNo objects selected"));
            }

            return(new ActionResult(ActionResult.Status.Success, "Set Collider\nSet " + selectionCount + " Objects"));
        }