Last active
August 29, 2015 14:15
-
-
Save kankikuchi/52d79561df4652d790e2 to your computer and use it in GitHub Desktop.
オーディオのファイル名を定数で管理するクラスを作成するエディタ拡張(ConstantsClassCreator使用版)【Unity】
This file contains hidden or 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
using System; | |
using System.IO; | |
using System.Text; | |
using UnityEditor; | |
using UnityEditorInternal; | |
using UnityEngine; | |
using System.Collections.Generic; | |
/// <summary> | |
/// オーディオのファイル名を定数で管理するクラスを作成するスクリプト | |
/// </summary> | |
public static class AudioNameCreator{ | |
//オーディオファイルのパス | |
private const string BGM_DIRECTORY_PATH = "Audio/BGM"; | |
private const string SE_DIRECTORY_PATH = "Audio/SE"; | |
// コマンド名 | |
private const string COMMAND_NAME = "Tools/Create/Audio Name"; | |
/// <summary> | |
/// オーディオのファイル名を定数で管理するクラスを作成します | |
/// </summary> | |
[MenuItem(COMMAND_NAME)] | |
public static void Create() | |
{ | |
if (!CanCreate()) | |
{ | |
return; | |
} | |
CreateScript(); | |
} | |
/// <summary> | |
/// スクリプトを作成します | |
/// </summary> | |
public static void CreateScript() | |
{ | |
//指定したパスのリソースを全て取得 | |
object[] bgmList = Resources.LoadAll(BGM_DIRECTORY_PATH); | |
object[] seList = Resources.LoadAll(SE_DIRECTORY_PATH); | |
//取得したオーディオリストの名前をDictionary形式でまとめる | |
Dictionary<string, string> audioDic = new Dictionary<string, string> (); | |
foreach(AudioClip bgm in bgmList){ | |
audioDic [bgm.name] = bgm.name; | |
} | |
foreach(AudioClip se in seList){ | |
audioDic [se.name] = se.name; | |
} | |
ConstantsClassCreator.Create ("AudioName", "オーディオ名を定数で管理するクラス", audioDic); | |
} | |
/// <summary> | |
/// オーディオのファイル名を定数で管理するクラスを作成できるかどうかを取得します | |
/// </summary> | |
[MenuItem(COMMAND_NAME, true)] | |
private static bool CanCreate() | |
{ | |
return !EditorApplication.isPlaying && !Application.isPlaying && !EditorApplication.isCompiling; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment