Esempio n. 1
0
    public static void Play(string keyName, float fadeTime = 0.6f)
    {
        Init();
        if (currentAudioGroupData != null && keyName == currentAudioGroupData.keyName && audioGroupPlayState == AudioGroupPlayState.Playing)
        {
            return;
        }

        //Debug.Log("AudioGroupSystem.Play :" + keyName);
        audioGroupPlayState = AudioGroupPlayState.Playing;


        // Dictionary<int, AudioAsset> playingMusics = AudioPlayManager.a2DPlayer.bgMusicDic;
        if (currentAudioGroupData != null)
        {
            foreach (var item in currentAudioGroupData.fixedMusicDatas)
            {
                AudioPlayManager.StopMusic2D(item.channel, fadeTime);
            }
            foreach (var ss in currentAudioGroupData.loopMusicDatas)
            {
                foreach (var item in ss.musicDatas)
                {
                    AudioPlayManager.StopMusic2D(item.channel, fadeTime);
                }
            }
        }
        currentAudioGroupData = audioGroupDataDic[keyName];
        for (int i = 0; i < currentAudioGroupData.fixedMusicDatas.Count; i++)
        {
            MusicPlayData data = currentAudioGroupData.fixedMusicDatas[i];
            PlayMusicData(data);
        }

        foreach (var item in currentAudioGroupData.fixedSFXDatas)
        {
            PlaySFXData(item);
        }

        instance.randomLoopSFXDatas.Clear();
        foreach (var item in currentAudioGroupData.sFXRandomLoopDatas)
        {
            instance.randomLoopSFXDatas.Add(new RandomLoopSFXData(item));
        }

        foreach (var item in instance.randomLoopMusicDatas)
        {
            item.Close();
        }
        instance.randomLoopMusicDatas.Clear();
        foreach (var item in currentAudioGroupData.loopMusicDatas)
        {
            instance.randomLoopMusicDatas.Add(new RandomLoopMusicData(item));
        }
    }
    private void OnGUI()
    {
        EditorDrawGUIUtil.DrawScrollView(this, () =>
        {
            EditorDrawGUIUtil.DrawList("", datas, itemTitleName: (item) =>
            {
                AudioGroupData da = (AudioGroupData)item;
                return(da.keyName);
            });
        });


        GUILayout.FlexibleSpace();
        if (GUILayout.Button("Save"))
        {
            string json = JsonUtils.ToJson(datas);
            FileUtils.CreateTextFile(SaveDir + AudioGroupSystem.ConfigName + ".txt", json);

            ShowNotification(new GUIContent("已保存!"));
        }
    }
    public static void Play(string keyName, float fadeTime = 0.6f)
    {
        Init();
        if (currentAudioGroupData != null && keyName == currentAudioGroupData.keyName)
        {
            return;
        }

        audioGroupPlayState   = AudioGroupPlayState.Playing;
        currentAudioGroupData = audioGroupDataDic[keyName];

        Dictionary <int, AudioAsset> playingMusics = AudioPlayManager.a2DPlayer.bgMusicDic;

        foreach (var item in playingMusics)
        {
            if (item.Key > currentAudioGroupData.fixedMusicDatas.Count - 1)
            {
                AudioPlayManager.StopMusic2D(item.Key, fadeTime);
            }
        }
        for (int i = 0; i < currentAudioGroupData.fixedMusicDatas.Count; i++)
        {
            MusicPlayData data = currentAudioGroupData.fixedMusicDatas[i];
            PlayMusicData(data);
        }

        foreach (var item in currentAudioGroupData.fixedSFXDatas)
        {
            PlaySFXData(item);
        }

        instance.randomLoopSFXDatas.Clear();
        foreach (var item in currentAudioGroupData.sFXRandomLoopDatas)
        {
            instance.randomLoopSFXDatas.Add(AddLoopSFX(item));
        }
    }