Skip to content

Commit 995618c

Browse files
authored
Create WaitForSecondsCache.cs
1 parent 09d4a53 commit 995618c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

WaitForSecondsCache.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// ReSharper disable InvertIf
2+
// ReSharper disable CheckNamespace
3+
// ReSharper disable InconsistentNaming
4+
5+
using UnityEngine;
6+
using System.Collections.Generic;
7+
8+
namespace AbyssMoth
9+
{
10+
public static class WaitForSecondsCache
11+
{
12+
private static readonly Dictionary<float, WaitForSeconds> cache = new();
13+
14+
public static IReadOnlyDictionary<float, WaitForSeconds> GetCache() => cache;
15+
16+
public static WaitForSeconds Get(float time)
17+
{
18+
if (!cache.TryGetValue(time, out var waitForSeconds))
19+
{
20+
waitForSeconds = new WaitForSeconds(time);
21+
cache[time] = waitForSeconds;
22+
23+
#if UNITY_EDITOR
24+
// NOTE: Exclusively for displaying the contents of the storage on the screen.
25+
// Dependency: MonoSingleton (https://github.com/RimuruDev/MonoSingleton.git)
26+
WaitForSecondsDebugView.Instance?.AddEntry(time);
27+
#endif
28+
}
29+
30+
return waitForSeconds;
31+
}
32+
33+
public static void Reset() => cache.Clear();
34+
}
35+
}

0 commit comments

Comments
 (0)