Esempio n. 1
0
        public static IEnumerator AssetBundleLoop()
        {
            while (true)
            {
                while (hasTaskToFinish == false)
                {
                    yield return(new WaitForEndOfFrame());
                }
                //处理Task
                while (assetTaskQueue.Count > 0)
                {
                    AssetRequestTask current = assetTaskQueue.Dequeue();
                    //AssetBundle已经被读取
                    if (LoadedAssets.ContainsKey(current.GetABName()))
                    {
                        string assetPath = LoadedAssets[current.GetABName()].GetAllAssetNames()[0];

                        AssetBundleRequest abRequest = LoadedAssets[current.GetABName()].LoadAssetAsync(assetPath);

                        yield return(abRequest);

                        current.onAssetLoaded(abRequest.asset);
                    }
                    //AssetBundle尚未读取
                    else
                    {
                        //依赖包 Loop
                        string[] DependenciesInfo = assetBundleManifest.GetAllDependencies(current.GetABName());
                        for (int i = 0; i < DependenciesInfo.Length; i++)
                        {
                            if (LoadedAssets.ContainsKey(DependenciesInfo[i]))
                            {
                                continue;
                            }
                            bool isDependenceAssetLoaded = false;

                            MonoActiveObject.StartCoroutine(LoadAsset(DependenciesInfo[i], () => {
                                isDependenceAssetLoaded = true;
                            }));

                            while (!isDependenceAssetLoaded)
                            {
                                yield return(new WaitForFixedUpdate());
                            }
                        }
                        //主AB
                        bool isMainLoaded = false;

                        MonoActiveObject.StartCoroutine(LoadAsset(current.GetABName(), () => {
                            isMainLoaded = true;
                        }));

                        while (!isMainLoaded)
                        {
                            yield return(new WaitForFixedUpdate());
                        }

                        //添加回队列 等待队列回调
                        assetTaskQueue.Enqueue(current);
                    }
                }
                hasTaskToFinish = false;
            }
        }
Esempio n. 2
0
 public static void LoadAssetFromAssetBundle(AssetRequestTask assetRequestTask)
 {
     assetTaskQueue.Enqueue(assetRequestTask);
     hasTaskToFinish = true;
 }