Esempio n. 1
0
        /// <summary>
        /// 分组执行任务,每组加载ASYNC_TASK_NUM个任务
        /// </summary>
        public void DoNextTask()
        {
            if (isStop)
            {
                return;
            }

            //获取一个任务
            while (taskList.Count > 0 && curDoTaskConter < ASYNC_TASK_NUM)
            {
                var task = taskList[0];
                taskList.RemoveAt(0);
                //这一步确保主资源最后加载,防止资源自动依赖丢失
                if (task.IsMainAsset && taskList.Count != 0)
                {
                    taskList.Add(task);
                    continue;
                }
                //主资源才加载
                IEnumeratorTool.StartCoroutine(IE_AsyncLoadAssetbundle(task, (ret) =>
                {
                    curDoTaskConter--;

                    switch (ret)
                    {
                    case LoadAssetState.IsLoding:
                        //正在加载,需要重新压入task
                        taskList.Add(task);
                        break;

                    case LoadAssetState.Fail:
                    case LoadAssetState.Success:
                        {
                            if (isStop)
                            {
                                return;
                            }
                            //判断任务进度
                            if (curDoTaskConter > 0)
                            {
                                this.DoNextTask();
                            }
                            else
                            {
                                //总进度通知
                                IsComplete  = true;
                                var instObj = loder.LoadFormAssetBundle <Object>(this.MainAssetName, this.manifestItem);
                                OnAllTaskCompleteCallback?.Invoke(MainAssetName, instObj);
                            }
                        }
                        break;
                    }
                }));

                curDoTaskConter++;
            }
        }
Esempio n. 2
0
    private void btn_06()
    {
        List <GameObject> golist = new List <GameObject>();
        //1.同步加载
        var go    = BResources.Load <GameObject>("AssetTest/Cube");
        var load1 = GameObject.Instantiate(go);

        go = BResources.Load <GameObject>("Test/Cube");
        var load2 = GameObject.Instantiate(go);

        go = BResources.Load <GameObject>("AssetTest/Particle");
        var load3 = GameObject.Instantiate(go);

        go = BResources.Load <GameObject>("Char/001");
        var loadModel = GameObject.Instantiate(go);

        golist.Add(load1);
        golist.Add(load2);
        golist.Add(load3);
        golist.Add(loadModel);
        //2.异步加载单个
        var id = BResources.AsyncLoad <GameObject>("Test/Cube", (o) =>
        {
            var load4 = GameObject.Instantiate(o);
            golist.Add(load4);
        });

        //3.异步加载多个
        var list = new List <string>()
        {
            "AssetTest/Cube", "Test/Cube"
        };

        BResources.AsyncLoad(list, (i, i2) =>
        {
            //进度
            Debug.Log(string.Format("进度 {0} / {1}", i, i2));
        }, (map) =>
        {
            BDebug.Log("加载全部完成,资源列表:");
            foreach (var r in map)
            {
                BDebug.Log(string.Format("--> {0} : {1}", r.Key, r.Value.name));
                var _go = GameObject.Instantiate(r.Value);
                golist.Add(_go as  GameObject);
            }
        });


        IEnumeratorTool.WaitingForExec(5, () =>
        {
            foreach (var _go in golist)
            {
                GameObject.Destroy(_go);
            }
        });
    }
