备份CatanBuilding瘦身独立工程
This commit is contained in:
148
Assets/Scripts/TravelMap/TravelMapCtrl.cs
Normal file
148
Assets/Scripts/TravelMap/TravelMapCtrl.cs
Normal file
@@ -0,0 +1,148 @@
|
||||
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<Tables>();
|
||||
traveMapDataManager = new TraveMapDataManager();
|
||||
traveMapDataManager.Init(isVisit);
|
||||
}
|
||||
|
||||
public async void InBuildAct()
|
||||
{
|
||||
ILoadResourceService loadResourceService = GContext.container.Resolve<ILoadResourceService>();
|
||||
CampDataMM campData = GContext.container.Resolve<CampDataMM>();
|
||||
bool isCanEnter = await loadResourceService.Loads(campData.AllPrefabs);
|
||||
if (isCanEnter)
|
||||
{
|
||||
InBuild();
|
||||
}
|
||||
else
|
||||
{
|
||||
var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel);
|
||||
panel.GetComponent<CloudTransitionPanel>().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<ILoadResourceService>();
|
||||
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<CloudTransitionPanel>().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($"<color=red>TravelMapCtrl InVisit Error</color>");
|
||||
return;
|
||||
}
|
||||
|
||||
var buildComp = _buildingObj.GetComponentInChildren<Building>();
|
||||
if (buildComp != null)
|
||||
{
|
||||
buildComp.SetTimelineAllDone();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"<color=red>TravelMapCtrl InVisit Error</color>");
|
||||
}
|
||||
GContext.Publish(new SwitchVirtualCameraEvent() { type = 11, isDrag = true });
|
||||
if (travelMapCampReveiw == null)
|
||||
{
|
||||
GameObject go = await UIManager.Instance.ShowUI(UITypes.TravelMapCampReveiwPanel);
|
||||
travelMapCampReveiw = go.GetComponent<TravelMapCampReveiwPanel>();
|
||||
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<TravelMapCtrl>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user