96 lines
3.5 KiB
C#
96 lines
3.5 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using Gameplay.SubSystems;
|
|
using PhxhSDK;
|
|
using PhxhSDK.Res;
|
|
using UnityEngine;
|
|
|
|
namespace Gameplay.LegionBattle
|
|
{
|
|
public sealed partial class LegionBattle : IUpdatable, ILoadable
|
|
{
|
|
/// <summary>
|
|
/// 军团战地图
|
|
/// </summary>
|
|
public Map Map { get; private set; }
|
|
|
|
/// <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;
|
|
Vector3 start = Map.TGSCellIndex2WorldPosition(0);
|
|
Vector3 end = Map.TGSCellIndex2WorldPosition(1);
|
|
Distance = (end - start).magnitude;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新建筑地板
|
|
/// </summary>
|
|
/// <param name="cellIndex"></param>
|
|
private void UpdateBuildingCell(int cellIndex)
|
|
{
|
|
if (!TryGetBuildingDataByIndex(cellIndex, out LegionBuildingData buildingData))
|
|
return;
|
|
|
|
switch (buildingData.CurCamp)
|
|
{
|
|
case NLDPB.BattlefieldActorCamp.CampA:
|
|
{
|
|
Color color = new(0f, 0f, 1f, 0.5f);
|
|
|
|
foreach (int index in buildingData.SetRange)
|
|
{
|
|
if (buildingData.SetAllIndex.Contains(index)) // TODO 占领格子临时刷成不透明
|
|
{
|
|
Map.SetBlockColor(index, true, new Color(color.r, color.g, color.b, 1f));
|
|
continue;
|
|
}
|
|
|
|
Map.SetBlockColor(index, true, color); // 范围格子
|
|
}
|
|
}
|
|
break;
|
|
case NLDPB.BattlefieldActorCamp.CampB:
|
|
{
|
|
Color color = new(1f, 0f, 0f, 0.5f);
|
|
|
|
foreach (int index in buildingData.SetRange)
|
|
{
|
|
if (buildingData.SetAllIndex.Contains(index)) // TODO 占领格子临时刷成不透明
|
|
{
|
|
Map.SetBlockColor(index, true, new Color(color.r, color.g, color.b, 1f));
|
|
continue;
|
|
}
|
|
|
|
Map.SetBlockColor(index, true, color); // 范围格子
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
{
|
|
foreach (int index in buildingData.SetRange)
|
|
{
|
|
if (buildingData.SetAllIndex.Contains(index)) // TODO 占领格子临时刷成不透明
|
|
{
|
|
Map.SetBlockColor(index, true, Color.white);
|
|
continue;
|
|
}
|
|
|
|
Map.SetBlockColor(index, false, Color.white); // 范围格子
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
} |