-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResourceLoader.cs
More file actions
35 lines (28 loc) · 866 Bytes
/
ResourceLoader.cs
File metadata and controls
35 lines (28 loc) · 866 Bytes
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
using System;
using UnityEngine;
public static class ResourceLoader
{
public static T GetResource<T>(Enum enumMember) where T : UnityEngine.Object
{
string fullPath = GetEnumPath(enumMember);
var resource = Resources.Load<T>(fullPath);
if (resource == null)
{
Debug.LogWarning($"Invalid name or path: {fullPath}");
return null;
}
return resource;
}
private static string GetEnumPath(Enum enumMember)
{
var enumType = enumMember.GetType();
var path = new System.Text.StringBuilder();
while (enumType != null)
{
path.Insert(0, $"{enumType.Name}/");
enumType = enumType.DeclaringType;
}
path.Append(enumMember.ToString());
return path.ToString();
}
}