示例#1
0
        public static LoadAssetOperation LoadAssetAsync(string assetBundleName, string assetName, System.Type type, bool preferential, LoadAssetCallback callback = null, object callbackParam = null)
        {
            LoadAssetOperation operation = null;

            if (pAssetBundleMode == ResourceMode.Debug_SimulativeAssetBundle)
            {
#if UNITY_EDITOR
                operation = new AssetBundleLoadAssetOperationSimulation(null);

                if (string.IsNullOrEmpty(assetName) || assetName.Equals("NULL") || assetName.Equals("null"))
                {
                }
                else
                {
                    string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, assetName);
                    if (assetPaths.Length == 0)
                    {
                        Utility.LogError("There is no asset with name \"" + assetName + "\" in " + assetBundleName);
                        if (callback != null)
                        {
                            callback(null, callbackParam as ResourceLoadParam);
                        }
                        return(null);
                    }
                    UnityEngine.Object target = AssetDatabase.LoadMainAssetAtPath(assetPaths[0]);
                    operation.LoadedAsset = target;
                }
                operation.Callback      = callback;
                operation.CallbackParam = callbackParam;
                if (preferential)
                {
                    WaitingOperations.Insert(0, operation);
                }
                else
                {
                    WaitingOperations.Add(operation);
                }
                return(operation);
#endif
            }
            else if (pAssetBundleMode == ResourceMode.Release_Resources || pAssetBundleMode == ResourceMode.Debug_Resources)
            {
                operation = new ResourceLoadAssetOperation()
                {
                    AssetName = assetName, AssetBundleName = assetBundleName, AssetType = type
                };
                operation.Callback      = callback;
                operation.CallbackParam = callbackParam;
                if (preferential)
                {
                    WaitingOperations.Insert(0, operation);
                }
                else
                {
                    WaitingOperations.Add(operation);
                }
                Utility.LogDebug("LoadAssetAsync: " + assetBundleName + "   mWaitingOperations: " + WaitingOperations.Count);
            }
            else
            {
                assetBundleName = RemapVariantName(assetBundleName);
                LoadAssetBundle(assetBundleName);
                operation               = new AssetBundleLoadAssetOperation(assetBundleName, assetName, type);
                operation.Callback      = callback;
                operation.CallbackParam = callbackParam;
                if (preferential)
                {
                    WaitingOperations.Insert(0, operation);
                }
                else
                {
                    WaitingOperations.Add(operation);
                }
            }
            return(operation);
        }
示例#2
0
 public static LoadAssetOperation IsInProgress(string assetbundleName, string assetName)
 {
     if (InProgressOperations != null && InProgressOperations.Count > 0)
     {
         for (int i = 0; i < InProgressOperations.Count; i++)
         {
             LoadAssetOperation operation = InProgressOperations[i] as LoadAssetOperation;
             if (operation == null)
             {
                 continue;
             }
             if (IsResourceMode)
             {
                 if (string.IsNullOrEmpty(operation.AssetBundleName))
                 {
                     continue;
                 }
                 if (operation.AssetBundleName.Equals(assetbundleName))
                 {
                     return(operation);
                 }
             }
             else
             {
                 if (string.IsNullOrEmpty(operation.AssetBundleName) || string.IsNullOrEmpty(operation.AssetName))
                 {
                     continue;
                 }
                 if (operation.AssetBundleName.Equals(assetbundleName) && operation.AssetName.Equals(assetName))
                 {
                     return(operation);
                 }
             }
         }
     }
     if (WaitingOperations != null && WaitingOperations.Count > 0)
     {
         for (int i = 0; i < WaitingOperations.Count; i++)
         {
             LoadAssetOperation operation = WaitingOperations[i] as LoadAssetOperation;
             if (operation == null)
             {
                 continue;
             }
             if (IsResourceMode)
             {
                 if (string.IsNullOrEmpty(operation.AssetBundleName))
                 {
                     continue;
                 }
                 if (operation.AssetBundleName.Equals(assetbundleName))
                 {
                     return(operation);
                 }
             }
             else
             {
                 if (string.IsNullOrEmpty(operation.AssetBundleName) || string.IsNullOrEmpty(operation.AssetName))
                 {
                     continue;
                 }
                 if (operation.AssetBundleName.Equals(assetbundleName) && operation.AssetName.Equals(assetName))
                 {
                     return(operation);
                 }
             }
         }
     }
     if (UIOperations != null && UIOperations.Count > 0)
     {
         for (int i = 0; i < UIOperations.Count; i++)
         {
             LoadAssetOperation operation = UIOperations[i] as LoadAssetOperation;
             if (operation == null)
             {
                 continue;
             }
             if (IsResourceMode)
             {
                 if (string.IsNullOrEmpty(operation.AssetBundleName))
                 {
                     continue;
                 }
                 if (operation.AssetBundleName.Equals(assetbundleName))
                 {
                     return(operation);
                 }
             }
             else
             {
                 if (string.IsNullOrEmpty(operation.AssetBundleName) || string.IsNullOrEmpty(operation.AssetName))
                 {
                     continue;
                 }
                 if (operation.AssetBundleName.Equals(assetbundleName) && operation.AssetName.Equals(assetName))
                 {
                     return(operation);
                 }
             }
         }
     }
     return(null);
 }
示例#3
0
        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);
            }
        }