public string GetUnpackageResPath(string name, ref bool isStreaming) { isStreaming = false; string key = GetResourceKey(name); if (!string.IsNullOrEmpty(key)) { string fileName = GetResourceFileName(key); ResourceData rd = _resourceList.Resources[key]; if (!rd.IsUnpackage()) { Debugger.LogError(name + " is not Unpackage resource!! 1"); return(null); } if (rd.IsOptional()) { return(_optionalPath + fileName); } if (File.Exists(_dataPath + fileName)) { return(_dataPath + fileName); } isStreaming = true; #if UNITY_ANDROID && !UNITY_EDITOR return(fileName); #else return(_streamingPath + fileName); #endif } #if UNITY_EDITOR else { if (!name.Contains("Unpackage")) { Debugger.LogError(name + " is not Unpackage resource!!"); return(null); } return(Application.dataPath + "/Resources/" + name); } #else return(null); #endif }
public static T Load <T>(string path) where T : UnityEngine.Object { string key = ResourceManager.Instance.GetResourceKey(path); if (!string.IsNullOrEmpty(key)) { ResourceData rd = ResourceManager.Instance.GetResourceData(key); if (rd.IsUnpackage() || rd.IsOptional()) { Debugger.LogError("The source : " + path + " is not normal resource!"); return(null); } T obj = ResourceManager.Instance.GetReferenceResource <T>(key); if (obj != null) { return(obj); } AssetBundle asset = ResourceManager.Instance.LoadAssetBundle(key); if (asset != null) { string assetPaht = "Assets/Resources/" + path; obj = asset.LoadAsset <T>(assetPaht); if (obj != null) { ResourceManager.Instance.AddResourceReference(key, obj); } ResourceManager.Instance.RemoveUnreferenceAssetBundle(key); return(obj); } ResourceManager.Instance.RemoveUnreferenceAssetBundle(key); } if (path.Contains("Unpackage") || path.Contains("Optional")) { Debugger.LogError("The source : " + path + " is not normal resource!"); return(null); } path = path.Substring(0, path.LastIndexOf(".")); return(Resources.Load <T>(path)); }
public static UnityEngine.Object[] LoadAll(string path) { string key = ResourceManager.Instance.GetResourceKey(path); if (!string.IsNullOrEmpty(key)) { ResourceData rd = ResourceManager.Instance.GetResourceData(key); if (rd.IsUnpackage() || rd.IsOptional()) { Debugger.LogError("The source : " + path + " is not normal resource!"); return(null); } UnityEngine.Object[] objs = ResourceManager.Instance.GetReferenceResources(key); if (objs != null && objs.Length > 0) { return(objs); } AssetBundle asset = ResourceManager.Instance.LoadAssetBundle(key); if (asset != null) { objs = asset.LoadAllAssets(); if (objs != null && objs.Length > 0) { ResourceManager.Instance.AddResourcesReference(key, objs); } ResourceManager.Instance.RemoveUnreferenceAssetBundle(key); return(objs); } ResourceManager.Instance.RemoveUnreferenceAssetBundle(key); } if (path.Contains("Unpackage") || path.Contains("Optional")) { Debugger.LogError("The source : " + path + " is not normal resource!"); return(null); } path = path.Substring(0, path.LastIndexOf(".")); return(Resources.LoadAll(path)); }
public static Downloader LoadOptionalUnpackageResBuffer(string path, Action <byte[]> callback) { string key = ResourceManager.Instance.GetResourceKey(path); if (!string.IsNullOrEmpty(key)) { ResourceData rd = ResourceManager.Instance.GetResourceData(key); if (!rd.IsOptional() || !rd.IsUnpackage()) { Debugger.LogError("The source : " + path + " is not Optional and UnpackageRes resource!"); callback(null); return(null); } List <DownloadFile> list = ResourceManager.Instance.GetOptionalNeedDownladList(key); if (list.Count > 0) { Downloader downloader = Downloader.DownloadFiles(list, (o) => { callback(LoadUnpackageResBuffer(path)); }); return(downloader); } callback(LoadUnpackageResBuffer(path)); return(null); } if (!path.Contains("Unpackage") || !path.Contains("Optional")) { Debugger.LogError("The source : " + path + " is not Optional and UnpackageRes resource!"); callback(null); return(null); } callback(LoadUnpackageResBuffer(path)); return(null); }
public static Downloader LoadOptionalResAll(string path, Action <UnityEngine.Object[]> callback) { string key = ResourceManager.Instance.GetResourceKey(path); if (!string.IsNullOrEmpty(key)) { ResourceData rd = ResourceManager.Instance.GetResourceData(key); if (!rd.IsOptional() || rd.IsUnpackage()) { Debugger.LogError("The source : " + path + " is not Optional resource!"); callback(null); return(null); } UnityEngine.Object[] objs = ResourceManager.Instance.GetReferenceResources(key); if (objs != null) { callback(objs); return(null); } AssetBundle asset = null; List <DownloadFile> list = ResourceManager.Instance.GetOptionalNeedDownladList(key); if (list.Count > 0) { Downloader downloader = Downloader.DownloadFiles(list, (o) => { asset = ResourceManager.Instance.LoadAssetBundle(key); if (asset != null) { objs = asset.LoadAllAssets(); if (objs != null && objs.Length > 0) { ResourceManager.Instance.AddResourcesReference(key, objs); } callback(objs); } else { callback(null); } ResourceManager.Instance.RemoveUnreferenceAssetBundle(key); }); return(downloader); } asset = ResourceManager.Instance.LoadAssetBundle(key); if (asset != null) { objs = asset.LoadAllAssets(); if (objs != null && objs.Length > 0) { ResourceManager.Instance.AddResourcesReference(key, objs); } callback(objs); } else { callback(null); } ResourceManager.Instance.RemoveUnreferenceAssetBundle(key); return(null); } if (!path.Contains("Optional") || path.Contains("Unpackage")) { Debugger.LogError("The source : " + path + " is not Optional resource!"); callback(null); return(null); } path = path.Substring(0, path.LastIndexOf(".")); callback(Resources.LoadAll(path)); return(null); }