Esempio n. 3
0
        /// <summary>
        /// 异步加载窗口
        /// </summary>
        /// <param name="indexes"></param>
        /// <param name="loadProcessAction"></param>
        public void AsyncLoadWindows(List <int> indexes, Action <int, int> loadProcessAction)
        {
            int allCount     = indexes.Count;
            int curTaskCount = 0;

            foreach (var i in indexes)
            {
                var index = i.GetHashCode();
                if (windowMap.ContainsKey(index))
                {
                    var uvalue = windowMap[index];
                    if (uvalue.IsLoad)
                    {
                        Debug.LogError("已经加载过并未卸载" + index);
                        //任务直接完成
                        {
                            curTaskCount++;
                            loadProcessAction(allCount, curTaskCount);
                        }
                        continue;
                    }
                }
                else
                {
                    //创建窗口
                    var win = CreateWindow(index);
                    if (win == null)
                    {
                        Debug.LogErrorFormat("不存在UI:{0}", index);
                        curTaskCount++;
                        loadProcessAction(allCount, curTaskCount);
                    }
                    else
                    {
                        windowMap[index] = win;
                        //开始窗口加载
                        win.AsyncLoad(() =>
                        {
                            IEnumeratorTool.WaitingForExec(0.1f, () =>
                            {
                                curTaskCount++;
                                loadProcessAction(allCount, curTaskCount);

                                if (win.Transform)
                                {
                                    win.Transform.SetParent(this.Bottom, false);
                                }
                                //推送缓存的数据
                                PushCaheData(index);
                            });
                        });
                    }
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 递归加载
        /// </summary>
        /// <param name="path"></param>
        /// <param name="sucessCallback"></param>
        /// <returns></returns>
        IEnumerator IEAsyncLoadAssetbundle(List <string> resList, Action <bool> callback)
        {
            if (resList.Count == 0)
            {
                callback(true);
            }
            else
            {
                //弹出一个任务
                var res = resList[0];
                resList.RemoveAt(0);
                if (res.EndsWith(".shader"))
                {
                    int i = 0;
                }
                var mainItem = manifest.Manifest.GetManifestItem(res);
                //单ab 多资源,加载真正ab名
                if (mainItem != null && !string.IsNullOrEmpty(mainItem.PackageName))
                {
                    res = mainItem.PackageName;
                }

                if (!currentLoadingABNames.Contains(res) && !assetbundleMap.ContainsKey(res))
                {
                    //加入列表防止同时加载一个
                    currentLoadingABNames.Add(res);
                    //
                    var resPath = FindAsset(res);
                    //开始加载
                    var result = AssetBundle.LoadFromFileAsync(resPath);
                    yield return(result);

                    //加载结束
                    if (result.isDone)
                    {
                        //移除当前列表
                        currentLoadingABNames.Remove(res);
                        //添加assetbundle
                        if (result.assetBundle != null)
                        {
                            AddAssetBundle(res, result.assetBundle);
                        }
                        else
                        {
                            BDebug.LogError("ab资源为空:" + resPath);
                        }
                    }
                }

                //开始下个任务
                IEnumeratorTool.StartCoroutine(IEAsyncLoadAssetbundle(resList, callback));
                yield break;
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Invoke the callback when the server return messge .
 /// </summary>
 /// <param name='pomeloMessage'>
 /// Pomelo message.
 /// </param>
 public void InvokeCallBack(uint id, JsonNode_Object data)
 {
     if (!callBackMap.ContainsKey(id))
     {
         return;
     }
     IEnumeratorTool.ExecAction(() =>
     {
         callBackMap[id](data);
     });
 }
        public override void Start()
        {
            base.Start();
            foreach (var cd in this.GetAllClassDatas())
            {
                var attr = cd.Attribute as ComponentAdaptorProcessAttribute;
                adaptorMap[attr.Type] = CreateInstance <AComponentAdaptor>(cd);
            }

            //执行30s清理一次的cache
            IEnumeratorTool.StartCoroutine(this.IE_ClearCache(30));
        }
Esempio n. 7
0
    public void BeginInit(Action <Exception> onInit, ScreenViewLayer layer)
    {
        this.IsLoad = true;
        //BDebug.Log("enter logo");

        UIMgr.Inst.LoadWindows(0);
        UIMgr.Inst.ShowWindow(0);

        IEnumeratorTool.WaitingForExec(3, () =>
        {
            ScreenViewMgr.Inst.BeginNav("Battle");
        });
    }
Esempio n. 8
0
 private void showInputContents()
 {
     if (tempInputContents.Count == tempDialData.Count)
     {
         return;
     }
     while (tempInputContents.Count > tempDialData.Count)
     {
         GameObject.DestroyImmediate(tempInputContents[tempInputContents.Count - 1].Transform.gameObject);
         tempInputContents.RemoveAt(tempInputContents.Count - 1);
     }
     txt_Num.text = tempDialData.Count.ToString();
     IEnumeratorTool.StartCoroutine(createInputContent());
 }
        /// <summary>
        /// 开始热更脚本逻辑
        /// </summary>
        static public void Load(string root, HotfixCodeRunMode mode)
        {
            if (root != "")
            {
                IEnumeratorTool.StartCoroutine(IE_LoadScript(root, mode));
            }
            else
            {
#if UNITY_EDITOR
                BDebug.Log("内置code模式!");
                BDLauncherBridge.Start();
#endif
            }
        }
        public void Do(IBattle battle, IHeroFSM selfFSM, IHeroFSM targetFSM)
        {
            var o = BResources.Load <GameObject>(this.se.StrParam0);

            effect = GameObject.Instantiate(o).transform;
            //在敌方阵营的特效 需要旋转


            //父节点
            Transform parent = null;

            if (se.DoubleParams0 == 1) //单体
            {
                if (targetFSM.Camp == 2)
                {
                    effect.eulerAngles = new Vector3(0, 180, 0);
                }
                parent = battle.World.GetPlayerRootTransform(targetFSM.ID);
            }
            else if (se.DoubleParams0 == 2)
            {
                parent = battle.World.GetPlayerRootTransform(targetFSM.Camp);
            }
            else if (se.DoubleParams0 == 3) //连接
            {
                parent = battle.World.GetPlayerRootTransform(selfFSM.Camp);
                var mypos  = battle.World.GetPlayerPos(selfFSM.ID);
                var tarpos = battle.World.GetPlayerPos(targetFSM.ID);

                //TODO 求两个向量夹角
                var v1  = new Vector2(mypos.x, mypos.z);
                var v2  = new Vector2(tarpos.x, tarpos.z);
                var dir = (v2 - v1).normalized;

                effect.LookAt(dir);
//              float angle = Vector3.Angle(mypos, tarpos);
//                effect.eulerAngles += new Vector3(0,angle,0);
            }

            effect.SetParent(parent, false);


            if (se.DoubleParams1 > 0)
            {
                IEnumeratorTool.WaitingForExec((float)se.DoubleParams1, () =>
                {
                    BResources.Destroy(effect);
                });
            }
        }
        static StackObject *StopCoroutine_1(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, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Int32 @id = ptr_of_this_method->Value;


            IEnumeratorTool.StopCoroutine(@id);

            return(__ret);
        }
Esempio n. 12
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="rootPath"></param>
        public void Init(string rootPath)
        {
            //多热更切换,需要卸载
            if (this.AssetConfigLoder != null)
            {
                this.UnloadAllAsset();
            }

            var platformPath = BApplication.GetRuntimePlatformPath();

            //1.设置加载路径
            if (Application.isEditor)
            {
                firstArtDirectory = IPath.Combine(rootPath, platformPath, BResources.ART_ASSET_ROOT_PATH);
                secArtDirectory   = IPath.Combine(Application.streamingAssetsPath, platformPath, BResources.ART_ASSET_ROOT_PATH); //
            }
            else
            {
                firstArtDirectory = IPath.Combine(Application.persistentDataPath, platformPath, BResources.ART_ASSET_ROOT_PATH);
                secArtDirectory   = IPath.Combine(Application.streamingAssetsPath, platformPath, BResources.ART_ASSET_ROOT_PATH); //
            }

            //2.路径替换
            firstArtDirectory = IPath.ReplaceBackSlash(firstArtDirectory);
            secArtDirectory   = IPath.ReplaceBackSlash(secArtDirectory);

            //3.加载ArtConfig
            this.AssetConfigLoder = new AssetbundleConfigLoder();
            var assetconfigPath = "";
            var assetTypePath   = "";

            if (Application.isEditor)
            {
                assetconfigPath = IPath.Combine(rootPath, platformPath, BResources.ART_ASSET_CONFIG_PATH);
                assetTypePath   = IPath.Combine(rootPath, platformPath, BResources.ART_ASSET_TYPES_PATH);
            }
            else
            {
                //真机环境config在persistent,跟dll和db保持一致
                assetconfigPath = IPath.Combine(Application.persistentDataPath, platformPath, BResources.ART_ASSET_CONFIG_PATH);
                assetTypePath   = IPath.Combine(Application.persistentDataPath, platformPath, BResources.ART_ASSET_TYPES_PATH);
            }

            this.AssetConfigLoder.Load(assetconfigPath, assetTypePath);
            //开始异步任务刷新
            IEnumeratorTool.StartCoroutine(this.IE_AsyncTaskListUpdte());
            BDebug.Log($"【AssetBundleV2】 firstDir:{firstArtDirectory}", "red");
            BDebug.Log($"【AssetBundleV2】 secDir:{secArtDirectory}", "red");
        }
Esempio n. 13
0
        public void AsyncLoadManifest(string path, Action <bool> callback)
        {
            //如果存在 不让加载
            //if (manifest != null)
            //{
            //    callback(true);
            //    return;
            //}
            path = Path.Combine(LocalHotUpdateResPath, path);
#if UNITY_EDITOR || UNITY_IPHONE
            path = "File:///" + path;
#endif
            path = path.Replace("\\", "/");
            IEnumeratorTool.StartCoroutine(IELoadAssetBundles(path, callback, true));
        }
Esempio n. 14
0
        public int LoadAsync <T>(string objName, Action <bool, T> action, bool isCreateTaskid = true) where T : UnityEngine.Object
        {
            //创建任务序列
            int taskid = -1;

            if (isCreateTaskid)
            {
                taskid = CreateTaskHash();
                taskHashSet.Add(taskid);
            }

            AsyncTask task = new AsyncTask();

            task.id = taskid;
            task.RegTask(() =>
            {
                if (objsMap.ContainsKey(objName))
                {
                    //判断任务结束
                    task.EndTask();
                    //有创建taskid的,判断段taskid是否存在
                    if (isCreateTaskid == true && taskHashSet.Contains(taskid) == false)
                    {
                        BDebug.Log("没发现任务id,不执行回调");
                        return;
                    }
                    action(true, objsMap[objName] as T);
                }
                else
                {
                    IEnumeratorTool.StartCoroutine(IELoadAsync <T>(objName, (bool b, T t) =>
                    {
                        //判断任务结束
                        task.EndTask();
                        //有创建taskid的,判断段taskid是否存在
                        if (isCreateTaskid == true && taskHashSet.Contains(taskid) == false)
                        {
                            BDebug.Log("没发现任务id,不执行回调");
                            return;
                        }
                        action(b, t);
                    }));
                }
            });

            asyncTaskList.Add(task);
            return(taskid);
        }
Esempio n. 15
0
 /// <summary>
 /// 开始热更脚本逻辑
 /// </summary>
 static public void Load(string root, HotfixCodeRunMode mode)
 {
     if (root != "")
     {
         IEnumeratorTool.StartCoroutine(IE_LoadScript(root, mode));
     }
     else
     {
         BDebug.Log("内置code模式!");
         //反射调用,防止编译报错
         var assembly = Assembly.GetExecutingAssembly();
         var type     = assembly.GetType("BDLauncherBridge");
         var method   = type.GetMethod("Start", BindingFlags.Public | BindingFlags.Static);
         method.Invoke(null, new object[] { false, false });
     }
 }
        public override void Start()
        {
            base.Start();
            var clsList = this.GetAllClassDatas();

            foreach (var cd in clsList)
            {
                var attr = cd.Attribute as ComponentBindAdaptorAttribute;
                var inst = CreateInstance <AComponentBindAdaptor>(cd);
                componentBindAdaptorMap[attr.BindType] = inst;
            }


            //执行30s清理一次的cache
            IEnumeratorTool.StartCoroutine(this.IE_ClearCache(30));
        }
Esempio n. 17
0
        /// <summary>
        /// 递归加载
        /// </summary>
        /// <param name="path"></param>
        /// <param name="sucessCallback"></param>
        /// <returns></returns>
        IEnumerator IEAsyncLoadAssetbundle(List <string> resList, Action <bool> callback)
        {
            if (resList.Count == 0)
            {
                callback(true);
                yield break;
            }
            else
            {
                //弹出一个任务
                var res = resList[0];
                resList.RemoveAt(0);

                if (!assetbundleMap.ContainsKey(res))
                {
                    var resPath = FindAsset(res);

                    //开始加载
                    var result = AssetBundle.LoadFromFileAsync(resPath);
                    yield return(result);

                    //加载结束
                    if (result.isDone)
                    {
                        //添加assetbundle
                        if (result.assetBundle != null)
                        {
                            AddAssetBundle(res, result.assetBundle);
                        }
                        else
                        {
                            BDebug.LogError("ab资源为空:" + resPath);
                        }
                    }
                }
                else
                {
                    BDebug.Log("已存在,無需加載:" + res);
                }



                //开始下个任务
                IEnumeratorTool.StartCoroutine(IEAsyncLoadAssetbundle(resList, callback));
            }
        }
Esempio n. 18
0
        /// <summary>
        /// If the event exists,invoke the event when server return messge.
        /// </summary>
        /// <param name="eventName"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        ///
        public void InvokeOnEvent(string route, JsonNode_Object msg)
        {
            if (!this.eventMap.ContainsKey(route))
            {
                return;
            }

            List <Action <JsonNode_Object> > list = eventMap[route];

            foreach (Action <JsonNode_Object> action in list)
            {
                IEnumeratorTool.ExecAction(() =>
                {
                    action.Invoke(msg);
                });
            }
        }
        static StackObject *StartCoroutine_0(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, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Collections.IEnumerator @ie = (System.Collections.IEnumerator) typeof(System.Collections.IEnumerator).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);


            var result_of_this_method = IEnumeratorTool.StartCoroutine(@ie);

            __ret->ObjectType = ObjectTypes.Integer;
            __ret->Value      = result_of_this_method;
            return(__ret + 1);
        }
Esempio n. 20
0
        /// <summary>
        /// 递归加载
        /// </summary>
        /// <param name="path"></param>
        /// <param name="sucessCallback"></param>
        /// <returns></returns>
        IEnumerator IEAsyncLoadAssetbundle(Stack <string> loadStack, Action <bool> callback)
        {
            if (loadStack.Count == 0)
            {
                callback(true);
            }
            else
            {
                //弹出一个任务
                var path = loadStack.Pop();

                //如果存在,直接执行下一个
                if (assetbundleMap.ContainsKey(path))
                {
                    IEnumeratorTool.StartCoroutine(IEAsyncLoadAssetbundle(loadStack, callback));
                    assetbundleMap[path].Use();
                    yield break;
                }


                //开始加载
                var result = AssetBundle.LoadFromFileAsync(path);
                yield return(result);

                //加载结束
                if (result.isDone)
                {
                    //添加assetbundle
                    if (result.assetBundle != null)
                    {
                        AddAssetBundle(path, result.assetBundle);
                    }
                    else
                    {
                        Debugger.LogError("ab资源为空:" + path);
                    }
                }
                else
                {
                    Debugger.LogError("加载失败:" + path);
                }
                //开始下个任务
                IEnumeratorTool.StartCoroutine(IEAsyncLoadAssetbundle(loadStack, callback));
            }
        }
Esempio n. 21
0
        /// <summary>
        /// 检测StreamingAsset下的资源包版本
        /// StreamingAsset 和 Persistent对比
        /// </summary>
        /// <param name="callback"></param>
        static public void CheckAssetPackageVersion(RuntimePlatform platform, Action callback)
        {
            switch (platform)
            {
            //android沙盒用www访问
            case RuntimePlatform.Android:
            {
                IEnumeratorTool.StartCoroutine(AndroidCheckAssetPackageVersion(platform, callback));
            }
            break;

            default:
            {
                IOSCheckAssetPackageVersion(platform, callback);
            }
            break;
            }
        }
        /// <summary>
        /// 加载ab
        /// </summary>
        /// <param name="path"></param>
        /// <param name="callback"></param>
        private void AsyncLoadAssetBundle(string path, Action <bool> callback)
        {
            //ab存储的是asset下的相对目录
            path = "assets/resource/runtime/" + path.ToLower();
            //寻找ab的后缀名
            var assetPath = GetExistPath(path);

            if (assetPath != null)
            {
                var res = manifest.Manifest.GetDirectDependencies(assetPath);
                //1.创建依赖加载队列
                Queue <string> loadQueue = new Queue <string>();
                foreach (var asset in res)
                {
                    //依赖队列需要加上resourcepath
                    var fullPath = Path.Combine(this.resourcePath, asset);
                    //判断是否已经加载过
                    if (assetbundleMap.ContainsKey(asset) == false)
                    {
                        loadQueue.Enqueue(fullPath);
                    }
                    else
                    {
                        assetbundleMap[asset].Use();
                    }
                }

                //2.加载主体
                if (assetbundleMap.ContainsKey(assetPath) == false)
                {
                    var fullPath = Path.Combine(this.resourcePath, assetPath);
                    loadQueue.Enqueue(fullPath);
                }

                //开始加载队列
                IEnumeratorTool.StartCoroutine(IEAsyncLoadAssetbundle(loadQueue, callback));
            }
            else
            {
                BDebug.LogError("没有该资源:" + path);
                //没有该资源
                callback(false);
            }
        }
Esempio n. 23
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="rootPath"></param>
        public void Init(string rootPath, RuntimePlatform platform = RuntimePlatform.Android)
        {
            //多热更切换,需要卸载
            if (this.AssetConfigLoder != null)
            {
                this.UnloadAllAsset();
            }

            //平台
            string platformPath = "";

            //1.设置加载路径
            if (Application.isEditor)
            {
                //editor下可以自行输入
                platformPath      = BApplication.GetPlatformPath(platform);
                firstArtDirectory = IPath.Combine(rootPath, platformPath, BResources.ART_ASSET_ROOT_PATH);
                secArtDirectory   = IPath.Combine(Application.streamingAssetsPath, platformPath, BResources.ART_ASSET_ROOT_PATH); //
            }
            else
            {
                //runtime只能使用当前平台
                platformPath      = BApplication.GetRuntimePlatformPath();
                firstArtDirectory = IPath.Combine(Application.persistentDataPath, platformPath, BResources.ART_ASSET_ROOT_PATH);
                secArtDirectory   = IPath.Combine(Application.streamingAssetsPath, platformPath, BResources.ART_ASSET_ROOT_PATH); //
                rootPath          = Application.persistentDataPath;
            }

            //2.寻址路径格式化
            firstArtDirectory = IPath.FormatPathOnRuntime(firstArtDirectory);
            secArtDirectory   = IPath.FormatPathOnRuntime(secArtDirectory);

            //3.加载ArtConfig
            this.AssetConfigLoder = GetAssetbundleConfigLoder(rootPath, platformPath);

            //开始异步任务刷新
            IEnumeratorTool.StartCoroutine(this.IE_LoadTaskUpdate());
            IEnumeratorTool.StartCoroutine(this.IE_UnLoadTaskUpdate());

            BDebug.Log($"【AssetBundleV2】 firstDir:{firstArtDirectory}", "red");
            BDebug.Log($"【AssetBundleV2】 secDir:{secArtDirectory}", "red");
        }
        /// <summary>
        /// 初始化DB
        /// </summary>
        /// <param name="str"></param>
        static public void Load(string root)
        {
            Connection?.Dispose();

            //先以外部传入的 作为 firstpath
            firstPath = IPath.Combine(root, BDUtils.GetPlatformPath(Application.platform) + "/Local.db");

            //firstpath不存在 或者 不支持io操作,
            //则默认情况生效,persistent为firstpath
            if (!File.Exists(firstPath))
            {
                //这里sqlite 如果不在firstPath下,就到Streamming下面拷贝到第一路径
                IEnumeratorTool.StartCoroutine(IE_LoadSqlite());
            }
            else
            {
                BDebug.Log("DB加载路径:" + firstPath, "red");
                Connection = new SQLiteConnection(firstPath, SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create);
            }
        }
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="path"></param>
 public AssetBundleManifestReference(string path)
 {
     if (Application.isEditor)
     {
         //这里开个同步接口 为了单元测试用
         if (File.Exists(path))
         {
             BDebug.Log("manifest加载成功!");
             var text = File.ReadAllText(path);
             this.Manifest = new ManifestConfig(text);
             OnLoaded?.Invoke();
             OnLoaded = null;
         }
     }
     else
     {
         //加载manifest
         IEnumeratorTool.StartCoroutine(IE_LoadConfig(path));
     }
 }
Esempio n. 26
0
        /// <summary>
        /// 加载ab
        /// </summary>
        /// <param name="path"></param>
        /// <param name="sucessCallback"></param>
        public void LoadAssetBundleAsync(string path, Action <bool> sucessCallback)
        {
            path = Path.Combine(LocalHotUpdateResPath, path);
            path = "file:///" + path;

            path = path.Replace("\\", "/");
            if (manifest.Manifest == null)
            {
                Debug.LogError("请先加载依赖文件!");
                return;
            }

            var res = manifest.Manifest.GetDirectDependencies(Path.GetFileName(path));
            //创建一个队列
            Queue <string> resQue = new Queue <string>();

            foreach (var r in res)
            {
                string _path = Path.GetDirectoryName(path) + "/" + Path.GetFileName(r);
                _path = _path.Replace("\\", "/");
                var key = Path.GetFileName(_path);
                if (AssetbundleMap.ContainsKey(key) == false)
                {
                    resQue.Enqueue(_path);
                }
                else
                {
                    AssetbundleMap[key].Use();
                }
            }

            if (AssetbundleMap.ContainsKey(Path.GetFileName(path)) == false)
            {
                resQue.Enqueue(path);
            }



            //开始加载队列
            IEnumeratorTool.StartCoroutine(IELoadAssetBundles(resQue, sucessCallback));
        }
Esempio n. 27
0
        /// <summary>
        /// 加载ab
        /// </summary>
        /// <param name="path"></param>
        /// <param name="callback"></param>
        private void AsyncLoadAssetBundle(string path, Action <bool> callback)
        {
            //寻找ab的后缀名
            var mainAssetPath = GetAssetRealPath(path);

            if (mainAssetPath != null)
            {
                //1.依赖资源
                var res = manifest.Manifest.GetDirectDependencies(mainAssetPath).ToList();
                //2.主体资源
                res.Add(mainAssetPath);
                //开始加载队列
                IEnumeratorTool.StartCoroutine(IEAsyncLoadAssetbundle(res, callback));
            }
            else
            {
                BDebug.LogError("没有该资源:" + mainAssetPath);
                //没有该资源
                callback(false);
            }
        }
Esempio n. 28
0
 /// <summary>
 /// runtime下加载,只读
 /// </summary>
 /// <param name="str"></param>
 static public void LoadOnRuntime(string path)
 {
     Connection?.Dispose();
     //用当前平台目录进行加载
     path = GetDBPath(path, Application.platform);
     if (File.Exists(path))
     {
         Connection = new SQLiteConnection(path, SQLiteOpenFlags.ReadOnly);
         BDebug.Log("DB加载路径:" + path, "red");
     }
     else if (!Application.isEditor)
     {
         //执行手机端操作,进行寻址 方便测试
         IEnumeratorTool.StartCoroutine(IE_LoadSqliteOnMobile());
         BDebug.Log("DB加载路径:" + path, "red");
     }
     else
     {
         Debug.LogError("DB不存在:" + path);
     }
 }
Esempio n. 29
0
        /// <summary>
        /// 分组执行任务,每组加载ASYNC_TASK_NUM个任务
        /// </summary>
        public void DoNextTask()
        {
            if (isStop)
            {
                return;
            }
            //获取一个任务
            while (taskList.Count > 0 && curDoTaskConter < ASYNC_TASK_NUM)
            {
                var task = taskList[0];
                taskList.RemoveAt(0);
                //这一步确保主资源最后加载,防止资源自动依赖丢失
                if (task.IsMainAsset && taskList.Count != 0)
                {
                    taskList.Add(task);
                    continue;
                }

                //主资源才加载
                IEnumeratorTool.StartCoroutine(IE_AsyncLoadAssetbundle(task, (ret, obj) =>
                {
                    curDoTaskConter--;
                    switch (ret)
                    {
                    case LoadAssetState.IsLoding:
                        //正在加载,需要重新执行一次task 插入在倒数第二个位置
                        taskList.Insert(taskList.Count - 2, task);
                        break;

                    case LoadAssetState.Fail:
                    case LoadAssetState.Success:
                        OnTaskComplete(task, obj);
                        break;
                    }
                }));

                curDoTaskConter++;
            }
        }
Esempio n. 30
0
        /// <summary>
        /// 加载ab
        /// </summary>
        /// <param name="path"></param>
        /// <param name="callback"></param>
        private void AsyncLoadAssetBundle(string path, Action <bool> callback)
        {
            //ab存储的是asset下的相对目录
            path = "assets/resource/runtime/" + path.ToLower() + ".";
            //寻找ab的后缀名
            var mainAssetPath = GetExistPath(path);

            if (mainAssetPath != null)
            {
                //1.依赖资源
                var res = manifest.Manifest.GetDirectDependencies(mainAssetPath).ToList();
                //2.主体资源
                res.Add(mainAssetPath);
                //开始加载队列
                IEnumeratorTool.StartCoroutine(IEAsyncLoadAssetbundle(res, callback));
            }
            else
            {
                BDebug.LogError("没有该资源:" + path);
                //没有该资源
                callback(false);
            }
        }