109 lines
2.9 KiB
C#
109 lines
2.9 KiB
C#
using System.Collections.Generic;
|
|
using Framework;
|
|
using Gameplay.Character;
|
|
using Gameplay.Unit;
|
|
using Gameplay.Unit.Data;
|
|
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;
|
|
_RegistEvents();
|
|
}
|
|
|
|
private void _RegistEvents()
|
|
{
|
|
EventManager.Instance.Register<GameUnit>(EventManager.EventName.INFIGHT_UNIT_CELLINDEX_CHANGE, _OnAnyCellIndexChange);
|
|
}
|
|
|
|
private void _UnRegistEvents()
|
|
{
|
|
EventManager.Instance.Unregister<GameUnit>(EventManager.EventName.INFIGHT_UNIT_CELLINDEX_CHANGE, _OnAnyCellIndexChange);
|
|
}
|
|
|
|
private void _OnAnyCellIndexChange(GameUnit unit)
|
|
{
|
|
_needUpdate = true;
|
|
}
|
|
|
|
private List<GameUnit> _FilterUnits()
|
|
{
|
|
var allUnits = GameUnitManager.instance.infightUnits.unitList;
|
|
var selectUnits = new List<GameUnit>();
|
|
for (int i = 0; i < allUnits.Count; i++)
|
|
{
|
|
var checkUnit = allUnits[i];
|
|
if (checkUnit.gameunitType is not (EGameUnitType.Character or EGameUnitType.Vehicle))
|
|
{
|
|
continue;
|
|
}
|
|
if (checkUnit.commonData.troopId != ETroopsId.Self)
|
|
{
|
|
continue;
|
|
}
|
|
if (checkUnit.statusData.isOnVehicle)
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_UnRegistEvents();
|
|
instance = null;
|
|
}
|
|
|
|
}
|
|
}
|