Пример #1
0
        IEnumerator LoadMultipleAssetsAsync <T>(string assetEntryKey, Action <T[]> onLoaded) where T : UnityEngine.Object
        {
            while (TimeUtility.DropFrameExists())
            {
                yield return(null);
            }

#if UNITY_EDITOR
            if (localMode)
            {
                string localFilePath = GetLocalFilePath(assetEntryKey);

                T[] localAsset = Resources.LoadAll <T>(localFilePath);
                if (localAsset != null)
                {
                    while (linker.IsPaused || TimeUtility.DropFrameExists())
                    {
                        yield return(null);
                    }

                    onLoaded?.Invoke(localAsset);
                    yield break;
                }
            }
#endif
            AssetEntryRecord assetEntryRecord = GetAssetEntryRecord(assetEntryKey, onLoaded);
            if (assetEntryRecord == null)
            {
                yield break;
            }

            linker.LoadMultipleAssets <T>(assetEntryRecord, this.Table.GetNecessaryAssetBundleRecords(assetEntryKey), onLoaded);
        }
Пример #2
0
        IEnumerator ClearAsync()
        {
            foreach (string filePath in Directory.GetFiles(AssetBundleUtility.GetLocalStoragePath(string.Empty), "*", SearchOption.AllDirectories))
            {
                if (protectingFilePaths.Contains(filePath))
                {
                    continue;
                }

                try
                {
                    File.Delete(filePath);
                }
                catch (Exception e)
                {
                    Debug.LogError(e);
                }

                if (TimeUtility.DropFrameExists())
                {
                    yield return(null);
                }
            }

            this.IsFinished = true;
        }
Пример #3
0
        IEnumerator Start()
        {
            foreach (Action action in StaticFieldRestarter.EnumerateRestartActions())
            {
                if (TimeUtility.DropFrameExists())
                {
                    yield return(null);
                }
                action.Invoke();
            }

            if (TimeUtility.DropFrameExists())
            {
                yield return(null);
            }
            Resources.UnloadUnusedAssets();

            if (TimeUtility.DropFrameExists())
            {
                yield return(null);
            }
            GC.Collect();


            if (TimeUtility.DropFrameExists())
            {
                yield return(null);
            }
            SceneManager.LoadSceneAsync("Permanent");
        }
Пример #4
0
        IEnumerator LoadSceneAdditiveAsync(string assetEntryKey)
        {
            while (TimeUtility.DropFrameExists())
            {
                yield return(null);
            }

#if UNITY_EDITOR
            if (localMode)
            {
                string         sceneName      = AssetBundleUtility.GetSceneName(assetEntryKey);
                AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
                while (!asyncOperation.isDone)
                {
                    yield return(null);
                }
                yield break;
            }
#endif
            string           loweredAssetEntryKey = assetEntryKey.ToLower();
            AssetEntryRecord assetEntryRecord     = GetAssetEntryRecord <UnityEngine.Object>(loweredAssetEntryKey, null);
            if (assetEntryRecord == null)
            {
                yield break;
            }

            linker.LoadSceneAdditive(assetEntryRecord, this.Table.GetNecessaryAssetBundleRecords(loweredAssetEntryKey));
        }
