121 lines
3.4 KiB
C#
121 lines
3.4 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
namespace Gameplay.LegionBattle.View
|
|
{
|
|
public class FightLineArea
|
|
{
|
|
public List<FightLineCell> cellList = new List<FightLineCell>(1600);
|
|
|
|
public bool isMainArea = false;
|
|
|
|
public FightLine finalLine = new FightLine();
|
|
|
|
public void AddCell(FightLineCell cell)
|
|
{
|
|
cellList.Add(cell);
|
|
if (cell.isMainCell)
|
|
{
|
|
isMainArea = true;
|
|
}
|
|
}
|
|
|
|
public void ResetArea(FightLineArea newArea)
|
|
{
|
|
cellList.Clear();
|
|
cellList.AddRange(newArea.cellList);
|
|
}
|
|
|
|
public void ReverseArea()
|
|
{
|
|
for (int i = 0; i < cellList.Count; i++)
|
|
{
|
|
var cell = cellList[i];
|
|
if (cell.standValue == -1)
|
|
{
|
|
cell.standValue = 1;
|
|
} else if (cell.standValue == 1)
|
|
{
|
|
cell.standValue = -1;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void AddArea(FightLineArea area)
|
|
{
|
|
cellList.AddRange(area.cellList);
|
|
}
|
|
|
|
public void CalcBoarder()
|
|
{
|
|
// 计算边界的cells
|
|
for (int i = 0; i < cellList.Count; i++)
|
|
{
|
|
var cell = cellList[i];
|
|
if (cell.CheckIsCenter())
|
|
{
|
|
cellList.RemoveAt(i);
|
|
i--;
|
|
}
|
|
cell.CalcBoardPos();
|
|
cell.isVisited = false;
|
|
}
|
|
}
|
|
|
|
public void ReSortBoardCells()
|
|
{
|
|
_ReSortCells();
|
|
}
|
|
|
|
private void _ReSortCells()
|
|
{
|
|
finalLine.Clear();
|
|
var workCell = cellList[^1];
|
|
cellList.RemoveAt(cellList.Count - 1);
|
|
finalLine.AddCell(workCell);
|
|
|
|
var searchNext = finalLine.SearchNext(cellList, out int outIndex);
|
|
while (searchNext != null)
|
|
{
|
|
cellList.RemoveAt(outIndex);
|
|
finalLine.AddCell(searchNext);
|
|
searchNext = finalLine.SearchNext(cellList, out outIndex);
|
|
}
|
|
}
|
|
|
|
private List<GameObject> _boardObjs = new List<GameObject>();
|
|
public void CreateBoardView(GameObject sampleObj, Transform parent)
|
|
{
|
|
// 先匹配个数
|
|
if (_boardObjs.Count != cellList.Count)
|
|
{
|
|
if (_boardObjs.Count > cellList.Count)
|
|
{
|
|
// 删除多余的
|
|
for (int i = _boardObjs.Count - 1; i >= cellList.Count; i--)
|
|
{
|
|
var obj = _boardObjs[i];
|
|
Object.Destroy(obj);
|
|
_boardObjs.RemoveAt(i);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// 补充
|
|
for (int i = _boardObjs.Count; i < cellList.Count; i++)
|
|
{
|
|
var obj = Object.Instantiate(sampleObj, parent);
|
|
_boardObjs.Add(obj);
|
|
}
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < cellList.Count; i++)
|
|
{
|
|
var cell = cellList[i];
|
|
var obj = _boardObjs[i];
|
|
obj.transform.localPosition = new Vector3(cell.pos.x, cell.pos.y, 0);
|
|
}
|
|
}
|
|
}
|
|
}
|