/// <summary> /// 异步加载 /// </summary> /// <param name="callback"></param> public void AsyncLoad(Action callback) { // JDeBug.Inst.Log("开始任务:" + resourcePath); BResources.LoadAsync <GameObject>(resourcePath, (bool result, GameObject o) => { var go = GameObject.Instantiate(o); Transform = go.transform; Transform.gameObject.SetActive(false); // ClientMain.AddToUIRoot(Transform); IsLoad = true; Init(); if (callback != null) { callback(); } }); }
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); } }