-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWaitForSecondsCache.cs
35 lines (28 loc) · 1.03 KB
/
WaitForSecondsCache.cs
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
// ReSharper disable InvertIf
// ReSharper disable CheckNamespace
// ReSharper disable InconsistentNaming
using UnityEngine;
using System.Collections.Generic;
namespace AbyssMoth
{
public static class WaitForSecondsCache
{
private static readonly Dictionary<float, WaitForSeconds> cache = new();
public static IReadOnlyDictionary<float, WaitForSeconds> GetCache() => cache;
public static WaitForSeconds Get(float time)
{
if (!cache.TryGetValue(time, out var waitForSeconds))
{
waitForSeconds = new WaitForSeconds(time);
cache[time] = waitForSeconds;
#if UNITY_EDITOR
// NOTE: Exclusively for displaying the contents of the storage on the screen.
// Dependency: MonoSingleton (https://github.com/RimuruDev/MonoSingleton.git)
WaitForSecondsDebugView.Instance?.AddEntry(time);
#endif
}
return waitForSeconds;
}
public static void Reset() => cache.Clear();
}
}