Пример #5
0
        IEnumerator LoadTableAsync(bool forciblyDownload)
        {
            isTableLoading = true;

#if UNITY_EDITOR
            if (localMode)
            {
                string          localFilePath   = GetLocalFilePath(tablePath);
                ResourceRequest resourceRequest = Resources.LoadAsync(localFilePath);
                while (!resourceRequest.isDone)
                {
                    yield return(null);
                }

                var localAsset = resourceRequest.asset as UnityEngine.Object;
                if (localAsset != null)
                {
                    while (linker.IsPaused || TimeUtility.DropFrameExists())
                    {
                        yield return(null);
                    }

                    OnTableAssetBundleLoaded(localAsset);
                    yield break;
                }
            }
#endif

            if (forciblyDownload)
            {
                // delete table cache
                string localTablePath = AssetBundleUtility.GetLocalStoragePath(tablePath);

                try
                {
                    if (File.Exists(localTablePath))
                    {
                        File.Delete(localTablePath);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError(e);
                    errorReceiver.OnError(AssetBundleErrorCode.FailureToDeleteTable, $"cannot delete table: {tablePath}");
                    yield break;
                }
            }

            linker.LoadTableAsset(tablePath, OnTableAssetBundleLoaded);
        }
Пример #6
0
        IEnumerator GetAsset <T>(
            int loadingTaskId,
            AssetEntryRecord assetEntryRecord,
            IReadOnlyList <AssetBundleRecord> necessaryAssetBundleRecords,
            Action <T> onLoaded,
            Func <AssetBundle, AssetEntryRecord, AsyncOperationSet> getAssetbundleRequestFunc,
            Func <AssetBundleRequest, T> getAssetFunc)
        {
            if (assetEntryRecord == null)
            {
                errorReceiver.OnError(AssetBundleErrorCode.MissingAssetEntryRecord, $"null asset entry record");
                yield break;
            }

            AssetBundle assetBundle = loadedAssetBundles.GetValue(assetEntryRecord.AssetBundleName);

            if (assetBundle == null)
            {
                errorReceiver.OnError(AssetBundleErrorCode.MissingAssetBundleName, $"cannot get asset bundle: AssetEntryKey={assetEntryRecord.AssetEntryKey}, AssetBundleName={assetEntryRecord.AssetBundleName}");
                yield break;
            }

            AsyncOperationSet asyncOperationSet = getAssetbundleRequestFunc.Invoke(assetBundle, assetEntryRecord);
            AsyncOperation    asyncOperation    = asyncOperationSet.AsyncOperation;

            while (!asyncOperation.isDone)
            {
                yield return(null);
            }

            AssetBundleRequest assetBundleRequest = asyncOperationSet.AssetBundleRequest;
            T asset = getAssetFunc.Invoke(assetBundleRequest);

            if (assetBundleRequest != null && asset == null)
            {
                errorReceiver.OnError(AssetBundleErrorCode.FailureToRemoveTaskId, $"cannot get asset: AssetEntryKey={assetEntryRecord.AssetEntryKey}, AssetBundleName={assetEntryRecord.AssetBundleName}, AssetName={assetEntryRecord.AssetName}");
                yield break;
            }

            while (this.IsPaused || TimeUtility.DropFrameExists())
            {
                yield return(null);
            }

            onLoaded?.Invoke(asset);

            FinishLoadingTask(loadingTaskId, necessaryAssetBundleRecords);
        }
Пример #7
0
        IEnumerator LoadAsync <T>(string assetEntryKey, Action <T> onLoaded) where T : UnityEngine.Object
        {
            while (TimeUtility.DropFrameExists())
            {
                yield return(null);
            }

#if UNITY_EDITOR
            if (localMode)
            {
                if (typeof(T).IsSubclassOf(typeof(Component)))
                {
                    string message = $"must use LoadPrefab<T> instead of Load<T>: {assetEntryKey}";
                    errorReceiver.OnError(AssetBundleErrorCode.InvalidType, message);
                    yield break;
                }

                string          localFilePath   = GetLocalFilePath(assetEntryKey);
                ResourceRequest resourceRequest = Resources.LoadAsync <T>(localFilePath);
                while (!resourceRequest.isDone)
                {
                    yield return(null);
                }

                var localAsset = resourceRequest.asset as T;
                if (localAsset != null)
                {
                    while (linker.IsPaused || TimeUtility.DropFrameExists())
                    {
                        yield return(null);
                    }

                    onLoaded?.Invoke(localAsset);
                    yield break;
                }
            }
#endif
            string           loweredAssetEntryKey = assetEntryKey.ToLower();
            AssetEntryRecord assetEntryRecord     = GetAssetEntryRecord(loweredAssetEntryKey, onLoaded);
            if (assetEntryRecord == null)
            {
                yield break;
            }

            linker.LoadAsset <T>(assetEntryRecord, this.Table.GetNecessaryAssetBundleRecords(loweredAssetEntryKey), onLoaded);
        }
        IEnumerator CheckQueueAsync()
        {
            while (taskDictionary.Count > 0)
            {
                while (assetBundleRecordQueue.Count > 0 && downloadingCount < MaxDownloadingCount)
                {
                    AssetBundleRecord record = assetBundleRecordQueue.Dequeue();
                    coroutineOwner.Run(downloader.LoadAsync(record, downloadFinishedAction));
                    downloadingCount++;

                    if (TimeUtility.DropFrameExists())
                    {
                        break;
                    }
                }

                yield return(null);
            }

            isCheckingQueue = false;
        }
Пример #9
0
        IEnumerator LoadPrefabAsync <T>(string assetEntryKey, Action <T> onLoaded) where T : Component
        {
            while (TimeUtility.DropFrameExists())
            {
                yield return(null);
            }

#if UNITY_EDITOR
            if (localMode)
            {
                string          localFilePath   = GetLocalFilePath(assetEntryKey);
                ResourceRequest resourceRequest = Resources.LoadAsync <T>(localFilePath);
                while (!resourceRequest.isDone)
                {
                    yield return(null);
                }

                T localAsset = resourceRequest.asset as T;
                if (localAsset != null)
                {
                    while (linker.IsPaused || TimeUtility.DropFrameExists())
                    {
                        yield return(null);
                    }

                    onLoaded?.Invoke(localAsset);
                    yield break;
                }
            }
#endif
            string           loweredAssetEntryKey = assetEntryKey.ToLower();
            AssetEntryRecord assetEntryRecord     = GetAssetEntryRecord(loweredAssetEntryKey, onLoaded);
            if (assetEntryRecord == null)
            {
                yield break;
            }

            linker.LoadPrefab <T>(assetEntryRecord, this.Table.GetNecessaryAssetBundleRecords(loweredAssetEntryKey), onLoaded);
        }