public void OnLoad(string tag, LoadPath loadPath, DataSet data, Callback <Sprite> callback) { CDebug.Log("load texture success " + loadPath.path); Texture2D texture2d = null; if (TextureCache.Instance.Contains(loadPath.path)) { texture2d = TextureCache.Instance.Get(loadPath.path).texture2d; } else { texture2d = ByteConvert.BytesToTexture2D(data.bytes); } texture2d.wrapMode = TextureWrapMode.Clamp; Sprite sprite = ByteConvert.CreateImage(texture2d); TextureCache.Instance.AddCache(loadPath.path, texture2d); SpriteCache.Instance.AddCache(loadPath.path, sprite); Callback unload = () => { TextureCache.Instance.UnloadCache(loadPath.path); SpriteCache.Instance.UnloadCache(loadPath.path); }; AddToUnloadTask(tag, unload); if (callback != null) { callback(sprite); callback = null; } }
public void OnLoad(string tag, LoadPath loadPath, DataSet data, Callback <string> callback) { CDebug.Log("load texture success " + loadPath.path); string str = ""; if (StringCache.Instance.Contains(loadPath.path)) { str = StringCache.Instance.Get(loadPath.path); } else { str = ByteConvert.BytesToString(data.bytes); StringCache.Instance.Add(loadPath.path, str); } Callback unload = () => { str = ""; }; AddToUnloadTask(tag, unload); if (callback != null) { callback(str); callback = null; } }
/// <summary> /// 向资源管理器中添加一个任务 /// </summary> public void AddTask(LoadPath loadPath, string flag, Action <DataSet> finish) { ITask task; if (loadPath.usewww) { task = new WWWTask(loadPath.path, flag, finish); } else { task = new FrameTask(loadPath.path, flag, finish); } AddTask(task); }
private void LoadCache() { //string path = resourceRoot + abName; //CDebug.Log(platform.platformStr + "/" + abName); if (!AppSetting.isRemote) { cachePath = new LoadPath(AppSetting.rootPath, resourceRoot + abName); } else { if (!TaskManager.instance.localResPaths.ContainsKey(platform.platformStr + "/" + abName)) { CDebug.LogError("---------- 资源不存在 " + platform.platformStr + "/" + abName); return; } else { cachePath = TaskManager.instance.localResPaths[platform.platformStr + "/" + abName]; } } if (AssetBundleCache.Instance.Contains(cachePath.path)) { cache = AssetBundleCache.Instance.GetCache(cachePath.path); LoadFinish(); } else { resMgr.AddTask(cachePath, flag, (CEngine.DataSet bundle) => { //CDebug.Log(bundle == null); //CDebug.Log("Path.GetFileNameWithoutExtension(abName) " + Path.GetFileNameWithoutExtension(abName)); if (AssetBundleCache.Instance.Contains(cachePath.path)) { cache = AssetBundleCache.Instance.GetCache(cachePath.path); } else { cache = AssetBundle.LoadFromMemory(bundle.bytes); AssetBundleCache.Instance.AddCache(cachePath.path, cache); //CDebug.Log(cache == null); } LoadFinish(); //if (cache != null) //{ // cacheObject = cache.LoadAsset(Path.GetFileNameWithoutExtension(abName)) as GameObject; // CDebug.Log("load cache " + abName + " finished " + (cacheObject == null)); // //Instantiate(cache); // //DateTime t2 = DateTime.Now; // //CDebug.Log(" Time2:" + (t2 - t1).TotalMilliseconds);//+ " Time3:" + (t3 - t2).TotalMilliseconds //} }); } }
private void LoadDepends() { AssetBundleManifest manifest = (AssetBundleManifest)mainFirst.LoadAsset("AssetBundleManifest"); //获取依赖文件列表; string[] dependNames = manifest.GetAllDependencies(abName); if (dependNames.Length == 0) { LoadCache(); } //CDebug.Log("!!!!!!!!!!!!!!!!!!!!!!!dependNames.Length " + dependNames.Length); //foreach (var item in dependNames) //{ // CDebug.Log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!dependName " + item); //} depends = new List <string>(); for (int index = 0; index < dependNames.Length; index++) { //加载所有的依赖文件; //string path = resourceRoot + dependNames[index]; LoadPath localPath; if (!AppSetting.isRemote) { localPath = new LoadPath(AppSetting.rootPath, resourceRoot + dependNames[index]); } else { //CDebug.Log(platform.platformStr + "/" + dependNames[index]); localPath = TaskManager.instance.localResPaths[platform.platformStr + "/" + dependNames[index]]; } //CDebug.LogError(dependNames[index]); if (AssetBundleCache.Instance.Contains(localPath.path)) { AssetBundleCache.Instance.GetCache(localPath.path); depends.Add(localPath.path); if (depends.Count == dependNames.Length) { //CDebug.Log("load depends finished 1" + abName); LoadCache(); } } else { resMgr.AddTask(localPath, flag, (CEngine.DataSet data) => { if (AssetBundleCache.Instance.Contains(localPath.path)) { AssetBundleCache.Instance.GetCache(localPath.path); depends.Add(localPath.path); if (depends.Count == dependNames.Length) { //CDebug.Log("load depends finished 2" + abName); LoadCache(); } } else { AssetBundle ab = AssetBundle.LoadFromMemory(data.bytes); depends.Add(localPath.path); AssetBundleCache.Instance.AddCache(localPath.path, ab); if (depends.Count == dependNames.Length) { //CDebug.Log("load depends finished 3" + abName); LoadCache(); } } }); } } }