-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathResources.cs
113 lines (103 loc) · 4.04 KB
/
Resources.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
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
using System;
using UnityEngine;
namespace UEx
{
/// <summary>
/// overrides the UnityEngine.Resources class
/// </summary>
public static class Resources
{
/// <summary>
/// Load the object of the specified type
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="path"></param>
/// <returns></returns>
public static T Load<T>(string path) where T : UnityEngine.Object
{
return UnityEngine.Resources.Load(path, typeof(T)) as T;
}
/// <summary>
/// Loads the specified map information (file named 'map', using same path as SceneInfo method)
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static T LoadMapInfo<T>() where T : UnityEngine.Object
{
return Load<T>("SceneInfo/" + Application.loadedLevelName + "/map");
}
/// <summary>
/// Load the specified map information, from the specified level name
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="levelName"></param>
/// <returns></returns>
public static T LoadMapInfo<T>(string levelName) where T: UnityEngine.Object
{
return Load<T>("SceneInfo/" + levelName + "/map");
}
/// <summary>
/// Load the specified scene info object (loads from Resources\SceneInfo\<seealso cref="UnityEngine.Application.loadedLevelName">levelName</seealso> folder)
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="filename"></param>
/// <param name="allowDefault"></param>
/// <returns></returns>
public static T LoadSceneInfo<T>(string filename, bool allowDefault = false) where T : UnityEngine.Object
{
var resource = Load<T>("SceneInfo/" + Application.loadedLevelName + "/" + filename);
if (allowDefault && resource == null)
{
resource = Load<T>("SceneInfo/Default Info/" + filename);
}
return resource;
}
//because overriding causes things to not use the UnityEngine class
#region Redirection
/// <summary>
/// Load all of the specified type at the path
/// </summary>
/// <param name="path"></param>
/// <param name="systemTypeInstance"></param>
/// <returns></returns>
public static UnityEngine.Object[] LoadAll(string path, Type systemTypeInstance)
{
return UnityEngine.Resources.LoadAll(path, systemTypeInstance);
}
/// <summary>
/// Unload the asset. Any remaining references will cause the asset to be reloaded as soon as it is accessed.
/// </summary>
/// <param name="assetToUnload"></param>
public static void UnloadAsset(UnityEngine.Object assetToUnload)
{
UnityEngine.Resources.UnloadAsset(assetToUnload);
}
/// <summary>
/// Unload all unused assets. Might take a while to do.
/// </summary>
public static void UnloadUnusedAssets()
{
UnityEngine.Resources.UnloadUnusedAssets();
}
/// <summary>
/// load the specified type at the path
/// </summary>
/// <param name="path"></param>
/// <param name="systemTypeInstance"></param>
/// <returns></returns>
public static UnityEngine.Object Load(string path, Type systemTypeInstance)
{
return UnityEngine.Resources.Load(path, systemTypeInstance);
}
/// <summary>
/// load the <seealso cref="UnityEngine.Object" /> at the path
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public static UnityEngine.Object Load(string path)
{
return UnityEngine.Resources.Load(path);
}
#endregion
}
}