void SaveMeshAssets() { try { foreach (Object targetObject in targets) { MeshSimplify meshSimplify = targetObject as MeshSimplify; GameObject gameObject = meshSimplify.gameObject; if (meshSimplify.MeshSimplifyRoot == null /* && meshSimplify.m_bEnablePrefabUsage*/) { string strMeshAssetPath = meshSimplify.AssetPath; //if (string.IsNullOrEmpty(strMeshAssetPath)) { //Debug.Log("Showing file selection panel"); string path; string name; if (string.IsNullOrEmpty(strMeshAssetPath)) { path = AssetDatabase.GetAssetPath(gameObject); name = Path.GetFileNameWithoutExtension(path); path = Path.GetDirectoryName(path); } else { path = strMeshAssetPath; name = Path.GetFileNameWithoutExtension(path); path = Path.GetDirectoryName(path); int idx = name.LastIndexOf('_'); if (idx >= 0) { name = name.Remove(idx, name.Length - idx); } } if (path.StartsWith("Assets/")) { path = path.Remove(0, 7); } strMeshAssetPath = UnityEditor.EditorUtility.SaveFilePanelInProject("Save mesh asset(s)", name + "_" + meshSimplify.GetSimplifiedTriangleCount(true).ToString() + ".asset", "asset", "Please enter a file name to save the mesh asset(s) to", path); if (strMeshAssetPath.Length == 0) { //Debug.LogWarning("strMeshAssetPath.Length == 0. User cancelled?"); return; } //Debug.Log("User selected " + strMeshAssetPath + " using panel."); meshSimplify.AssetPath = strMeshAssetPath; } int nCounter = 0; //Debug.Log("Saving files to " + strMeshAssetPath + ". Exists previously?: " + System.IO.File.Exists(strMeshAssetPath)); SaveMeshAssetsRecursive(gameObject, gameObject, strMeshAssetPath, true, System.IO.File.Exists(strMeshAssetPath), ref nCounter); } } } catch (System.Exception e) { Debug.LogError("Error saving mesh assets to disk: " + e.Message + " Stack: " + e.StackTrace); EditorUtility.ClearProgressBar(); Simplifier.Cancelled = false; } EditorUtility.ClearProgressBar(); UnityEditor.AssetDatabase.Refresh(); Simplifier.Cancelled = false; }