private void load_chatter_audio()
{
//first, start a loop through all the elements in chatter_array
//check for a capsule directory
//if exists, run GetFiles() for each of the file extensions
string[] set_types = { "capcom", "capsule" };
string[] audio_file_ext = { "*.wav", "*.ogg", "*.aif", "*.aiff" };
int k;
string chatter_root = AssemblyLoader.loadedAssemblies.GetPathByType(typeof(chatterer)) + "/../../../Sounds/chatter/";
//string chatter_root = KSPUtil.ApplicationRootPath.Substring(0, KSPUtil.ApplicationRootPath.IndexOf("KSP_Data")) + "GameData/RBR/Sounds/chatter/";
if (Directory.Exists(chatter_root))
{
chatter_exists = true;
if (debugging) Debug.Log("[CHATR] loading chatter audio...");
for (k = 0; k < chatter_array.Count; k++)
{
if (Directory.Exists(chatter_root + chatter_array[k].directory))
{
//audioset directory found OK
//if (debugging) Debug.Log("[CHATR] directory [" + chatter_array[k].directory + "] found OK");
foreach (string st in set_types)
{
//search through each set_type (capcom, capsule)
if (Directory.Exists(chatter_root + chatter_array[k].directory + "/" + st))
{
//if (debugging) Debug.Log("[CHATR] directory [" + chatter_array[k].directory + "/" + st + "] found OK");
//if (debugging) Debug.Log("[CHATR] clearing existing " + chatter_array[k].directory + "/" + st + " audio");
if (st == "capcom") chatter_array[k].capcom.Clear();
else if (st == "capsule") chatter_array[k].capsule.Clear(); //clear any existing audio
string[] st_array;
foreach (string ext in audio_file_ext)
{
//if (debugging) Debug.Log("[CHATR] checking for " + ext + " files...");
st_array = Directory.GetFiles(chatter_root + chatter_array[k].directory + "/" + st + "/", ext);
foreach (string file in st_array)
{
//if (debugging) Debug.Log("[CHATR] file = " + file);
//[CHATR] file = C:/KSP/ksp-win-0-21-1/KSP_win/GameData/RBR/Sounds/apollo11/capcom\capcom_16.ogg
//try it anyway
//substring the capcom_16 out of file
//tear out the whole root + directory + st + one more for final slash
int start_pos = (chatter_root + chatter_array[k].directory + "/" + st + "/").Length;
string file_name = file.Substring(start_pos);
//end pos to find the pos of the "."
int end_pos = file_name.LastIndexOf(".");
//now need a length between
file_name = file_name.Substring(0, end_pos);
//if (debugging) Debug.Log("[CHATR] file_name = " + file_name);
if (ext == "*.mp3")
{
//try old method
string mp3_path = "file://" + AssemblyLoader.loadedAssemblies.GetPathByType(typeof(chatterer)) + "/../../../Sounds/chatter/" + chatter_array[k].directory + "/" + st + "/" + file_name + ".mp3";
WWW www_chatter = new WWW(mp3_path);
if (www_chatter != null)
{
if (st == "capcom")
{
chatter_array[k].capcom.Add(www_chatter.GetAudioClip(false));
//if (debugging) Debug.Log("[CHATR] " + mp3_path + " loaded OK");
}
else if (st == "capsule")
{
chatter_array[k].capsule.Add(www_chatter.GetAudioClip(false));
//if (debugging) Debug.Log("[CHATR] " + mp3_path + " loaded OK");
}
}
}
else
{
string gdb_path = "Chatterer/Sounds/chatter/" + chatter_array[k].directory + "/" + st + "/" + file_name;
if (GameDatabase.Instance.ExistsAudioClip(gdb_path))
{
if (st == "capcom")
{
chatter_array[k].capcom.Add(GameDatabase.Instance.GetAudioClip(gdb_path));
//if (debugging) Debug.Log("[CHATR] " + gdb_path + " loaded OK");
}
else if (st == "capsule")
{
chatter_array[k].capsule.Add(GameDatabase.Instance.GetAudioClip(gdb_path));
//if (debugging) Debug.Log("[CHATR] " + gdb_path + " loaded OK");
}
}
else
{
//no audio exists at gdb_path
Debug.LogWarning("[CHATR] " + gdb_path + " load FAIL, trying old method");
}
}
}
}
}
else
{
Debug.LogWarning("[CHATR] directory [" + chatter_array[k].directory + "/" + st + "] NOT found, skipping...");
}
}
}
else
{
//audioset directory NOT found
Debug.LogWarning("[CHATR] directory [" + chatter_array[k].directory + "] NOT found, skipping...");
}
}
}
load_toggled_chatter_sets();
}