Essentials + extra crap
Loadings Startups Movement Camera
This commit is contained in:
1 parent
662f4a1d05
commit
5f5ace1b52
734 files changed
+107323
-1713
No files matched your search
@@ -0,0 +1,46 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Code.Infrastructure.EventBus
|
||||
{
|
||||
internal class SubscribersList<TSubscriber> where TSubscriber : class
|
||||
{
|
||||
private bool m_NeedsCleanUp;
|
||||
|
||||
public bool Executing;
|
||||
|
||||
public readonly List<TSubscriber> List = new(); // TODO Weakptr
|
||||
|
||||
public void Add(TSubscriber subscriber)
|
||||
{
|
||||
List.Add(subscriber);
|
||||
}
|
||||
|
||||
public void Remove(TSubscriber subscriber)
|
||||
{
|
||||
if (Executing)
|
||||
{
|
||||
var i = List.IndexOf(subscriber);
|
||||
if (i >= 0)
|
||||
{
|
||||
m_NeedsCleanUp = true;
|
||||
List[i] = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
List.Remove(subscriber);
|
||||
}
|
||||
}
|
||||
|
||||
public void Cleanup()
|
||||
{
|
||||
if (!m_NeedsCleanUp)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
List.RemoveAll(s => s == null);
|
||||
m_NeedsCleanUp = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user