-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameResources.cs
More file actions
63 lines (51 loc) · 1.79 KB
/
GameResources.cs
File metadata and controls
63 lines (51 loc) · 1.79 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
using System.Collections.Generic;
using CodeName.Modding.Localization;
using Cysharp.Threading.Tasks;
using Exanite.Core.Collections;
using Exanite.Core.Properties;
using UnityEngine;
namespace CodeName.Modding
{
public static class GameResources
{
private static LoadedGameInfo GameInfo { get; set; }
private static TwoWayDictionary<string, Object> Resources => GameInfo.Resources;
public static string LocaleCode = Constants.DefaultLocaleCode;
public static IReadOnlyDictionary<string, Object> ResourcesByKey => GameInfo.Resources;
public static Dictionary<string, List<LocalizationTable>> LocalizationTables => GameInfo.LocalizationTables;
public static Object GetResource(string key)
{
return Resources[key];
}
public static T GetResource<T>(PropertyDefinition<T> resourceDefinition) where T : Object
{
return (T)GetResource(resourceDefinition.Key);
}
public static bool TryGetResource(string key, out Object resource)
{
return Resources.TryGetValue(key, out resource);
}
public static string GetResourceKey(Object resource)
{
TryGetResourceKey(resource, out var key);
return key;
}
public static bool TryGetResourceKey(Object resource, out string key)
{
return Resources.Inverse.TryGetValue(resource, out key);
}
public static void Initialize(LoadedGameInfo gameInfo)
{
GameInfo = gameInfo;
}
public static async UniTask Unload()
{
if (GameInfo == null)
{
return;
}
await GameInfo.OriginalInfo.Unload(GameInfo);
GameInfo = null;
}
}
}