84 lines
2.4 KiB
C#
84 lines
2.4 KiB
C#
using Gameplay.Camp.Fsm;
|
||
using LTGame;
|
||
using PhxhSDK;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using TGS;
|
||
using UnityEngine;
|
||
|
||
namespace Gameplay.Camp
|
||
{
|
||
/// <summary>
|
||
/// 营地
|
||
/// </summary>
|
||
public sealed class Camp
|
||
{
|
||
/// <summary>
|
||
/// 网格系统
|
||
/// </summary>
|
||
private TerrainGridSystem gridSystem;
|
||
/// <summary>
|
||
/// 所有Cell,key:Cell索引,value:Cell
|
||
/// </summary>
|
||
private Dictionary<int, Cell> dicCellByIndex;
|
||
/// <summary>
|
||
/// 所有Cell,key:Cell行列,Value:Cell
|
||
/// </summary>
|
||
private Dictionary<Vector2Int, Cell> dicCellByRowCol;
|
||
/// <summary>
|
||
/// 格子状态
|
||
/// </summary>
|
||
private Dictionary<Cell, E_CampCellState> dicCellState;
|
||
|
||
/// <summary>
|
||
/// 网格系统
|
||
/// </summary>
|
||
public TerrainGridSystem GridSystem
|
||
{
|
||
get { return gridSystem; }
|
||
}
|
||
|
||
public Camp(TerrainGridSystem terrainGridSystem)
|
||
{
|
||
gridSystem = terrainGridSystem;
|
||
|
||
dicCellByIndex = new Dictionary<int, Cell>();
|
||
dicCellByRowCol = new Dictionary<Vector2Int, Cell>();
|
||
dicCellState = new Dictionary<Cell, E_CampCellState>();
|
||
foreach (Cell cell in gridSystem.cells)
|
||
{
|
||
dicCellByIndex[cell.index] = cell;
|
||
dicCellByRowCol[new Vector2Int(cell.row, cell.column)] = cell;
|
||
dicCellState[cell] = E_CampCellState.Empty;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 尝试通过索引获取cell
|
||
/// </summary>
|
||
/// <param name="index"></param>
|
||
/// <param name="cell"></param>
|
||
/// <returns></returns>
|
||
public bool TryGetCellByIndex(int index, out Cell cell)
|
||
{
|
||
if (!dicCellByIndex.TryGetValue(index, out cell))
|
||
return false;
|
||
|
||
return null != cell;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 尝试通过行列索引获取cell
|
||
/// </summary>
|
||
/// <param name="index"></param>
|
||
/// <param name="cell"></param>
|
||
/// <returns></returns>
|
||
public bool TryGetCellByRowCol(Vector2Int rowAndCol, out Cell cell)
|
||
{
|
||
if (!dicCellByRowCol.TryGetValue(rowAndCol, out cell))
|
||
return false;
|
||
|
||
return null != cell;
|
||
}
|
||
}
|
||
} |