示例#1
0
    // SOUNDS
    public void PlaySound(SoundNames soundID)
    {
        SoundSO sound = Sounds.Find(s => s.SoundID == soundID);

        if (sound != null)
        {
            StartCoroutine(PlayingSound(sound));
        }
    }
示例#2
0
 private SoundSO GetSound(SoundSO sound)
 {
     if (!soundsList.Contains(sound))
     {
         soundsList.Add(sound);
         sound.source = gameObject.AddComponent <AudioSource>();
         sound.Init();
     }
     return(sound);
 }
示例#3
0
    private SoundSO GetSound(string name)
    {
        SoundSO s = Array.Find <SoundSO>(sounds, sound => sound._name == name);

        if (s.source == null)
        {
            s.source = gameObject.AddComponent <AudioSource>();
            s.Init();
        }
        return(s);
    }
示例#4
0
    public void PlaySound(string soundName)
    {
        SoundSO s = Array.Find(sounds, sound => sound.name == soundName);

        if (s == null)
        {
            Debug.LogWarning("Sound: " + soundName + " not found");
            return;
        }
        if (!s.multipleSounds)
        {
            s.source.Play();
        }
        else
        {
            s.source.clip = s.clips[UnityEngine.Random.Range(0, s.clips.Length - 1)];
            s.source.Play();
        }
    }
示例#5
0
    public IEnumerator PlayingSound(SoundSO sound)
    {
        AudioSource audio = Instantiate(Resources.Load("Prefabs/AudioPrefab") as GameObject, SoundsContainer.transform).GetComponent <AudioSource>();

        if (!SoundSources.ContainsKey(sound.SoundID))
        {
            SoundSources.Add(sound.SoundID, new List <AudioSource>());
        }
        SoundSources[sound.SoundID].Add(audio);

        audio.PlayOneShot(sound.Sound);

        yield return(new WaitForSeconds(sound.Sound.length));

        SoundSources[sound.SoundID].Remove(audio);
        if (SoundSources[sound.SoundID].Count <= 0)
        {
            SoundSources.Remove(sound.SoundID);
        }

        Destroy(audio.gameObject);
    }
示例#6
0
    public void PlayAudio(SoundSO soundToPlay)
    {
        SoundSO soundSelected = Array.Find(sound, sound => sound.name == soundToPlay.name);

        soundSelected.source.Play();
    }
示例#7
0
 public void SetVolume(SoundSO sound, float volume)
 {
     GetSound(sound).SetVolume(volume);
 }
示例#8
0
 public void StopPlay(SoundSO sound)
 {
     GetSound(sound).Stop();
 }
示例#9
0
 public void PlaySoundEffect(SoundSO sound)
 {
     GetSound(sound).PlayRandon();
 }