Skip to content

Instantly share code, notes, and snippets.

@sunny352
Created August 12, 2015 02:29
Show Gist options
  • Save sunny352/a1f1af5a6eb53bc5133f to your computer and use it in GitHub Desktop.
Save sunny352/a1f1af5a6eb53bc5133f to your computer and use it in GitHub Desktop.
简单的资源加载功能
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