-
-
Save todorok1/83cf55464c3c027bec45c47bcf52e52a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <Summary> | |
/// 結合したメッシュをアセットとして保存します。 | |
/// 保存先は現在開いているシーン名のフォルダです。 | |
/// </Summary> | |
void SaveMeshAsAsset(Mesh saveMesh) | |
{ | |
// 現在開いているシーンのパスを取得します。 | |
string scenePath = EditorSceneManager.GetActiveScene().path; | |
// フォルダの存在を確認します。 | |
string folderPath = scenePath.Replace(".unity", ""); | |
bool existFolder = AssetDatabase.IsValidFolder(folderPath); | |
// フォルダがない場合は作成します。 | |
if (!existFolder) | |
{ | |
string sceneName = EditorSceneManager.GetActiveScene().name; | |
string parentFolder = folderPath.Substring(0, folderPath.LastIndexOf(sceneName) - 1); | |
string folderName = sceneName; | |
AssetDatabase.CreateFolder(parentFolder, folderName); | |
} | |
// メッシュを保存します。 | |
string meshPath = $"{folderPath}/{saveMesh.name}.asset"; | |
var asset = (Mesh)AssetDatabase.LoadAssetAtPath(meshPath, typeof(Mesh)); | |
if (asset == null) | |
{ | |
AssetDatabase.CreateAsset(saveMesh, meshPath); | |
} | |
else | |
{ | |
EditorUtility.CopySerialized(saveMesh, asset); | |
AssetDatabase.SaveAssets(); | |
} | |
AssetDatabase.Refresh(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment