public static void SaveMeshsToAssetDatabase(SA3MeshCombineCommon mom, string folderPath, string newFileNameBase) { if (SA3MeshCombiner.EVAL_VERSION) { return; } if (mom is SA3MeshCombine) { SA3MeshCombine mb = (SA3MeshCombine)mom; string newFilename = newFileNameBase + ".asset"; string ap = AssetDatabase.GetAssetPath(((SA3MeshCombinerSingle)mb.meshCombiner).GetMesh()); if (ap == null || ap.Equals("")) { Debug.Log("Saving mesh asset to " + newFilename); AssetDatabase.CreateAsset(((SA3MeshCombinerSingle)mb.meshCombiner).GetMesh(), newFilename); } else { Debug.Log("Mesh is an asset at " + ap); } } else if (mom is SA3MultiMeshCombine) { SA3MultiMeshCombine mmb = (SA3MultiMeshCombine)mom; List <SA3MultiMeshCombiner.CombinedMesh> combiners = ((SA3MultiMeshCombiner)mmb.meshCombiner).meshCombiners; for (int i = 0; i < combiners.Count; i++) { string newFilename = newFileNameBase + i + ".asset"; Mesh mesh = combiners[i].combinedMesh.GetMesh(); string ap = AssetDatabase.GetAssetPath(mesh); if (ap == null || ap.Equals("")) { Debug.Log("Saving mesh asset to " + newFilename); AssetDatabase.CreateAsset(mesh, newFilename); } else { Debug.Log("Mesh is an asset at " + ap); } } } else { Debug.LogError("Argument was not a SA3MeshCombine or an SA3MultiMeshCombine."); } }
public static void RebuildPrefab(SA3MeshCombineCommon mom) { if (SA3MeshCombiner.EVAL_VERSION) { return; } if (mom is SA3MeshCombine) { SA3MeshCombine mb = (SA3MeshCombine)mom; SA3MeshCombinerSingle mbs = (SA3MeshCombinerSingle)mb.meshCombiner; GameObject prefabRoot = mom.resultPrefab; GameObject rootGO = (GameObject)PrefabUtility.InstantiatePrefab(prefabRoot); SA3MeshCombinerSingle.BuildSceneHierarch(mbs, rootGO, mbs.GetMesh()); string prefabPth = AssetDatabase.GetAssetPath(prefabRoot); PrefabUtility.ReplacePrefab(rootGO, AssetDatabase.LoadAssetAtPath(prefabPth, typeof(GameObject)), ReplacePrefabOptions.ConnectToPrefab); Editor.DestroyImmediate(rootGO); } else if (mom is SA3MultiMeshCombine) { SA3MultiMeshCombine mmb = (SA3MultiMeshCombine)mom; SA3MultiMeshCombiner mbs = (SA3MultiMeshCombiner)mmb.meshCombiner; GameObject prefabRoot = mom.resultPrefab; GameObject rootGO = (GameObject)PrefabUtility.InstantiatePrefab(prefabRoot); for (int i = 0; i < mbs.meshCombiners.Count; i++) { SA3MeshCombinerSingle.BuildSceneHierarch(mbs.meshCombiners[i].combinedMesh, rootGO, mbs.meshCombiners[i].combinedMesh.GetMesh(), true); } string prefabPth = AssetDatabase.GetAssetPath(prefabRoot); PrefabUtility.ReplacePrefab(rootGO, AssetDatabase.LoadAssetAtPath(prefabPth, typeof(GameObject)), ReplacePrefabOptions.ConnectToPrefab); Editor.DestroyImmediate(rootGO); } else { Debug.LogError("Argument was not a SA3MeshCombine or an SA3MultiMeshCombine."); } }