Created
August 12, 2015 02:29
-
-
Save sunny352/a1f1af5a6eb53bc5133f to your computer and use it in GitHub Desktop.
简单的资源加载功能
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
//资源管理 | |
public class ResourcesManager | |
{ | |
public static T Load<T>(string folder, string fileName) where T : UnityEngine.Object | |
{ | |
#if UNITY_EDITOR | |
T obj = UnityEditor.AssetDatabase.LoadAssetAtPath<T>(string.Format("Assets/{0}/{1}", folder, fileName)); | |
if (null != obj) | |
{ | |
return obj; | |
} | |
#endif | |
int sep = fileName.LastIndexOf("."); | |
if (-1 != sep) | |
{ | |
fileName = fileName.Substring(0, sep); | |
} | |
return Resources.Load<T>(string.Format("{0}/{1}", folder, fileName)); | |
} | |
public static UnityEngine.Object Load(string folder, string fileName) | |
{ | |
#if UNITY_EDITOR | |
UnityEngine.Object obj = UnityEditor.AssetDatabase.LoadMainAssetAtPath(string.Format("Assets/{0}/{1}", folder, fileName)); | |
if (null != obj) | |
{ | |
return obj; | |
} | |
#endif | |
int sep = fileName.LastIndexOf("."); | |
if (-1 != sep) | |
{ | |
fileName = fileName.Substring(0, sep); | |
} | |
return Resources.Load(string.Format("{0}/{1}", folder, fileName)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment