public AudioClip PlaySound(HumanAISoundModule.SoundType type) { if (!this.m_AI || !this.m_AI.m_StartExecuted) { return(null); } AudioClip clip = this.m_Sounds[(int)type][UnityEngine.Random.Range(0, this.m_Sounds[(int)type].Count)]; return(this.PlaySound(clip)); }
private void InitHumanSoundsParser() { TextAsset textAsset = Resources.Load("Scripts/AI/HumanSounds") as TextAsset; if (textAsset) { TextAssetParser textAssetParser = new TextAssetParser(textAsset); for (int i = 0; i < textAssetParser.GetKeysCount(); i++) { Key key = textAssetParser.GetKey(i); if (key.GetName() == "Sound") { HumanAISoundModule.SoundType key2 = (HumanAISoundModule.SoundType)Enum.Parse(typeof(HumanAISoundModule.SoundType), key.GetVariable(0).SValue); this.m_Tribe0Sounds[(int)key2] = new List <AudioClip>(); this.m_Tribe1Sounds[(int)key2] = new List <AudioClip>(); this.m_Tribe2Sounds[(int)key2] = new List <AudioClip>(); string svalue = key.GetVariable(1).SValue; string path = "Sounds/" + key.GetVariable(2).SValue + "/Tribe0/" + svalue; AudioClip audioClip = Resources.Load <AudioClip>(path); if (audioClip) { this.m_Tribe0Sounds[(int)key2].Add(audioClip); } else { for (int j = 1; j < 99; j++) { path = string.Concat(new string[] { "Sounds/", key.GetVariable(2).SValue, "/Tribe0/", svalue, (j >= 10) ? string.Empty : "0", j.ToString() }); audioClip = Resources.Load <AudioClip>(path); if (!audioClip) { break; } this.m_Tribe0Sounds[(int)key2].Add(audioClip); } } path = "Sounds/" + key.GetVariable(2).SValue + "/Tribe1/" + svalue; audioClip = Resources.Load <AudioClip>(path); if (audioClip) { this.m_Tribe1Sounds[(int)key2].Add(audioClip); } else { for (int k = 1; k < 99; k++) { path = string.Concat(new string[] { "Sounds/", key.GetVariable(2).SValue, "/Tribe1/", svalue, (k >= 10) ? string.Empty : "0", k.ToString() }); audioClip = Resources.Load <AudioClip>(path); if (!audioClip) { break; } this.m_Tribe1Sounds[(int)key2].Add(audioClip); } } path = "Sounds/" + key.GetVariable(2).SValue + "/Tribe2/" + svalue; audioClip = Resources.Load <AudioClip>(path); if (audioClip) { this.m_Tribe2Sounds[(int)key2].Add(audioClip); } else { for (int l = 1; l < 99; l++) { path = string.Concat(new string[] { "Sounds/", key.GetVariable(2).SValue, "/Tribe2/", svalue, (l >= 10) ? string.Empty : "0", l.ToString() }); audioClip = Resources.Load <AudioClip>(path); if (!audioClip) { break; } this.m_Tribe2Sounds[(int)key2].Add(audioClip); } } } } Resources.UnloadAsset(textAsset); } else { DebugUtils.Assert("Missing HumanSounds script!", true, DebugUtils.AssertType.Info); } }