85 lines
3.6 KiB
C#
85 lines
3.6 KiB
C#
using System.Collections.Generic;
|
|
using Gameplay.Level;
|
|
using UnityEngine;
|
|
namespace Gameplay.Area.BoardView
|
|
{
|
|
public class BoardViewHelper
|
|
{
|
|
|
|
private static List<int> _cacheCellIndexList = new List<int>();
|
|
|
|
private static readonly int Prop_HintColor1 = Shader.PropertyToID("_Color");
|
|
private static readonly int Prop_HintColor2 = Shader.PropertyToID("_SecondColor");
|
|
|
|
public static List<BoardViewData> GenerateBoard(List<int> cellIndexList, Color hintColor1, Color hintColor2)
|
|
{
|
|
_cacheCellIndexList.Clear();
|
|
_cacheCellIndexList.AddRange(cellIndexList);
|
|
var result = new List<BoardViewData>();
|
|
|
|
var tgsSystem = LevelManager.Instance.CurrentLevel.Map.TerrainGridSystem;
|
|
BoardViewData workViewData = null;
|
|
List<int> workCellIndexList = new List<int>();
|
|
List<int> nextWorkCellIndexList = new List<int>();
|
|
while (_cacheCellIndexList.Count > 0)
|
|
{
|
|
if (workViewData == null)
|
|
{
|
|
workCellIndexList.Clear();
|
|
var workCellIndex = _cacheCellIndexList[^1];
|
|
_cacheCellIndexList.RemoveAt(_cacheCellIndexList.Count - 1);
|
|
workViewData = new BoardViewData();
|
|
workViewData.cellIndexList.Add(workCellIndex);
|
|
result.Add(workViewData);
|
|
workCellIndexList.Add(workCellIndex);
|
|
}
|
|
else
|
|
{
|
|
nextWorkCellIndexList.Clear();
|
|
for (int j = 0; j < workCellIndexList.Count; j++)
|
|
{
|
|
var workCellIndex = workCellIndexList[j];
|
|
var aroundCell = tgsSystem.CellGetNeighbours(workCellIndex);
|
|
for (int i = 0; i < aroundCell.Count; i++)
|
|
{
|
|
var cell = aroundCell[i];
|
|
var findIndex = _cacheCellIndexList.IndexOf(cell.index);
|
|
if (findIndex == -1)
|
|
{
|
|
continue;
|
|
}
|
|
workViewData.cellIndexList.Add(cell.index);
|
|
// fast remove
|
|
_cacheCellIndexList[findIndex] = _cacheCellIndexList[^1];
|
|
_cacheCellIndexList.RemoveAt(_cacheCellIndexList.Count - 1);
|
|
nextWorkCellIndexList.Add(cell.index);
|
|
}
|
|
}
|
|
if (nextWorkCellIndexList.Count == 0)
|
|
{
|
|
workViewData = null;
|
|
}
|
|
else
|
|
{
|
|
// switch work list
|
|
workCellIndexList.Clear();
|
|
workCellIndexList.AddRange(nextWorkCellIndexList);
|
|
}
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < result.Count; i++)
|
|
{
|
|
var viewData = result[i];
|
|
viewData.tgsTerritory = tgsSystem.TerritoryCreate(viewData.cellIndexList);
|
|
viewData.borderObj = tgsSystem.ForceDrawTerritoryDrawInteriorBorder(viewData.tgsTerritory, 0, 1, hintColor1, hintColor2);
|
|
var getMaterial = viewData.borderObj.transform.GetChild(0).GetComponent<MeshRenderer>().material;
|
|
getMaterial.SetColor(Prop_HintColor1, hintColor1);
|
|
getMaterial.SetColor(Prop_HintColor2, hintColor2);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|