コード例 #1
0
    /**
     * Create the prefabs for the pool
     */
    GameObject SpawnForPool(AudioPool audioPool, List <AudioSource> pool)
    {
        GameObject instance = new GameObject(audioPool.audioClip.name);

        //disable this at the moment
        instance.SetActive(false);

        //add the ParticleClip so it can accessed by this ParticleManager
        AudioSource audioSource = instance.AddComponent <AudioSource>();

        audioSource.clip = audioPool.audioClip;

        AudioManagerClip amClip = instance.AddComponent <AudioManagerClip>();

        amClip.audioType = audioPool.audioType;

        pool.Add(audioSource);

        //set the parent to this (ParticleManager's) game object
        //so our hierarchy looks clean
        instance.transform.parent = this.gameObject.transform;

        //we don't want our pool instance destroyed when we change the scene
//		DontDestroyOnLoad(instance);


        return(instance);
    }
コード例 #2
0
ファイル: AudioManager.cs プロジェクト: crilose/NoNutGame
    public void Play(AudioManagerClip clip)
    {
        AudioSource source = _sources[clip];

        source.clip   = clip.Clip;
        source.volume = clip.Volume;
        source.pitch  = clip.Pitch;
        source.loop   = clip.Loop;

        source.Play();
    }
コード例 #3
0
ファイル: AudioManager.cs プロジェクト: crilose/NoNutGame
    public void Play(string name)
    {
        AudioManagerClip clip = System.Array.Find(Clips, c => c.Name == name);

        if (clip != null)
        {
            Play(clip);
        }
        else
        {
            Debug.LogWarning("Audio clip \"" + name + "\" not found!");
        }
    }
コード例 #4
0
 public void Unmute(AudioType audioType)
 {
     foreach (AudioSource aSource in m_ActiveSound)
     {
         AudioManagerClip amc = aSource.GetComponent <AudioManagerClip> ();
         if (amc != null)
         {
             if (amc.audioType == audioType)
             {
                 amc.Unmute();
             }
         }
     }
 }
コード例 #5
0
 public void SetVolume(AudioType audioType, float volume, float fadingTime)
 {
     foreach (AudioSource aSource in m_ActiveSound)
     {
         AudioManagerClip amc = aSource.GetComponent <AudioManagerClip> ();
         if (amc != null)
         {
             if (amc.audioType == audioType)
             {
                 Debug.Log("Fade si:" + amc.gameObject.name + "v:" + volume + " fadeTime:" + fadingTime);
                 amc.Fade(volume, fadingTime);
             }
         }
     }
 }
コード例 #6
0
    public void SetVolume(string soundName, AudioType audioType, float volume, float fadingTime)
    {
        //get the Particle info from dictionary
        AudioPool audioPool;

        if (m_AudioDictionary.TryGetValue(soundName, out audioPool))
        {
            //get the list from the pool dictionary
            List <AudioSource> pool;
            if (m_AudioPool.TryGetValue(soundName, out pool))
            {
                //search the ACTIVE game object
                int i = 0;
                while (i < pool.Count)
                {
                    GameObject currentGameObject = pool[i].gameObject;
                    Debug.Log("CurrentGameObject:::::" + currentGameObject);
                    if (currentGameObject.activeInHierarchy)
                    {
                        Debug.Log(currentGameObject + "  is activeInHierarchy");
                        AudioManagerClip amClip = currentGameObject.GetComponent <AudioManagerClip>();

                        // if it's BGM, check the BGM play and
                        // if it's SFX, check the SFX play
                        if ((amClip.audioType == AudioType.BGM && IsBgmPlay) ||
                            (amClip.audioType == AudioType.SFX && IsSfxPlay))
                        {
                            if (audioType != null)
                            {
                                if ((audioType == AudioType.BGM && amClip.audioType == AudioType.BGM) ||
                                    (audioType == AudioType.SFX && amClip.audioType == AudioType.SFX))
                                {
                                    // play fading
                                    amClip.Fade(volume, fadingTime);
                                }
                                else
                                {
                                    // don't care, just change
                                    amClip.Fade(volume, fadingTime);
                                }
                            }
                            else
                            {
                                // play fading
                                amClip.Fade(volume, fadingTime);
                            }
                        }
                        else
                        {
                            // just fade
                            amClip.Fade(volume, fadingTime);
                        }
                    }
                    i++;
                }
            }
            else
            {
                Debug.LogWarning("No prefabs called " + soundName + " in particle pool dictionary");
            }
        }
        else
        {
            Debug.LogWarning("No prefabs called " + soundName + " in dictionary");
        }
    }
コード例 #7
0
    public GameObject Play(string soundName, bool isLoop, float volume, float fadingTime, bool once)
    {
        if (m_IsPause)
        {
            return(null);
        }

        //get the Particle info from dictionary
        AudioPool audioPool;

        if (m_AudioDictionary.TryGetValue(soundName, out audioPool))
        {
            //get the list from the pool dictionary
            List <AudioSource> pool;
            GameObject         spawnObject = null;
            if (m_AudioPool.TryGetValue(soundName, out pool))
            {
                //search the inactive game object
                bool found = false;
                int  i     = 0;
                while (!found && i < pool.Count)
                {
                    GameObject currentGameObject = pool[i].gameObject;
                    if (!currentGameObject.activeInHierarchy)
                    {
                        spawnObject = currentGameObject;
                        found       = true;
                    }
                    else
                    {
                        // check it's active but being silent
                        AudioManagerClip amClip = currentGameObject.GetComponent <AudioManagerClip>();


                        // Don't play at all if it's once and found someone playing
                        if (once)
                        {
                            if (amClip.GetVolume() > 0f || !amClip.GetAudioSource().mute)
                            {
                                return(null);
                            }
                        }

                        if (amClip.GetVolume() <= 0f || amClip.GetAudioSource().mute)
                        {
                            spawnObject = currentGameObject;
                            found       = true;
                        }
                    }
                    i++;
                }

                //check the game object available
                if (spawnObject != null)
                {
                    // find other playing audio if it's only once
                    if (once)
                    {
                        //search the inactive game object
                        bool foundPlaying = false;
                        int  itPlaying    = 0;
                        while (!foundPlaying && itPlaying < pool.Count)
                        {
                            GameObject currentGameObject = pool[itPlaying].gameObject;
                            // check it's active but being silent
                            AudioManagerClip playingClip = currentGameObject.GetComponent <AudioManagerClip>();
                            if (playingClip.GetVolume() <= 0f || playingClip.GetAudioSource().mute)
                            {
                                foundPlaying = true;
                            }
                            itPlaying++;
                        }

                        if (foundPlaying)
                        {
                            return(null);
                        }
                    }

                    AudioManagerClip amClip = spawnObject.GetComponent <AudioManagerClip>();

                    // if it's BGM, check the BGM play and
                    // if it's SFX, check the SFX play
                    if ((amClip.audioType == AudioType.BGM && IsBgmPlay) ||
                        (amClip.audioType == AudioType.SFX && IsSfxPlay))
                    {
                        AudioSource audioSource = spawnObject.GetComponent <AudioSource>();
                        //set the GameObject active
                        spawnObject.SetActive(true);

                        audioSource.Play();

                        // check muted
                        if (amClip.audioType == AudioType.BGM)
                        {
                            if (GameSaveManager.Instance.IsBGMPlay())
                            {
                                amClip.Unmute();
                            }
                            else
                            {
                                amClip.Mute();
                            }
                        }
                        if (amClip.audioType == AudioType.SFX)
                        {
                            if (GameSaveManager.Instance.IsSFXPlay())
                            {
                                amClip.Unmute();
                            }
                            else
                            {
                                amClip.Mute();
                            }
                        }


                        if (fadingTime > 0)
                        {
                            amClip.Fade(volume, fadingTime);
                        }
                        else
                        {
                            amClip.SetVolume(volume);
                        }

                        audioSource.loop = isLoop;

                        //add the spawned object to our active list
                        m_ActiveSound.Add(audioSource);
                    }

                    //return the succeedly found object. YAY!
                    return(spawnObject);
                }
                else
                {
                    //create new object for particle pool
                    if (audioPool.isExpanding)
                    {
                        GameObject go = SpawnForPool(audioPool, pool);
                        return(go);
                    }
                    else
                    {
                        Debug.LogWarning("No inactive gameobjects for " + soundName);

                        return(null);
                    }
                }
            }
            else
            {
                Debug.LogWarning("No prefabs called " + soundName + " in particle pool dictionary");
                return(null);
            }
        }
        else
        {
            Debug.LogWarning("No prefabs called " + soundName + " in dictionary");
            return(null);
        }
    }