146 lines
4.1 KiB
C#
146 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;
|
|
_RegistEvents();
|
|
_InitCaptureAreas();
|
|
}
|
|
|
|
private void _InitCaptureAreas()
|
|
{
|
|
var levelData = LevelManager.Instance.CurrentLevel.GetLevelData();
|
|
var map = LevelManager.Instance.CurrentLevel.Map;
|
|
var captureProgress = levelData.captureProgress;
|
|
|
|
var captureList = map.MapData.capturePoints;
|
|
for (int i = 0; i < captureList.Count; i++)
|
|
{
|
|
var cellIndex = captureList[i];
|
|
_AddCaptureInst(cellIndex, captureProgress);
|
|
}
|
|
|
|
}
|
|
|
|
private void _AddCaptureInst(int cellIndex,
|
|
int captureValue)
|
|
{
|
|
var newInst = new CaptureInst(cellIndex, captureValue);
|
|
captureInsts.Add(newInst);
|
|
}
|
|
|
|
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);
|
|
// if (captureInst.isCaptured)
|
|
// {
|
|
// captureInst.Dispose();
|
|
// captureInsts.RemoveAt(i);
|
|
// i--;
|
|
// }
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_UnRegistEvents();
|
|
for (int i = 0; i < captureInsts.Count; i++)
|
|
{
|
|
var captureInst = captureInsts[i];
|
|
captureInst.Dispose();
|
|
}
|
|
captureInsts.Clear();
|
|
instance = null;
|
|
}
|
|
|
|
}
|
|
}
|