Exemplo n.º 1
0
    /// <summary>
    /// regist by SoundSceneResource.
    /// </summary>
    /// <param name="soundAudioInfos"></param>
    public void RegisterAudioSource(List <soundAudioInfo> soundAudioInfos, SoundSceneResource soundSceneResource)
    {
        //! 若這個場景已註冊過SoundSceneResource,就直接加入AudioSource就好.
        if (firstSoundSceneResourceInCurrentScene != null)
        {
            AddRegisterAudioSource(soundAudioInfos);
            return;
        }
        else
        {
            //! 記住場景中第一個soundSceneResource.
            firstSoundSceneResourceInCurrentScene = soundSceneResource;
        }

        //! 關閉上個流程音效
        for (int i = 0; i < soundAudios.Count; i++)
        {
            if (soundAudios[i].isPlaying)
            {
                soundAudios[i].Stop();
            }

            Destroy(soundAudios[i]);
        }
        soundAudios.Clear();

        audioDic.Clear();


        // system sound.

        foreach (KeyValuePair <string, soundAudioInfo> sysAdo in sysAudioDic)
        {
            if ((sysAdo.Value.name == "") && (sysAdo.Value.audioClip != null))
            {
                sysAdo.Value.name = sysAdo.Value.audioClip.name;
            }
            audioDic[sysAdo.Value.name] = sysAdo.Value;
        }
        int soundCount = soundAudioInfos.Count;

        if (soundCount > 30)
        {
            Debug.LogWarning("Too much soundAudioInfo loading");
        }
        // normal sound.
        for (int i = 0; i < soundCount; i++)
        {
            if ((soundAudioInfos[i].name == "") && (soundAudioInfos[i].audioClip != null))
            {
                soundAudioInfos[i].name = soundAudioInfos[i].audioClip.name;
            }
            audioDic[soundAudioInfos[i].name] = soundAudioInfos[i];
        }
    }
Exemplo n.º 2
0
 /// <summary>
 /// 反註冊soundSceneResource.
 /// </summary>
 public void UnRegisterSoundSceneResource()
 {
     firstSoundSceneResourceInCurrentScene = null;
 }