Created
February 14, 2015 00:11
-
-
Save kankikuchi/f5471e8c3dde4765bc6b to your computer and use it in GitHub Desktop.
オーディオのファイル名を定数で管理するクラスを自動で作成するスクリプト【Unity】
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
/*ブログ説明用 | |
DirectoryPath.TOP_RESOURCES = "Assets/Resources/"; | |
DirectoryPath.AUDIO = "Audio"; | |
DirectoryPath.BGM = DirectoryPath.AUDIO + "/BGM"; | |
DirectoryPath.SE = DirectoryPath.AUDIO + "/SE"; | |
*/ | |
using System; | |
using System.IO; | |
using System.Text; | |
using UnityEditor; | |
using UnityEditorInternal; | |
using UnityEngine; | |
using System.Collections.Generic; | |
using System.Linq; | |
/// <summary> | |
/// オーディオのファイル名を定数で管理するクラスを自動で作成するスクリプト | |
/// </summary> | |
public class AudioNameCreator : AssetPostprocessorEx{ | |
private const string COMMAND_NAME = "Tools/Create/Audio Name"; // コマンド名 | |
//オーディオファイルが編集または追加されたら自動でAUDIO.csを作成する | |
private static void OnPostprocessAllAssets (string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) | |
{ | |
List<string[]> assetsList = new List<string[]> (){ | |
importedAssets, deletedAssets, movedAssets, movedFromAssetPaths | |
}; | |
List<string> targetDirectoryNameList = new List<string> (){ | |
DirectoryPath.TOP_RESOURCES + DirectoryPath.BGM, | |
DirectoryPath.TOP_RESOURCES + DirectoryPath.SE | |
}; | |
if(ExistsDirectoryInAssets(assetsList, targetDirectoryNameList)){ | |
Create (); | |
} | |
} | |
//スクリプトを作成します | |
[MenuItem(COMMAND_NAME)] | |
private static void Create() | |
{ | |
Dictionary<string, string> audioDic = Resources.LoadAll(DirectoryPath.AUDIO) | |
.Select(audioFile => ((AudioClip)audioFile).name) | |
.ToDictionary(audioFile => audioFile); | |
ConstantsClassCreator.Create ("AudioName", "オーディオ名を定数で管理するクラス", audioDic); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment