void Play(AudioClip clip, string audioSourceName = "", bool toLoop = false, float pitch = 1.0f, bool playNext = false, bool replaceNext = false) { AudioSourceScript audioSource = GetAudioSource(audioSourceName); if (audioSource != null) { //if (audioSource.HasBacklog() && audioSource.IsMaxed()) //{ // Debug.Log(audioSourceName + " Is Full, Trying to search for another audioSource to Take Over the Job"); // bool found = false; // foreach (KeyValuePair<string, AudioSourceScript> entry in audioSources) // { // if (!entry.Value.HasBacklog()) // { // if (entry.Value.IsPlaying()) // continue; // } // else if (entry.Value.IsMaxed()) // continue; // found = true; // audioSource = entry.Value; // break; // } // if (!found) // { // Debug.Log(" Can't Find Suitable Role to Take Over the Job, Using Default to take over"); // audioSource = defaultAudioSource; // } // if (playNext) // if (replaceNext) // defaultAudioSource.ReplaceNext(clip, toLoop, pitch); // else // defaultAudioSource.PlayNext(clip, toLoop, pitch); // else // defaultAudioSource.PlayOnSchedule(clip, toLoop, pitch); //} //else if (playNext) { if (replaceNext) { audioSource.ReplaceNext(clip, toLoop, pitch); } else { audioSource.PlayNext(clip, toLoop, pitch); } } else { audioSource.PlayOnSchedule(clip, toLoop, pitch); } } else { Debug.Log("Cant Find AudioSource of name : " + audioSourceName + " Are you sure you entered the right name ?"); return; } }
public void AddAudioSource(string audioSourceName, AudioSourceScript audioSource) { audioSources.Add(audioSourceName, audioSource); if (defaultAudioSource == null) { defaultAudioSource = audioSource; } }
// Start is called before the first frame update void Start() { if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } DontDestroyOnLoad(this); source = GetComponent <AudioSource>(); }
public void ChangeClip(AudioClip clip, bool toLoop = false, float pitch = 1.0f, bool replaceNext = false, string audioSourceName = "") { AudioSourceScript audioSource = GetAudioSource(audioSourceName); if (audioSource != null) { audioSource.ChangeClip(clip, toLoop, pitch, replaceNext); } else { Debug.Log("Cant Find AudioSourceName : " + audioSourceName + " Are you sure youve entered the right name?"); return; } }
//void Initialze(Database database, string tableName) //{ // database.dbConnection.Open(); // database.dbCmd = database.dbConnection.CreateCommand(); // string sqlQuery = "SELECT * FROM " + tableName; // database.dbCmd.CommandText = sqlQuery; // database.reader = database.dbCmd.ExecuteReader(); // while (database.reader.Read()) // { // for (AUDIO_TYPE i = AUDIO_TYPE.BACKGROUND_MUSIC; i < AUDIO_TYPE.END; ++i) // { // GetAudioManagerByType(i).SetAllVolume(database.reader.GetFloat((int)i)); // } // } // database.SoftReset(); // Debug.Log("Finished Creating AudioClip From Database"); //} void AddAudioSource(AudioSourceScript audioSource) { if (CheckIfExist(audioSource.gameObject.name)) { Debug.Log("Already Have AudioSource with name : " + audioSource + " Please Set it to a different name in the editor"); return; } foreach (KeyValuePair <AUDIO_TYPE, AudioManager> entry in audioList) { if (entry.Key == audioSource.type) { entry.Value.AddAudioSource(audioSource.gameObject.name, audioSource); } } }