152 lines
5.2 KiB
C#
152 lines
5.2 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using Gameplay.Area;
|
|
using Gameplay.Area.Around;
|
|
using Gameplay.Area.BoardView;
|
|
using Gameplay.Common;
|
|
using Gameplay.Level;
|
|
using Gameplay.Story.Cmp.Anim;
|
|
using Gameplay.SubSystems;
|
|
using NLDPB;
|
|
using PhxhSDK;
|
|
using PhxhSDK.Res;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Gameplay.LegionBattle
|
|
{
|
|
public sealed partial class LegionBattle : IUpdatable, ILoadable
|
|
{
|
|
/// <summary>
|
|
/// 蓝方势力地板颜色
|
|
/// </summary>
|
|
private readonly Color CAMP_A_CELL_COLOR = new(0f, 0f, 1f, 0.05f);
|
|
/// <summary>
|
|
/// 红方势力地板颜色
|
|
/// </summary>
|
|
private readonly Color CAMP_B_CELL_COLOR = new(1f, 0f, 0f, 0.05f);
|
|
|
|
/// <summary>
|
|
/// 军团战地图
|
|
/// </summary>
|
|
public Map Map { get; private set; }
|
|
/// <summary>
|
|
/// 格子数据
|
|
/// </summary>
|
|
private Dictionary<Vector2Int, LegionBattleHexesData> dicHexesData;
|
|
/// <summary>
|
|
/// 所有格子
|
|
/// </summary>
|
|
private List<int> listAllCellIndex;
|
|
private List<BoardViewData> listBoardViewData;
|
|
public BoardLineObjPool boardLineObjPool = new();
|
|
|
|
/// <summary>
|
|
/// 两格之间的距离
|
|
/// </summary>
|
|
public float Distance { get; private set; }
|
|
|
|
public async UniTask LoadMap()
|
|
{
|
|
SceneHandle sceneHandle = await GameSceneManager.Instance.LoadSceneAsync(MapCfg.Path);
|
|
MapData mapData = await MapUtils.LoadMapData(MapCfg.MapData); // 加载地图数据
|
|
Map = await MapUtils.LoadMap(mapData); // 加载地图
|
|
|
|
Camera camera = sceneHandle.Camera;
|
|
CameraManager.Instance.SwitchMainCamera(camera);
|
|
MapUtils.BindCameraController(camera, Map);
|
|
Map.TerrainGridSystem.showCells = true;
|
|
Map.TerrainGridSystem.cellBorderThickness = 0.04f;
|
|
Vector3 start = Map.TGSCellIndex2WorldPosition(0);
|
|
Vector3 end = Map.TGSCellIndex2WorldPosition(1);
|
|
Distance = (end - start).magnitude;
|
|
|
|
if (null == listAllCellIndex)
|
|
listAllCellIndex = new List<int>();
|
|
|
|
if (null == listBoardViewData)
|
|
listBoardViewData = new List<BoardViewData>();
|
|
|
|
if (null == dicHexesData)
|
|
dicHexesData = new Dictionary<Vector2Int, LegionBattleHexesData>();
|
|
|
|
foreach (TGS.Cell cell in Map.TerrainGridSystem.cells)
|
|
{
|
|
listAllCellIndex.Add(cell.index);
|
|
dicHexesData.Add(Map.TGSCellIndex2BlockPosition(cell.index), new LegionBattleHexesData(cell.index));
|
|
}
|
|
|
|
for (int i = 0; i < 6; i++)
|
|
{
|
|
var sidePath = PathDefine.BoardSide.SIDE_PATHS[i];
|
|
AssetManager.Instance.PostPreload(sidePath);
|
|
}
|
|
|
|
await AssetManager.Instance.WaitAllPreloads();
|
|
boardLineObjPool.Init();
|
|
AroundHelper.Init(Map);
|
|
AreaManager.CreateInstance(Map);
|
|
//AreaManager.instance.Init();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新地板颜色通过索引
|
|
/// </summary>
|
|
/// <param name="index"></param>
|
|
private void UpdateCellColorByIndex(LegionBattleHexesData hexesData)
|
|
{
|
|
switch (hexesData.Camp)
|
|
{
|
|
case BattlefieldActorCamp.CampA:
|
|
{
|
|
Map.SetBlockColor(hexesData.Index, true, CmpAnimGlobalSet.instance.LegionBattle_A_CELL_COLOR);
|
|
}
|
|
break;
|
|
case BattlefieldActorCamp.CampB:
|
|
{
|
|
Map.SetBlockColor(hexesData.Index, true, CmpAnimGlobalSet.instance.LegionBattle_B_CELL_COLOR);
|
|
}
|
|
break;
|
|
default:
|
|
{
|
|
Map.SetBlockColor(hexesData.Index, true, new Color(0f, 0f, 0f, 0f));
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新建筑地板上的线
|
|
/// </summary>
|
|
/// <param name="cellIndex"></param>
|
|
private void UpdateCellLine()
|
|
{
|
|
/*foreach (BoardViewData boardViewData in listBoardViewData)
|
|
{
|
|
boardViewData.Destroy(Map.TerrainGridSystem);
|
|
}
|
|
listBoardViewData.Clear();
|
|
boardLineObjPool.ReturnAll();
|
|
|
|
BoardViewHelper.GenerateBoard(listAllCellIndex, listBoardViewData, Map.TerrainGridSystem);
|
|
for (int i = 0; i < listBoardViewData.Count; ++i)
|
|
{
|
|
listBoardViewData[i].CreateLegionBattleBoardSideView(Map.TerrainGridSystem, boardLineObjPool);
|
|
}*/
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取地板阵营根据索引
|
|
/// </summary>
|
|
/// <param name="index"></param>
|
|
/// <returns></returns>
|
|
public BattlefieldActorCamp GetCellCampByIndex(int index)
|
|
{
|
|
Vector2Int pos = Map.TGSCellIndex2BlockPosition(index);
|
|
|
|
if (!dicHexesData.TryGetValue(pos, out LegionBattleHexesData hexesData))
|
|
return BattlefieldActorCamp.BacNone;
|
|
|
|
return hexesData.Camp;
|
|
}
|
|
}
|
|
} |