コード例 #1
0
        void Update()
        {
            if (loadingBundleQueue.Count > 0)
            {
                if (loadAssetBundleStep == LoadAssetBundleStep.PreLoad)
                {
                    loadAssetBundleStep  = LoadAssetBundleStep.Loading;
                    curLoadData          = loadingBundleQueue.Dequeue();
                    curLoadData.curState = LoadingAssetBundleData.State.Prepare;
                }
            }

            if (curLoadData != null && curLoadData.curState == LoadingAssetBundleData.State.Prepare)
            {
                LoadAssetBundleHandler();
            }
        }
コード例 #2
0
        public void GetAssetAsync(string bundleName, string assetName, Callback <UObject> callback)
        {
            if (!bundlesDic.ContainsKey(bundleName))
            {
                DebugUtils.LogError(DebugUtils.Type.AssetBundle, string.Format("AssetBundle \"{0}\" for this platform not found", bundleName));
                if (callback != null)
                {
                    callback(null);
                }
                return;
            }
            AssetBundleRef assetBundleRef = bundlesDic[bundleName];

            LoadingAssetBundleData loadData = new LoadingAssetBundleData();

            loadData.assetName = assetName;
            loadData.abRef     = assetBundleRef;
            CollectDepend(assetBundleRef, out loadData.dependRefList);
            loadData.assetLoadCompleteCall = callback;
            loadingBundleQueue.Enqueue(loadData);

            DebugUtils.Log(DebugUtils.Type.AssetBundle, string.Format("Prepare load bundle data \"{0}\" ,assetName is \"{1}\"", loadData.abRef.bundleName, loadData.assetName));
        }
コード例 #3
0
        private void LoadAssetBundleHandler()
        {
            switch (curLoadData.curState)
            {
            case LoadingAssetBundleData.State.Prepare:
            {
                DebugUtils.Log(DebugUtils.Type.AssetBundle, string.Format("Prepare load bundle is \"{0}\" ,assetName is \"{1}\"", curLoadData.abRef.bundleName, curLoadData.assetName));
                curLoadData.curState = LoadingAssetBundleData.State.LoadDepend;
                LoadAssetBundleHandler();
                break;
            }

            case LoadingAssetBundleData.State.LoadDepend:
            {
                int length = curLoadData.dependRefList == null ? 0 : curLoadData.dependRefList.Count;

                DebugUtils.Log(DebugUtils.Type.AssetBundle, "Prepare load depend bundles, number is : " + length);

                if (length == 0)
                {
                    curLoadData.curState = LoadingAssetBundleData.State.LoadBundle;
                    LoadAssetBundleHandler();
                    break;
                }

                int count = 0;
                for (int i = 0; i < length; i++)
                {
                    curLoadData.dependRefList[i].AddIncreaseDep(curLoadData.abRef.bundleName);

                    if (curLoadData.dependRefList[i].assetBundle != null)
                    {
                        if (++count == length)
                        {
                            curLoadData.curState = LoadingAssetBundleData.State.LoadBundle;
                            LoadAssetBundleHandler();
                        }
                        continue;
                    }

                    DebugUtils.Log(DebugUtils.Type.AssetBundle, "Start loading depend bundle : " + curLoadData.dependRefList[i].bundleName);
                    StartCoroutine(LoadBundleAsync(curLoadData.dependRefList[i].bundleName, delegate(AssetBundle ab, int index)
                        {
                            curLoadData.dependRefList[index].assetBundle = ab;
                            if (++count == length)
                            {
                                curLoadData.curState = LoadingAssetBundleData.State.LoadBundle;
                                LoadAssetBundleHandler();
                            }
                        }, i));
                }

                break;
            }

            case LoadingAssetBundleData.State.LoadBundle:
            {
                DebugUtils.Log(DebugUtils.Type.AssetBundle, "Prepare load bundle : " + curLoadData.abRef.bundleName);

                if (curLoadData.abRef.assetBundle != null)
                {
                    curLoadData.curState = LoadingAssetBundleData.State.LoadAsset;
                    LoadAssetBundleHandler();
                    break;
                }

                StartCoroutine(LoadBundleAsync(curLoadData.abRef.bundleName, delegate(AssetBundle ab, int index)
                    {
                        curLoadData.abRef.assetBundle = ab;
                        curLoadData.curState          = LoadingAssetBundleData.State.LoadAsset;
                        LoadAssetBundleHandler();
                    }));
                break;
            }

            case LoadingAssetBundleData.State.LoadAsset:
            {
                if (!curLoadData.assetName.Equals(preloadFlag))
                {
                    StartCoroutine(LoadAssetAsync(curLoadData.abRef.assetBundle, curLoadData.assetName, delegate(UObject obj)
                        {
                            curLoadData.abRef.AddRef(curLoadData.assetName);
                            curLoadData.assetLoadCompleteCall(obj);
#if UNITY_EDITOR
                            RestAssetShader(new UObject[] { obj });
#endif
                            curLoadData.curState = LoadingAssetBundleData.State.Complete;
                            LoadAssetBundleHandler();
                        }));
                }
                break;
            }

            case LoadingAssetBundleData.State.Complete:
            {
                curLoadData.Dispose();
                curLoadData         = null;
                loadAssetBundleStep = LoadAssetBundleStep.PreLoad;
                break;
            }
            }
        }