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 { /// /// 蓝方势力地板颜色 /// private readonly Color CAMP_A_CELL_COLOR = new(0f, 0f, 1f, 0.05f); /// /// 红方势力地板颜色 /// private readonly Color CAMP_B_CELL_COLOR = new(1f, 0f, 0f, 0.05f); /// /// 军团战地图 /// public Map Map { get; private set; } /// /// 格子数据 /// private Dictionary dicHexesData; /// /// 所有格子 /// private List listAllCellIndex; private List listBoardViewData; public BoardLineObjPool boardLineObjPool = new(); /// /// 两格之间的距离 /// 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(); if (null == listBoardViewData) listBoardViewData = new List(); if (null == dicHexesData) dicHexesData = new Dictionary(); 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(); } /// /// 更新地板颜色通过索引 /// /// 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; } } /// /// 更新建筑地板上的线 /// /// 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); }*/ } /// /// 获取地板阵营根据索引 /// /// /// public BattlefieldActorCamp GetCellCampByIndex(int index) { Vector2Int pos = Map.TGSCellIndex2BlockPosition(index); if (!dicHexesData.TryGetValue(pos, out LegionBattleHexesData hexesData)) return BattlefieldActorCamp.BacNone; return hexesData.Camp; } } }