148 lines
3.8 KiB
C#
148 lines
3.8 KiB
C#
using cfg.LegionBattleCfg;
|
|
using Cysharp.Threading.Tasks;
|
|
using Framework;
|
|
using Gameplay.Common;
|
|
using Gameplay.SubSystems;
|
|
using LTGame;
|
|
using PhxhSDK;
|
|
using UnityEngine;
|
|
|
|
namespace Gameplay.LegionBattle
|
|
{
|
|
public sealed partial class LegionBattle : IUpdatable, ILoadable
|
|
{
|
|
/// <summary>
|
|
/// 军团战状态
|
|
/// </summary>
|
|
private NStateMachine<BaseLegionBattleState> fsm;
|
|
|
|
/// <summary>
|
|
/// 加载完成
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool IsLoadComplete { get; private set; }
|
|
|
|
public LegionBattle()
|
|
{
|
|
fsm = new();
|
|
|
|
fsm.Add(new LegionBattleStatePrepare(this));
|
|
fsm.Add(new LegionBattleStateBattle(this));
|
|
fsm.Add(new LegionBattleStateOver(this));
|
|
|
|
IsLoadComplete = false;
|
|
}
|
|
|
|
public LegionBattle(int mapId)
|
|
{
|
|
fsm = new();
|
|
|
|
fsm.Add(new LegionBattleStateInspect(this));
|
|
|
|
foreach (DataLegionBattleMap dataLegionBattleMap in TableManager.Instance.Tables.LegionBattleMap.DataList)
|
|
{
|
|
if (dataLegionBattleMap.ID == mapId)
|
|
{
|
|
MapCfg = dataLegionBattleMap;
|
|
break;
|
|
}
|
|
}
|
|
|
|
IsLoadComplete = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 加载军团战
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async UniTask Load()
|
|
{
|
|
AssetManager.Instance.PostPreload(PathDefine.RoadLine.ROAD_LINE_STRAIGHT);
|
|
|
|
await LoadMap(); // 加载地图
|
|
await LoadLevelData(); // 加载关卡数据
|
|
|
|
await AssetManager.Instance.WaitAllPreloads();
|
|
|
|
await LoadActor(); // 加载玩家
|
|
|
|
IsLoadComplete = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 加载军团战查看地图
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async UniTask LoadInspect()
|
|
{
|
|
await LoadMap(); // 加载地图
|
|
await LoadLevelData(); // 加载关卡数据
|
|
|
|
IsLoadComplete = true;
|
|
}
|
|
|
|
public void Update(float deltaTime)
|
|
{
|
|
fsm.LogicUpdate(deltaTime);
|
|
}
|
|
|
|
public async UniTask Unload()
|
|
{
|
|
CameraManager.Instance.RevertMainCamera();
|
|
MapUtils.UnLoadMap(Map);
|
|
|
|
ClearInfo();
|
|
|
|
await GameSceneManager.Instance.UnLoadSceneAsync(MapCfg.Path);
|
|
AssetManager.Instance.Unload(PathDefine.RoadLine.ROAD_LINE_STRAIGHT);
|
|
}
|
|
|
|
public void Release()
|
|
{
|
|
fsm.Exit();
|
|
fsm = null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 进入军团战查看地图
|
|
/// </summary>
|
|
public void EnterLegionBattleInspect()
|
|
{
|
|
fsm.SetForceChangeState((int)E_LegionBattleState.Inspect);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 进入军团战
|
|
/// </summary>
|
|
public void EnterLegionBattle()
|
|
{
|
|
//fsm.SetForceChangeState((int)E_LegionBattleState.Prepare);
|
|
BeginLegionBattle();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 开始军团战
|
|
/// </summary>
|
|
public void BeginLegionBattle()
|
|
{
|
|
fsm.SetForceChangeState((int)E_LegionBattleState.Battle);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 结束军团战
|
|
/// </summary>
|
|
public void EndLegionBattle(LegionSettleData legionSettleData)
|
|
{
|
|
fsm.SetForceChangeState((int)E_LegionBattleState.Over, legionSettleData);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 点击屏幕
|
|
/// </summary>
|
|
/// <param name="screenPos"></param>
|
|
public void ClickFromScreen(Vector2 screenPos)
|
|
{
|
|
fsm.currentState?.ClickFromScreen(screenPos);
|
|
}
|
|
}
|
|
} |