40 lines
958 B
C#
40 lines
958 B
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
|
||
|
using Syntriax.Engine.Core.Abstract;
|
||
|
|
||
|
namespace Syntriax.Engine.Core;
|
||
|
|
||
|
public class CoroutineManager : HierarchyObjectBase
|
||
|
{
|
||
|
public List<IEnumerator> enumerators = [];
|
||
|
|
||
|
public IEnumerator CreateCoroutine(IEnumerator enumerator)
|
||
|
{
|
||
|
enumerators.Add(enumerator);
|
||
|
return enumerator;
|
||
|
}
|
||
|
|
||
|
public void StopCoroutine(IEnumerator enumerator)
|
||
|
{
|
||
|
enumerators.Remove(enumerator);
|
||
|
}
|
||
|
|
||
|
protected override void OnEnteringHierarchy(IGameManager gameManager)
|
||
|
{
|
||
|
gameManager.OnUpdate += OnUpdate;
|
||
|
}
|
||
|
|
||
|
protected override void OnExitingHierarchy(IGameManager gameManager)
|
||
|
{
|
||
|
gameManager.OnUpdate -= OnUpdate;
|
||
|
}
|
||
|
|
||
|
private void OnUpdate(IGameManager sender, EngineTime time)
|
||
|
{
|
||
|
for (int i = enumerators.Count - 1; i >= 0; i--)
|
||
|
if (!enumerators[i].MoveNext())
|
||
|
enumerators.RemoveAt(i);
|
||
|
}
|
||
|
}
|