/// <summary> /// 从缓存中卸载 实例化的资源 /// </summary> /// <param name="assetLoadPath">api传入的加载路径,Runtime下的相对路径</param> /// <returns></returns> public void UnloadObjectCache(Type type, string assetLoadPath) { if (type != null) { //卸载指定类型的缓存资源 var ret = GameObjectCacheMap.TryGetValue(type, out var map); if (ret) { ret = map.TryGetValue(assetLoadPath, out var gobj); if (ret) { //卸载 BResources.UnloadAsset(gobj); map.Remove(assetLoadPath); } } } else { //卸载所有同名的缓存资产 foreach (var typeMap in GameObjectCacheMap.Values) { var ret = typeMap.TryGetValue(assetLoadPath, out var gobj); if (ret) { //卸载 BResources.UnloadAsset(gobj); typeMap.Remove(assetLoadPath); } } } }
/// <summary> /// 销毁窗口 /// </summary> virtual public void Destroy() { //卸载 BResources.Destroy(this.Transform); // foreach (var subwin in this.subWindowsDictionary.Values) { subwin.Destroy(); } IsLoad = false; //卸载窗口 BResources.UnloadAsset(resourcePath); }
static public void Clear() { //卸载复制体 foreach (var v in gameObjPoolsMap.Values) { v.Clear(); } gameObjPoolsMap = new Dictionary <string, GameObjectRecord>(); //卸载源数据 foreach (var m in gameObjPoolsMap) { BResources.UnloadAsset(m.Key); } }
static StackObject *UnloadAsset_4(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj) { ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject *ptr_of_this_method; StackObject *__ret = ILIntepreter.Minus(__esp, 2); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); System.Boolean @isUnloadIsUsing = ptr_of_this_method->Value == 1; ptr_of_this_method = ILIntepreter.Minus(__esp, 2); System.String @path = (System.String) typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); BResources.UnloadAsset(@path, @isUnloadIsUsing); return(__ret); }
void OnGUI() { if (GUILayout.Button("测试拷贝streamingasset", GUILayout.Height(50), GUILayout.Width(300))) { //多层目录 //versionControl.CopyStreamingAsset(1.8f, () => //{ // JDeBug.Inst.Log("拷贝完成!"); //}); } if (GUILayout.Button("下载测试", GUILayout.Height(50), GUILayout.Width(300))) { ////启动版本控制 //versionControl.Start("3", "100", "V0uFhE2GRNnRipS0hery9OhY", (float state, string info, bool issuccess) => //{ // JDeBug.Inst.Log("业务逻辑层通知:" + "下载完成"); // JDeBug.Inst.Log("本地目录:" + versionControl.LocalHotUpdateResPath); //}); } if (GUILayout.Button("editor模式:[异步]加载依测试", GUILayout.Height(50), GUILayout.Width(300))) { BResources.IsAssetBundleModel = false; //切换为 resource.load加载模式 //单层目录 BResources.LoadAsync <GameObject>("Canvas", (bool issuccess, GameObject o) => { if (issuccess) { GameObject.Instantiate(o); } }); } if (GUILayout.Button("ab模式:加载依赖文件", GUILayout.Height(50), GUILayout.Width(300))) { BResources.IsAssetBundleModel = true; //切换为 ab加载模式 BResources.LoadManifestAsync("AllResources", (bool _issuccess) => //step.2 全局加载依赖 只需加载一次。 { if (_issuccess) { BDebug.Log("依赖加载成功!"); } }); } if (GUILayout.Button("ab模式:[异步]加载1级目录", GUILayout.Height(50), GUILayout.Width(300))) { BResources.IsAssetBundleModel = true; //切换为 ab加载模式 //单层目录 BResources.LoadAsync <GameObject>("Canvas", (bool issuccess, GameObject o) => { if (issuccess) { isLoadCanvas = true; GameObject.Instantiate(o); } }); } if (isLoadCanvas) { if (GUILayout.Button("ab模式:卸载canvas", GUILayout.Height(50), GUILayout.Width(300))) { BResources.UnloadAsset("Canvas"); } } if (GUILayout.Button("ab模式:[异步]加载多级目录", GUILayout.Height(50), GUILayout.Width(300))) { BResources.IsAssetBundleModel = true; //切换为 ab加载模式 //多层目录 BResources.LoadAsync <GameObject>("test1/test", (bool issuccess, GameObject o) => { if (issuccess) { GameObject.Instantiate(o); } }); } if (GUILayout.Button("ab模式:[异步]加载一组", GUILayout.Height(50), GUILayout.Width(300))) { BResources.IsAssetBundleModel = true; //切换为 ab加载模式 IList <string> list = new List <string>() { "Canvas", "test1/test" }; //多层目录 var task = BResources.LoadAsync(list, (IDictionary <string, UnityEngine.Object> resmap) => { var o1 = GameObject.Instantiate(resmap["Canvas"]); var o2 = GameObject.Instantiate(resmap["test1/test"]); }); BResources.LoadCancel(task); } if (GUILayout.Button("ab模式:[异步]取消加载请求", GUILayout.Height(50), GUILayout.Width(300))) { BResources.IsAssetBundleModel = true; //切换为 ab加载模式 //多层目录 var taskid = BResources.LoadAsync <GameObject>("test1/test", (bool issuccess, GameObject o) => { if (issuccess) { GameObject.Instantiate(o); } }); BResources.LoadCancel(taskid); } }
/// <summary> /// 卸载,ab中需要 /// </summary> /// <param name="path"></param> static public void Unload(string path) { BResources.UnloadAsset(path); }