Beispiel #1
0
        void bake(MB3_MeshBakerCommon mom)
        {
            bool createdDummyTextureBakeResults = false;

            try{
                if (mom.textureBakeResults == null)
                {
                    if (_OkToCreateDummyTextureBakeResult(mom))
                    {
                        createdDummyTextureBakeResults = true;
                        MB2_TextureBakeResults tbr = (MB2_TextureBakeResults)ScriptableObject.CreateInstance(typeof(MB2_TextureBakeResults));
                        List <GameObject>      gos = mom.GetObjectsToCombine();
                        Material[]             ms  = MB_Utility.GetGOMaterials(gos[0]);
                        tbr.resultMaterial    = ms[0];
                        tbr.fixOutOfBoundsUVs = false;

                        tbr.materials       = ms;
                        tbr.resultMaterials = new MB_MultiMaterial[ms.Length];
                        if (ms.Length > 1)
                        {
                            tbr.prefabUVRects = new Rect[ms.Length];
                            for (int i = 0; i < ms.Length; i++)
                            {
                                tbr.prefabUVRects[i]   = new Rect(0f, 0f, 1f, 1f);
                                tbr.resultMaterials[i] = new MB_MultiMaterial();
                                List <Material> sourceMats = new List <Material>();
                                sourceMats.Add(ms[i]);
                                tbr.resultMaterials[i].sourceMaterials  = sourceMats;
                                tbr.resultMaterials[i].combinedMaterial = ms[i];
                            }
                            tbr.doMultiMaterial = true;
                        }
                        else
                        {
                            tbr.doMultiMaterial = false;
                            tbr.prefabUVRects   = new Rect[] { new Rect(0f, 0f, 1f, 1f) };
                        }
                        mom.textureBakeResults         = tbr;
                        createdDummyTextureBakeResults = true;
                    }
                }
                if (mom.meshCombiner.outputOption == MB2_OutputOptions.bakeIntoSceneObject)
                {
                    MB3_MeshBakerEditorFunctions.BakeIntoCombined(mom);
                }
                else if (mom.meshCombiner.outputOption == MB2_OutputOptions.bakeIntoPrefab)
                {
                    MB3_MeshBakerEditorFunctions.BakeIntoCombined(mom);
                }
                else
                {
                    if (mom is MB3_MeshBaker)
                    {
                        if (MB3_MeshCombiner.EVAL_VERSION)
                        {
                            Debug.LogError("Bake Meshes In Place is disabled in the evaluation version.");
                        }
                        else
                        {
                            if (!MB3_MeshBakerRoot.DoCombinedValidate(mom, MB_ObjsToCombineTypes.prefabOnly, new MB3_EditorMethods()))
                            {
                                return;
                            }

                            List <GameObject> objsToMesh = mom.GetObjectsToCombine();
                            //objsToMesh = mom.GetComponent<MB3_TextureBaker>().GetObjectsToCombine();
                            MB3_BakeInPlace.BakeMeshesInPlace((MB3_MeshCombinerSingle)((MB3_MeshBaker)mom).meshCombiner, objsToMesh, mom.bakeAssetsInPlaceFolderPath, updateProgressBar);
                        }
                    }
                    else
                    {
                        Debug.LogError("Multi-mesh Baker components cannot be used for Bake In Place. Use an ordinary Mesh Baker object instead.");
                    }
                }
                if (mom.clearBuffersAfterBake)
                {
                    mom.meshCombiner.ClearBuffers();
                }
            } catch (Exception e) {
                Debug.LogError(e);
            } finally {
                if (createdDummyTextureBakeResults)
                {
                    GameObject.DestroyImmediate(mom.textureBakeResults);
                    mom.textureBakeResults = null;
                }
                EditorUtility.ClearProgressBar();
            }
        }