Chatterer.chatterer.load_beep_audio C# (CSharp) Method

load_beep_audio() private method

private load_beep_audio ( ) : void
return void
        private void load_beep_audio()
        {
            string[] audio_file_ext = { "*.wav", "*.ogg", "*.aif", "*.aiff" };

            string probe_sounds_root = AssemblyLoader.loadedAssemblies.GetPathByType(typeof(chatterer)) + "/../../../Sounds/beeps/";
            //if (Application.platform == RuntimePlatform.OSXPlayer) probe_sounds_root = KSPUtil.ApplicationRootPath.Substring(0, KSPUtil.ApplicationRootPath.IndexOf("KSP.app")) + "GameData/RBR/Sounds/probe/";

            if (Directory.Exists(probe_sounds_root))
            {
                beeps_exists = true;

                string[] st_array;
                foreach (string ext in audio_file_ext)
                {
                    //if (debugging) Debug.Log("[CHATR] checking for " + ext + " files...");
                    st_array = Directory.GetFiles(probe_sounds_root, ext);
                    foreach (string file in st_array)
                    {
                        //if (debugging) Debug.Log("[CHATR] probe file = " + file);
                        //[CHATR] file = C:/KSP/ksp-win-0-21-1/KSP_win/GameData/RBR/Sounds/apollo11/capcom/capcom_16.ogg

                        //tear out the whole root + directory + st + one more for final slash
                        int start_pos = probe_sounds_root.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

                        string short_file_name = file_name.Substring(0, end_pos);

                        //if (debugging) Debug.Log("[CHATR] file_name = " + file_name);

                        if (ext == "*.mp3")
                        {
                            //GameDatabase won't load MP3
                            //try old method
                            string mp3_path = "file://" + AssemblyLoader.loadedAssemblies.GetPathByType(typeof(chatterer)) + "/../../../Sounds/beeps/" + short_file_name + ".mp3";
                            WWW www_chatter = new WWW(mp3_path);
                            if (www_chatter != null)
                            {
                                dict_probe_samples.Add(short_file_name, www_chatter.GetAudioClip(false));
                                dict_probe_samples2.Add(www_chatter.GetAudioClip(false), short_file_name);
                                if (debugging) Debug.Log("[CHATR] " + mp3_path + " loaded OK");
                            }
                            else
                            {
                                Debug.LogWarning("[CHATR] " + mp3_path + " load FAIL");
                            }
                        }
                        else
                        {
                            string gdb_path = "Chatterer/Sounds/beeps/" + short_file_name;
                            if (GameDatabase.Instance.ExistsAudioClip(gdb_path))
                            {
                                //all_beep_clips.Add(GameDatabase.Instance.GetAudioClip(gdb_path));
                                dict_probe_samples.Add(short_file_name, GameDatabase.Instance.GetAudioClip(gdb_path));
                                dict_probe_samples2.Add(GameDatabase.Instance.GetAudioClip(gdb_path), short_file_name);
                                //if (debugging) Debug.Log("[CHATR] " + gdb_path + " loaded OK");
                            }
                            else
                            {
                                //no ExistsAudioClip == false
                                Debug.LogWarning("[CHATR] " + gdb_path + " load FAIL");
                            }
                        }
                    }
                }
            }
        }
chatterer