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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace I2.Loc;
public class ResourceManager : MonoBehaviour
{
private static ResourceManager mInstance;
public List<IResourceManager_Bundles> mBundleManagers = new List<IResourceManager_Bundles>();
public UnityEngine.Object[] Assets;
private readonly Dictionary<string, UnityEngine.Object> mResourcesCache = new Dictionary<string, UnityEngine.Object>(StringComparer.Ordinal);
public static ResourceManager pInstance
{
get
{
bool flag = mInstance == null;
if (mInstance == null)
{
mInstance = (ResourceManager)UnityEngine.Object.FindObjectOfType(typeof(ResourceManager));
}
if (mInstance == null)
{
GameObject obj = new GameObject("I2ResourceManager", typeof(ResourceManager));
obj.hideFlags |= HideFlags.HideAndDontSave;
mInstance = obj.GetComponent<ResourceManager>();
SceneManager.sceneLoaded += MyOnLevelWasLoaded;
}
if (flag && Application.isPlaying)
{
UnityEngine.Object.DontDestroyOnLoad(mInstance.gameObject);
}
return mInstance;
}
}
public static void MyOnLevelWasLoaded(Scene scene, LoadSceneMode mode)
{
pInstance.CleanResourceCache();
LocalizationManager.UpdateSources();
}
public T GetAsset<T>(string Name) where T : UnityEngine.Object
{
T val = FindAsset(Name) as T;
if ((UnityEngine.Object)val != (UnityEngine.Object)null)
{
return val;
}
return LoadFromResources<T>(Name);
}
private UnityEngine.Object FindAsset(string Name)
{
if (Assets != null)
{
int i = 0;
for (int num = Assets.Length; i < num; i++)
{
if (Assets[i] != null && Assets[i].name == Name)
{
return Assets[i];
}
}
}
return null;
}
public bool HasAsset(UnityEngine.Object Obj)
{
if (Assets == null)
{
return false;
}
return Array.IndexOf(Assets, Obj) >= 0;
}
public T LoadFromResources<T>(string Path) where T : UnityEngine.Object
{
try
{
if (string.IsNullOrEmpty(Path))
{
return null;
}
if (mResourcesCache.TryGetValue(Path, out var value) && value != null)
{
return value as T;
}
T val = null;
if (Path.EndsWith("]", StringComparison.OrdinalIgnoreCase))
{
int num = Path.LastIndexOf("[", StringComparison.OrdinalIgnoreCase);
int length = Path.Length - num - 2;
string value2 = Path.Substring(num + 1, length);
Path = Path.Substring(0, num);
T[] array = Resources.LoadAll<T>(Path);
int i = 0;
for (int num2 = array.Length; i < num2; i++)
{
if (array[i].name.Equals(value2))
{
val = array[i];
break;
}
}
}
else
{
val = Resources.Load(Path, typeof(T)) as T;
}
if ((UnityEngine.Object)val == (UnityEngine.Object)null)
{
val = LoadFromBundle<T>(Path);
}
if ((UnityEngine.Object)val != (UnityEngine.Object)null)
{
mResourcesCache[Path] = val;
}
return val;
}
catch (Exception ex)
{
Debug.LogErrorFormat("Unable to load {0} '{1}'\nERROR: {2}", typeof(T), Path, ex.ToString());
return null;
}
}
public T LoadFromBundle<T>(string path) where T : UnityEngine.Object
{
int i = 0;
for (int count = mBundleManagers.Count; i < count; i++)
{
if (mBundleManagers[i] != null)
{
T val = mBundleManagers[i].LoadFromBundle(path, typeof(T)) as T;
if ((UnityEngine.Object)val != (UnityEngine.Object)null)
{
return val;
}
}
}
return null;
}
public void CleanResourceCache(bool unloadResources = false)
{
mResourcesCache.Clear();
if (unloadResources)
{
Resources.UnloadUnusedAssets();
}
CancelInvoke();
}
}
|