NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/LegionBattle/LegionBattle.Map.cs

152 lines
5.2 KiB
C#
Raw Normal View History

2025-02-13 13:44:36 +08:00
using Cysharp.Threading.Tasks;
2025-03-17 17:52:27 +08:00
using Gameplay.Area;
using Gameplay.Area.Around;
using Gameplay.Area.BoardView;
using Gameplay.Common;
using Gameplay.Level;
2025-03-20 13:50:50 +08:00
using Gameplay.Story.Cmp.Anim;
2025-02-13 13:44:36 +08:00
using Gameplay.SubSystems;
2025-03-17 17:52:27 +08:00
using NLDPB;
2025-02-13 13:44:36 +08:00
using PhxhSDK;
using PhxhSDK.Res;
2025-03-17 15:51:39 +08:00
using System.Collections.Generic;
2025-02-13 13:44:36 +08:00
using UnityEngine;
namespace Gameplay.LegionBattle
{
public sealed partial class LegionBattle : IUpdatable, ILoadable
{
/// <summary>
/// 蓝方势力地板颜色
/// </summary>
2025-03-20 13:50:50 +08:00
private readonly Color CAMP_A_CELL_COLOR = new(0f, 0f, 1f, 0.05f);
/// <summary>
/// 红方势力地板颜色
/// </summary>
2025-03-20 13:50:50 +08:00
private readonly Color CAMP_B_CELL_COLOR = new(1f, 0f, 0f, 0.05f);
2025-02-13 13:44:36 +08:00
/// <summary>
/// 军团战地图
/// </summary>
public Map Map { get; private set; }
2025-03-17 15:51:39 +08:00
/// <summary>
/// 格子数据
/// </summary>
private Dictionary<Vector2Int, LegionBattleHexesData> dicHexesData;
2025-03-17 17:52:27 +08:00
/// <summary>
/// 所有格子
/// </summary>
private List<int> listAllCellIndex;
private List<BoardViewData> listBoardViewData;
public BoardLineObjPool boardLineObjPool = new();
2025-02-13 13:44:36 +08:00
/// <summary>
/// 两格之间的距离
/// </summary>
public float Distance { get; private set; }
2025-02-13 13:44:36 +08:00
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;
2025-03-20 16:32:22 +08:00
Map.TerrainGridSystem.cellBorderThickness = 0.04f;
Vector3 start = Map.TGSCellIndex2WorldPosition(0);
Vector3 end = Map.TGSCellIndex2WorldPosition(1);
Distance = (end - start).magnitude;
2025-03-17 15:51:39 +08:00
2025-03-17 17:52:27 +08:00
if (null == listAllCellIndex)
listAllCellIndex = new List<int>();
if (null == listBoardViewData)
listBoardViewData = new List<BoardViewData>();
2025-03-17 15:51:39 +08:00
if (null == dicHexesData)
dicHexesData = new Dictionary<Vector2Int, LegionBattleHexesData>();
foreach (TGS.Cell cell in Map.TerrainGridSystem.cells)
{
2025-03-17 17:52:27 +08:00
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);
2025-03-17 15:51:39 +08:00
}
2025-03-17 17:52:27 +08:00
await AssetManager.Instance.WaitAllPreloads();
boardLineObjPool.Init();
AroundHelper.Init(Map);
AreaManager.CreateInstance(Map);
//AreaManager.instance.Init();
2025-02-13 13:44:36 +08:00
}
2025-02-25 13:23:42 +08:00
/// <summary>
/// 更新地板颜色通过索引
/// </summary>
/// <param name="index"></param>
private void UpdateCellColorByIndex(LegionBattleHexesData hexesData)
{
switch (hexesData.Camp)
{
case BattlefieldActorCamp.CampA:
{
2025-03-20 13:50:50 +08:00
Map.SetBlockColor(hexesData.Index, true, CmpAnimGlobalSet.instance.LegionBattle_A_CELL_COLOR);
}
break;
case BattlefieldActorCamp.CampB:
{
2025-03-20 13:50:50 +08:00
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>
/// 更新建筑地板上的线
2025-02-25 13:23:42 +08:00
/// </summary>
/// <param name="cellIndex"></param>
private void UpdateCellLine()
2025-03-17 17:52:27 +08:00
{
/*foreach (BoardViewData boardViewData in listBoardViewData)
2025-03-17 17:52:27 +08:00
{
boardViewData.Destroy(Map.TerrainGridSystem);
}
listBoardViewData.Clear();
boardLineObjPool.ReturnAll();
2025-03-17 17:52:27 +08:00
BoardViewHelper.GenerateBoard(listAllCellIndex, listBoardViewData, Map.TerrainGridSystem);
for (int i = 0; i < listBoardViewData.Count; ++i)
{
listBoardViewData[i].CreateLegionBattleBoardSideView(Map.TerrainGridSystem, boardLineObjPool);
}*/
2025-02-25 13:23:42 +08:00
}
2025-03-24 17:09:05 +08:00
/// <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;
}
2025-02-13 13:44:36 +08:00
}
}