| | |
| | | [System.Serializable] |
| | | public class Sound |
| | | { |
| | | public string name; |
| | | public SoundName name; |
| | | public AudioClip clip; |
| | | public AudioMixerGroupEnum mixerGroup; |
| | | |
| | |
| | | sounds[i].SetSource(_go.AddComponent<AudioSource>(), audioMixer); |
| | | } |
| | | DontDestroyOnLoad(this); |
| | | PlaySound("MusicHappy"); |
| | | PlaySound(SoundName.MusicHappy); |
| | | } |
| | | |
| | | public void PlaySound(string _name) |
| | | public void PlaySound(SoundName _name) |
| | | { |
| | | if (_name == SoundName.None) |
| | | return; |
| | | |
| | | for (int i = 0; i < sounds.Length; i++) |
| | | { |
| | | if (sounds[i].name == _name) |
| | |
| | | Debug.LogWarning("SoundManager: Sounds not found in list: " + _name); |
| | | } |
| | | |
| | | public void PlaySoundAtPoint(GameObject gObject, string _name) |
| | | public void PlaySoundAtPoint(GameObject gObject, SoundName _name) |
| | | { |
| | | if (_name == SoundName.None) |
| | | return; |
| | | |
| | | gObject.AddComponent<AudioSource>(); |
| | | for (int i = 0; i < sounds.Length; i++) |
| | | { |
| | |
| | | |
| | | private static AudioSource PlayClipAtPointCustom(AudioSource audioSource, Vector3 pos, Sound sound) |
| | | { |
| | | audioSource.volume = sound.volume * (1 + Random.Range(-sound.randomVolume / 2f, sound.randomVolume / 2f)); |
| | | audioSource.pitch = sound.pitch * (1 + Random.Range(-sound.randomPitch / 2f, sound.randomPitch / 2f)); |
| | | GameObject tempGO = new GameObject("TempAudio"); // create the temp object |
| | | tempGO.transform.position = pos; // set its position |
| | | AudioSource tempASource = tempGO.AddComponent<AudioSource>(); // add an audio source |
| | |
| | | tempASource.playOnAwake = audioSource.playOnAwake; |
| | | tempASource.loop = audioSource.loop; |
| | | tempASource.priority = audioSource.priority; |
| | | tempASource.volume = audioSource.volume; |
| | | tempASource.pitch = audioSource.pitch; |
| | | tempASource.volume = audioSource.volume * (1 + Random.Range(-sound.randomVolume / 2f, sound.randomVolume / 2f)); |
| | | tempASource.pitch = audioSource.pitch * (1 + Random.Range(-sound.randomPitch / 2f, sound.randomPitch / 2f)); |
| | | tempASource.panStereo = audioSource.panStereo; |
| | | tempASource.spatialBlend = audioSource.spatialBlend; |
| | | tempASource.reverbZoneMix = audioSource.reverbZoneMix; |
| | |
| | | audioMixer.SetFloat("sfxVol", 20f * Mathf.Log10(_volume)); |
| | | } |
| | | |
| | | public void ChangeMusic(string _name) |
| | | public void ChangeMusic(SoundName _name) |
| | | { |
| | | for (int i = 0; i < sounds.Length; i++) |
| | | { |