-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogMonitorChannel.cs
More file actions
69 lines (57 loc) · 1.87 KB
/
LogMonitorChannel.cs
File metadata and controls
69 lines (57 loc) · 1.87 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace LogMonitor
{
[CreateAssetMenu(fileName = "LogMonitorChannel", menuName = "LogMonitorChannel", order = 0)]
public class LogMonitorChannel : ScriptableObject, ILogMonitor
{
private readonly Dictionary<string, LogMonitorMessage> _messages;
private int _lastFrame;
public LogMonitorChannel()
{
_messages = new Dictionary<string, LogMonitorMessage>();
}
public void Log(string key, object value, Component context = null)
{
Log(key, value, 0, context);
}
public void Log(string key, object value, double lifeTime, Component context = null)
{
_messages[key] = new LogMonitorMessage(Time.timeAsDouble)
{
Key = key,
Value = value,
Context = context,
LifeTimeInSeconds = lifeTime
};
}
public void Clear()
{
_messages.Clear();
}
public int MessageCount => _messages.Count;
public bool AnyMessages => _messages.Any();
public void Tick()
{
if (Time.frameCount == _lastFrame)
return;
_lastFrame = Time.frameCount;
for (int i = 0; i < _messages.Count; i++)
{
var keyValuePair = _messages.ElementAt(i);
var key = keyValuePair.Key;
var message = keyValuePair.Value;
if (message.Expired)
{
_messages.Remove(key);
i--;
}
}
}
public IEnumerable<LogMonitorMessage> GetMessages()
{
return _messages.Values.ToList();
}
}
}