-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHall.cs
More file actions
52 lines (43 loc) · 1.4 KB
/
Hall.cs
File metadata and controls
52 lines (43 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
namespace LLM.Visitors.Base
{
public abstract class Hall : IHall
{
protected HashSet<IVisitor> visitors;
protected int tickrate;
public Hall(int tickrateMiliseconds) => tickrate = tickrateMiliseconds;
public async virtual UniTask CheckVisitors()
{
foreach (var visitor in visitors)
{
await UniTask.Delay(tickrate);
visitor.OnTick();
}
}
public void Enter(IVisitor visitor)
{
visitors.Add(visitor);
OnVisitorCame(visitor);
}
public void Remove(IVisitor visitor)
{
if(!visitors.Contains(visitor)) return;
visitors.Remove(visitor);
OnVisitorLeft(visitor);
}
public void Remove<TVisitor>(bool removeAll = true)
where TVisitor : IVisitor
{
foreach (var visitor in visitors)
{
if(visitor.GetType() != typeof(TVisitor)) continue;
visitors.Remove(visitor);
OnVisitorLeft(visitor);
if(!removeAll) return;
}
}
public virtual void OnVisitorLeft(IVisitor visitor) => visitor.OnVisitorEnter();
public virtual void OnVisitorCame(IVisitor visitor) => visitor.OnVisitorLeave();
}
}