void createAndSetupBaker(List <GameObjectFilterInfo> gaws, string pthRoot) { for (int i = gaws.Count - 1; i >= 0; i--) { if (gaws[i].go == null) { gaws.RemoveAt(i); } } if (gaws.Count < 1) { Debug.LogError("No game objects."); return; } if (pthRoot == null || pthRoot == "") { Debug.LogError("Folder for saving created assets was not set."); return; } int numVerts = 0; for (int i = 0; i < gaws.Count; i++) { if (gaws[i].go != null) { numVerts = gaws[i].numVerts; } } GameObject newMeshBaker = null; if (numVerts >= 65535) { newMeshBaker = MB3_MultiMeshBakerEditor.CreateNewMeshBaker(); } else { newMeshBaker = MB3_MeshBakerEditor.CreateNewMeshBaker(); } newMeshBaker.name = ("MeshBaker-" + gaws[0].shaderName + "-LM" + gaws[0].lightmapIndex).ToString().Replace("/", "-"); MB3_TextureBaker tb = newMeshBaker.GetComponent <MB3_TextureBaker>(); MB3_MeshBakerCommon mb = tb.GetComponentInChildren <MB3_MeshBakerCommon>(); tb.GetObjectsToCombine().Clear(); for (int i = 0; i < gaws.Count; i++) { if (gaws[i].go != null) { tb.GetObjectsToCombine().Add(gaws[i].go); } } if (gaws[0].numMaterials > 1) { string pthMat = AssetDatabase.GenerateUniqueAssetPath(pthRoot + newMeshBaker.name + ".asset"); MB3_TextureBakerEditorInternal.CreateCombinedMaterialAssets(tb, pthMat); tb.doMultiMaterial = true; SerializedObject tbr = new SerializedObject(tb); SerializedProperty resultMaterials = tbr.FindProperty("resultMaterials"); MB3_TextureBakerEditorInternal.ConfigureMutiMaterialsFromObjsToCombine(tb, resultMaterials, tbr); } else { string pthMat = AssetDatabase.GenerateUniqueAssetPath(pthRoot + newMeshBaker.name + ".asset"); MB3_TextureBakerEditorInternal.CreateCombinedMaterialAssets(tb, pthMat); } if (gaws[0].isMeshRenderer) { mb.meshCombiner.renderType = MB_RenderType.meshRenderer; } else { mb.meshCombiner.renderType = MB_RenderType.skinnedMeshRenderer; } }
void createAndSetupBaker(List <_GameObjectAndWarning> gaws, string pthRoot) { if (gaws.Count < 1) { return; } int numVerts = 0; for (int i = 0; i < gaws.Count; i++) { numVerts = gaws[i].numVerts; } GameObject newMeshBaker = null; if (numVerts >= 65535) { newMeshBaker = MB3_MultiMeshBakerEditor.CreateNewMeshBaker(); } else { newMeshBaker = MB3_MeshBakerEditor.CreateNewMeshBaker(); } newMeshBaker.name = ("MeshBaker-" + gaws[0].shader.name + "-LM" + gaws[0].lightmapIndex).ToString().Replace("/", "-"); MB3_TextureBaker tb = newMeshBaker.GetComponent <MB3_TextureBaker>(); //string pth = AssetDatabase.GenerateUniqueAssetPath(pthRoot); //create result material string pthMat = AssetDatabase.GenerateUniqueAssetPath(pthRoot + newMeshBaker.name + ".mat"); AssetDatabase.CreateAsset(new Material(Shader.Find("Diffuse")), pthMat); tb.resultMaterial = (Material)AssetDatabase.LoadAssetAtPath(pthMat, typeof(Material)); //create the MB2_TextureBakeResults string pthAsset = AssetDatabase.GenerateUniqueAssetPath(pthRoot + newMeshBaker.name + ".asset"); AssetDatabase.CreateAsset(ScriptableObject.CreateInstance <MB2_TextureBakeResults>(), pthAsset); tb.textureBakeResults = (MB2_TextureBakeResults)AssetDatabase.LoadAssetAtPath(pthAsset, typeof(MB2_TextureBakeResults)); AssetDatabase.Refresh(); tb.resultMaterial.shader = gaws[0].shader; tb.objsToMesh = new List <GameObject>(); for (int i = 0; i < gaws.Count; i++) { tb.objsToMesh.Add(gaws[i].go); } MB3_MeshBakerCommon mb = newMeshBaker.GetComponent <MB3_MeshBakerCommon>(); if (generate_LightmapOption == LightMapOption.ignore) { mb.meshCombiner.lightmapOption = MB2_LightmapOptions.ignore_UV2; } else { if (gaws[0].lightmapIndex == -1 || gaws[0].lightmapIndex == -2) { mb.meshCombiner.lightmapOption = MB2_LightmapOptions.ignore_UV2; } else { mb.meshCombiner.lightmapOption = MB2_LightmapOptions.preserve_current_lightmapping; } } }