コード例 #1
0
ファイル: ResContext.cs プロジェクト: l2xin/graduation-design
        public static LoadOperation LoadLevelAsync(string assetBundleName, string levelName, bool isAdditive)
        {
            Utility.LogDebug("Loading " + levelName + " from " + assetBundleName + " bundle");
            LoadOperation operation = null;

            if (pAssetBundleMode == ResourceMode.Debug_SimulativeAssetBundle ||
                pAssetBundleMode == ResourceMode.Debug_Resources || pAssetBundleMode == ResourceMode.Release_Resources)
            {
                operation = new LoadLevelSimulationOperation(assetBundleName, levelName, isAdditive);
            }
            else
            {
                assetBundleName = RemapVariantName(assetBundleName);
                LoadAssetBundle(assetBundleName);
                operation = new AssetBundleLoadLevelOperation(assetBundleName, levelName, isAdditive);
                InProgressOperations.Add(operation);
            }
            return(operation);
        }
コード例 #2
0
ファイル: ResContext.cs プロジェクト: l2xin/graduation-design
        IEnumerator LoadLooper()
        {
            while (true)
            {
                //if (mLoadLevelOperations.Count > 0)
                //{
                //    AssetBundleLoadLevelOperation operation = mLoadLevelOperations[0];
                //    mInProgressOperations.Add(operation);
                //    operation.Execute();
                //    ResourceManagerUtility.LogDebug("Looper yield return new Coroutine(AssetBundleLoadLevelOperation)  LevelName: " + operation.mLevelName);
                //    yield return StartCoroutine(operation);
                //    ResourceManagerUtility.LogDebug("Looper success  LevelName: " + operation.mLevelName);
                //    try
                //    {
                //        operation.Callback(operation.GetAsset());
                //    }
                //    catch (Exception e)
                //    {
                //        if (operation.GetType().IsSubclassOf(typeof(LoadAssetOperation)))
                //        {
                //            ResourceManagerUtility.LogError("Looper success,but some exception is occuried in callback, LevelName: " + operation.mLevelName + " Exception: " + e.Message);
                //        }
                //    }
                //    mLoadLevelOperations.Remove(operation);
                //}
                if (UIOperations.Count > 0)
                {
                    LoadOperation operation = UIOperations[0];
                    InProgressOperations.Add(operation);
                    operation.Execute();
                    Utility.LogDebug("Looper yield return new coroutine  " + (operation as LoadAssetOperation).AssetBundleName);
                    yield return(AppEnterance.GetInstance().StartCoroutine(operation));

                    Utility.LogDebug("Looper success  " + (operation as LoadAssetOperation).AssetBundleName);
                    try
                    {
                        operation.Finish(operation.GetAsset());
                    }
                    catch (Exception e)
                    {
                        if (operation.GetType().IsSubclassOf(typeof(LoadAssetOperation)))
                        {
                            Utility.LogError("Looper success,but some exception occuried: " + (operation as LoadAssetOperation).AssetBundleName + " Exception: " + e.Message);
                        }
                    }
                    UIOperations.Remove(operation);
                    if (UIOperations.Count > 0)
                    {
                        yield return(null);
                    }
                }
                if (BoolFastMode)
                {
                    if (CurrentOperations.Count > 0)
                    {
                        for (int i = 0; i < CurrentOperations.Count; i++)
                        {
                            LoadOperation operation = CurrentOperations[i];
                            if (operation.IsDone())
                            {
                                try
                                {
                                    //ResourceManagerUtility.LogDebug("Looper success  " + (operation as LoadAssetOperation).AssetBundleName);
                                    operation.Finish(operation.GetAsset());
                                }
                                catch (Exception e)
                                {
                                    if (operation.GetType().IsSubclassOf(typeof(LoadAssetOperation)))
                                    {
                                        Utility.LogError("Looper success,but some exception occuried: " + (operation as LoadAssetOperation).AssetBundleName + " Exception: " + e.Message);
                                    }
                                }
                                WaitingOperations.Remove(operation);
                                CurrentOperations.Remove(operation);
                                i--;
                            }
                            //else
                            //{
                            //    i++;
                            //}
                        }
                    }
                    if (CurrentOperations.Count == MAX_LOAD_COUNT)
                    {
                        Utility.LogError("Full task, current waiting count: " + WaitingOperations.Count);
                        yield return(null);
                    }
                }
                if (WaitingOperations.Count > 0)
                {
                    if (BoolFastMode)
                    {
                        int finalCount = Mathf.Min(MAX_LOAD_COUNT - CurrentOperations.Count, WaitingOperations.Count);
                        for (int i = 0; i < finalCount; i++)
                        {
                            LoadOperation operation = WaitingOperations[i];
                            InProgressOperations.Add(operation);
                            CurrentOperations.Add(operation);
                            operation.Execute();
                            Utility.LogDebug("add task:   final count: " + finalCount + "  name : " + (operation as LoadAssetOperation).AssetBundleName);
                            AppEnterance.GetInstance().StartCoroutine(operation);
                        }
                        yield return(null);
                    }
                    else
                    {
                        LoadOperation operation = WaitingOperations[0];
                        InProgressOperations.Add(operation);
                        operation.Execute();
                        Utility.LogDebug("Looper yield return new coroutine  " + (operation as LoadAssetOperation).AssetBundleName);
                        yield return(AppEnterance.GetInstance().StartCoroutine(operation));

                        Utility.LogDebug("Looper success  " + (operation as LoadAssetOperation).AssetBundleName);
                        try
                        {
                            operation.Finish(operation.GetAsset());
                        }
                        catch (Exception e)
                        {
                            LoadAssetOperation loadAssetOperation = operation as LoadAssetOperation;
                            if (loadAssetOperation != null && loadAssetOperation.GetType().IsSubclassOf(typeof(LoadAssetOperation)))
                            {
                                if (string.IsNullOrEmpty(loadAssetOperation.AssetBundleName) == false && string.IsNullOrEmpty(loadAssetOperation.AssetName) == false)
                                {
                                    Utility.LogError("Looper success,but some exception occuried, Task key: " + loadAssetOperation.AssetBundleName + "/" + loadAssetOperation.AssetName + ", Exception: " + e.Message + ", Track: " + e.StackTrace);
                                }
                                else
                                {
                                    Utility.LogError("Looper success,but some exception occuried, Exception: " + e.Message + ", Track: " + e.StackTrace);
                                }
                            }
                        }
                        WaitingOperations.Remove(operation);
                    }
                }
                yield return(null);
            }
        }