public static void Do() { GameObject obj = Selection.activeGameObject; if (obj != null) { string directory = EditorUtility.OpenFolderPanel("Save", "Assets/KGame", ""); if (!directory.Contains(VIO.WorkSpace())) { return; } VIO.MeshUtil.CopyMeshToDst(obj.GetComponent <MeshFilter>(), directory, false); AssetDatabase.Refresh(); } }
public static Mesh CopyMeshToDst(MeshFilter mf, string directory, bool auto2UV) { if (mf != null) { Mesh mesh = mf.sharedMesh; if (mesh != null) { if (!directory.Contains(VIO.WorkSpace())) { return(null); } Mesh newMesh = new Mesh(); newMesh.vertices = mesh.vertices; newMesh.uv = mesh.uv; newMesh.normals = mesh.normals; newMesh.triangles = mesh.triangles; newMesh.bounds = mesh.bounds; newMesh.subMeshCount = mesh.subMeshCount; for (int i = 0; i < newMesh.subMeshCount; i++) { newMesh.SetTriangles(mesh.GetTriangles(i), i); } if (auto2UV) { Unwrapping.GenerateSecondaryUVSet(newMesh); } string unityPath = ToUnity(directory + "/" + mesh.name); AssetDatabase.CreateAsset(newMesh, unityPath + ".asset"); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } return(mesh); } else { return(null); } }