using System;using System.Linq;using System.Collections.Generic;using System.Threading;using System.Threading.Tasks; public partial class GetUiSubject { public async Task GetUI() { HomePanel homePanel = null; if (!fishingData.isMapBuff && !IsHideHomeMap) { var go = await UIManager.Instance.RestartShowUI(UITypes.HomePanel); homePanel = go.GetComponent(); } //实例 GContext.container.Resolve(); //这里确认补单 await GContext.container.Resolve().ReleaseReplenishment(); await Awaiters.SecondsRealtime(0.5f); GContext.container.Resolve().ShowRankTierChange(); if (fishingData.isMapBuff) { fishingData.isMapBuff = false; } else { fishingBehavior?.RodBehaviour.gameObject.SetActive(true); fishingBehavior.cameraAnimator.speed = 1; GContext.Publish(new ShowHandEvent() { isShow = true }); SetMapShow(!IsHideHomeMap); if (IsHideHomeMap) { IsHideHomeMap = false; } else if (homePanel != null) { homePanel.OnStart(); } } } } public partial class ManagerSubject { public async Task Init(System.Action progress) { //playerData = GContext.container.Resolve(); _tables = GContext.container.Resolve(); //var service = (SoundService)soundService; await soundService.InitAsync(); var opMap = new Dictionary>(); foreach (var addr in residentFish) { opMap[addr] = Addressables.LoadAssetAsync(addr); } var tasks = opMap.Values.Select(_ => _.Task); var total = (float)tasks.Count(); while (true) { var completed = tasks.Count(_ => _.IsCompleted); if (completed == total) { progress.Invoke(1f); break; } else { progress.Invoke(completed / total); } await Awaiters.NextFrame; } residentClip = opMap.ToDictionary(_ => _.Key, _ => _.Value.Result); disposables = new CompositeDisposable(); GContext.OnEvent().Subscribe(PlaySound).AddTo(disposables); GContext.OnEvent().Subscribe(PlayRewardSound).AddTo(disposables); GContext.OnEvent().Subscribe(PlayFishingSound).AddTo(disposables); GContext.OnEvent().Subscribe(PlayMusic).AddTo(disposables); GContext.OnEvent().Subscribe(FadeOutEvent).AddTo(disposables); GContext.OnEvent().Subscribe(PlaySoundByReference).AddTo(disposables); GContext.OnEvent().Subscribe(PlayVoiceSoundByReference).AddTo(disposables); GContext.OnEvent().Subscribe(OnChangeRodData).AddTo(disposables); GContext.OnEvent().Subscribe(OnSoundMute).AddTo(disposables); GContext.OnEvent().Subscribe(OnSoundStateEvent).AddTo(disposables); soundService.BGMVol = GContext.container.Resolve().Music ? 80 : 0; soundService.SFXVol = GContext.container.Resolve().Sound ? 80 : 0; soundService.VoiceVol = GContext.container.Resolve().Sound ? 80 : 0; } public void Release() { if (disposables != null) { disposables.Dispose(); disposables = null; } if (residentClip != null) { foreach (var item in residentClip) { if (item.Value != null) { Addressables.Release(item.Value); } } residentClip.Clear(); } if (rewardSoundDic != null) { rewardSoundDic.Clear(); } if (soundService != null) { foreach (var s in _activeFishingLoopSounds.ToList()) { if (s != null) { s.audioSource.Stop(); soundService.ReturnSound(s); } } } _activeFishingLoopSounds.Clear(); if (soundService != null) { soundService.Release(); } if (BGM_Clip != null) { Addressables.Release(BGM_Clip); BGM_Clip = null; } if (BGM_Sound != null && BGM_Sound.gameObject != null) { GameObject.Destroy(BGM_Sound.gameObject); BGM_Sound = null; } BGMName = null; } } public partial class ServiceSubject { public async Task InitAsync(string mixerAddr = "AudioMixer", string soundPrefabAddr = "sound", string bgmGroupId = "BGM", string fishingGroupId = "Fishing", string uiGroupId = "UI", string voiceGroupId = "Voice") { SoundFadeTaskDic = new Dictionary(); mixerHandle = Addressables.LoadAssetAsync(mixerAddr); mixer = await mixerHandle.Task; Assert.IsNotNull(mixer); mixer.GetFloat(Bgm_Vol_Param_Name, out bgmVol); mixer.GetFloat(Fishing_Vol_Param_Name, out fishingVol); bgmGroup = FindMixerGroup(bgmGroupId); fishingGroup = FindMixerGroup(fishingGroupId); uiGroup = FindMixerGroup(uiGroupId); voiceGroup = FindMixerGroup(voiceGroupId); normal = mixer.FindSnapshot("Snapshot");// ("normal"); //lowpass = mixer.FindSnapshot("lowpass"); Assert.IsNotNull(bgmGroup); Assert.IsNotNull(fishingGroup); Assert.IsNotNull(uiGroup); soundPrefabHandle = Addressables.LoadAssetAsync(soundPrefabAddr); var soundPrefab = await soundPrefabHandle.Task; Assert.IsNotNull(soundPrefab); var sound = soundPrefab.GetComponent(); Assert.IsNotNull(sound); lowpassEvtDisposable = GContext.OnEvent().Subscribe(OnLowpassEffectEvt); poolService.CreatePool(sound, 10, 50); } public void Release() { if (SoundFadeTaskDic != null) { foreach (var source in SoundFadeTaskDic.Values) { source.Cancel(); } SoundFadeTaskDic.Clear(); SoundFadeTaskDic = null; } poolService?.DestroyPool(); if (mixerHandle.IsValid()) Addressables.Release(mixerHandle); mixerHandle = default; if (soundPrefabHandle.IsValid()) Addressables.Release(soundPrefabHandle); soundPrefabHandle = default; lowpassEvtDisposable?.Dispose(); lowpassEvtDisposable = null; } }