148 lines
4.1 KiB
C#
148 lines
4.1 KiB
C#
using System.Collections.Generic;
|
|
using Framework;
|
|
using Gameplay.Character;
|
|
using Gameplay.Level;
|
|
using Gameplay.Unit;
|
|
using Gameplay.Unit.Data;
|
|
using UnityEngine;
|
|
namespace Gameplay.Fight.Capture
|
|
{
|
|
/// <summary>
|
|
/// 用于管理战场内的所有占领点
|
|
/// 仅在战场内使用
|
|
/// </summary>
|
|
public class CaptureManager
|
|
{
|
|
|
|
public List<CaptureInst> captureInsts = new List<CaptureInst>();
|
|
|
|
private bool _needUpdate;
|
|
|
|
public static CaptureManager instance { get; private set; }
|
|
|
|
public static void CreateInstance()
|
|
{
|
|
instance = new CaptureManager();
|
|
}
|
|
|
|
private CaptureManager()
|
|
{
|
|
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
_needUpdate = true;
|
|
_RegisterEvents();
|
|
_InitCaptureAreas();
|
|
}
|
|
|
|
private void _InitCaptureAreas()
|
|
{
|
|
var levelData = LevelManager.Instance.CurrentLevel.GetLevelData();
|
|
var captureProgress = levelData.CapturePoints;
|
|
|
|
foreach (var captureInfo in captureProgress)
|
|
{
|
|
_AddCaptureInst(captureInfo.CapturePoint, captureInfo.CaptureProgress);
|
|
}
|
|
}
|
|
|
|
private void _AddCaptureInst(int cellIndex,
|
|
int captureValue)
|
|
{
|
|
var newInst = new CaptureInst(cellIndex, captureValue);
|
|
captureInsts.Add(newInst);
|
|
}
|
|
|
|
private void _RegisterEvents()
|
|
{
|
|
EventManager.Instance.Register<GameUnit>(EventManager.EventName.INFIGHT_UNIT_CELLINDEX_CHANGE, _OnAnyCellIndexChange);
|
|
}
|
|
|
|
private void _UnRegisterEvents()
|
|
{
|
|
EventManager.Instance.Unregister<GameUnit>(EventManager.EventName.INFIGHT_UNIT_CELLINDEX_CHANGE, _OnAnyCellIndexChange);
|
|
}
|
|
|
|
private void _OnAnyCellIndexChange(GameUnit unit)
|
|
{
|
|
_needUpdate = true;
|
|
}
|
|
|
|
private List<GameUnit> _cacheSelectUnits = new List<GameUnit>(10);
|
|
private List<GameUnit> _FilterUnits()
|
|
{
|
|
var allUnits = GameUnitManager.instance.infightUnits.unitList;
|
|
var selectUnits = _cacheSelectUnits;
|
|
selectUnits.Clear();
|
|
for (int i = 0; i < allUnits.Count; i++)
|
|
{
|
|
var checkUnit = allUnits[i];
|
|
if (!checkUnit.commonData.canControl)
|
|
{
|
|
continue;
|
|
}
|
|
if (checkUnit.gameunitType is not (EGameUnitType.Character or EGameUnitType.Vehicle))
|
|
{
|
|
continue;
|
|
}
|
|
if (checkUnit.commonData.troopId != ETroopsId.Self)
|
|
{
|
|
continue;
|
|
}
|
|
if (!checkUnit.statusData.isOnFloor)
|
|
{
|
|
continue;
|
|
}
|
|
if (checkUnit.statusData.isDead)
|
|
{
|
|
continue;
|
|
}
|
|
selectUnits.Add(checkUnit);
|
|
}
|
|
return selectUnits;
|
|
}
|
|
|
|
public void LogicUpdate(float dt)
|
|
{
|
|
|
|
if (_needUpdate)
|
|
{
|
|
var checkUnits = _FilterUnits();
|
|
for (int i = 0; i < captureInsts.Count; i++)
|
|
{
|
|
var captureInst = captureInsts[i];
|
|
captureInst.UpdateInAreaUnits(checkUnits);
|
|
}
|
|
_needUpdate = false;
|
|
}
|
|
|
|
for (int i = 0; i < captureInsts.Count; i++)
|
|
{
|
|
var captureInst = captureInsts[i];
|
|
captureInst.LogicUpdate(dt);
|
|
// if (captureInst.isCaptured)
|
|
// {
|
|
// captureInst.Dispose();
|
|
// captureInsts.RemoveAt(i);
|
|
// i--;
|
|
// }
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_UnRegisterEvents();
|
|
for (int i = 0; i < captureInsts.Count; i++)
|
|
{
|
|
var captureInst = captureInsts[i];
|
|
captureInst.Dispose();
|
|
}
|
|
captureInsts.Clear();
|
|
instance = null;
|
|
}
|
|
|
|
}
|
|
}
|