NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/Fight/ExtLogic/ExtLogicManager.cs

61 lines
1.4 KiB
C#

using System.Collections.Generic;
namespace Code.Scripts.Gameplay.Fight.ExtLogic
{
public class ExtLogicManager
{
private static ExtLogicManager _instance;
public static ExtLogicManager instance
{
get
{
if (_instance == null)
{
_instance = new ExtLogicManager();
}
return _instance;
}
}
private List<BaseExtLogic> _extLogics;
public void Init()
{
_extLogics = new List<BaseExtLogic>();
}
public void AddLogic(BaseExtLogic logic)
{
logic.Init();
_extLogics.Add(logic);
}
public void LogicUpdate(float dt)
{
for (int i = 0; i < _extLogics.Count; i++)
{
var extLogic = _extLogics[i];
extLogic.LogicUpdate(dt);
if (extLogic.needRemove)
{
extLogic.Dispose();
_extLogics.RemoveAt(i);
i--;
}
}
}
public void Dispose()
{
for (int i = 0; i < _extLogics.Count; i++)
{
var extLogic = _extLogics[i];
extLogic.Dispose();
}
_extLogics.Clear();
_extLogics = null;
}
}
}