using asap.core; using cfg; using game; using Game; using GameCore; using System.Threading.Tasks; using UnityEngine; using UnityEngine.AddressableAssets; public class TravelMapCtrl { public TraveMapDataManager traveMapDataManager; Tables tables; GameObject _buildingObj; TravelMapCampReveiwPanel travelMapCampReveiw; int visitInidex = 0; TraveMapItemData traveMapItemData; public void Init(bool isVisit) { tables = GContext.container.Resolve(); traveMapDataManager = new TraveMapDataManager(); traveMapDataManager.Init(isVisit); } public async void InBuildAct() { ILoadResourceService loadResourceService = GContext.container.Resolve(); CampDataMM campData = GContext.container.Resolve(); bool isCanEnter = await loadResourceService.Loads(campData.AllPrefabs); if (isCanEnter) { InBuild(); } else { var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel); panel.GetComponent().SetBtn(true, InBuild); } } async void InBuild() { GContext.Publish(new UnloadActToNextAct("BuildAct")); await Awaiters.Seconds(0.5f); OnDestroy(); } public void OnLeft() { visitInidex--; InVisit(visitInidex); } public void OnRight() { visitInidex++; InVisit(visitInidex); } public async Task InVisit(int index) { visitInidex = index; if (visitInidex < 0) { visitInidex = traveMapDataManager.mapShowItemData.Count - 1; } if (visitInidex >= traveMapDataManager.mapShowItemData.Count) { visitInidex = 0; } traveMapItemData = traveMapDataManager.mapShowItemData[visitInidex]; ILoadResourceService loadResourceService = GContext.container.Resolve(); Construction mapData = tables.TbConstruction.Get(traveMapItemData.id); string prefabName = mapData.Prefab; bool isCanEnter = await loadResourceService.Load(prefabName); if (isCanEnter) { await InVisit(mapData); } else { var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel); panel.GetComponent().SetBtn(true, async () => await InVisit(mapData)); } } async Task InVisit(Construction mapData) { await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel); await Awaiters.Seconds(0.5f); if (_buildingObj != null) { Addressables.ReleaseInstance(_buildingObj); _buildingObj = null; } _buildingObj = await Addressables.InstantiateAsync(mapData.Prefab).Task; GContext.Publish(new EventBGMSound(mapData.BGM)); GContext.Publish(new EndTransition()); if (_buildingObj == null) { Debug.LogError($"TravelMapCtrl InVisit Error"); return; } var buildComp = _buildingObj.GetComponentInChildren(); if (buildComp != null) { buildComp.SetTimelineAllDone(); } else { Debug.LogError($"TravelMapCtrl InVisit Error"); } GContext.Publish(new SwitchVirtualCameraEvent() { type = 11, isDrag = true }); if (travelMapCampReveiw == null) { GameObject go = await UIManager.Instance.ShowUI(UITypes.TravelMapCampReveiwPanel); travelMapCampReveiw = go.GetComponent(); UIManager.Instance.DestroyUI(UITypes.TravelMapPanel); } travelMapCampReveiw.SetName(traveMapItemData.name); } public async void OutVisit() { visitInidex = 0; await UIManager.Instance.ShowUI(UITypes.TravelMapPanel); GContext.Publish(new EventMainBGM()); UIManager.Instance.DestroyUI(UITypes.TravelMapCampReveiwPanel); travelMapCampReveiw = null; if (_buildingObj != null) { Addressables.ReleaseInstance(_buildingObj); _buildingObj = null; } } public void OnDestroy() { UIManager.Instance.DestroyUI(UITypes.TravelMapPanel); RestartShowHomeUIEvent restartShowHomeUIEvent = new RestartShowHomeUIEvent(); GContext.Publish(restartShowHomeUIEvent); GContext.Publish(new MapShowEvent() { isShow = true }); traveMapDataManager = null; GContext.container.Unregister(); } }