Exemplo n.º 1
0
        public void LoadTable(bool forciblyDownload)
        {
            if (IsTableLoaded)
            {
                errorReceiver.OnError(AssetBundleErrorCode.LoadedTable, "has already loaded asset bundle table");
                return;
            }

            if (isTableLoading)
            {
                errorReceiver.OnError(AssetBundleErrorCode.LoadingTable, "is loading asset bundle table");
                return;
            }

            coroutineOwner.Run(LoadTableAsync(forciblyDownload));
        }
Exemplo n.º 2
0
        void OnDownloadFinished(LoaderResult result)
        {
            var assetBundleName = result.AssetBundleRecord.AssetBundleName;
            Action <LoaderResult> onFinished;

            if (!actionDictionary.TryGetValue(assetBundleName, out onFinished))
            {
                errorReceiver.OnError(AssetBundleErrorCode.MissingFinishedAction, $"cannot find finished action: {assetBundleName}");
                return;
            }

            // release load async coroutine
            actionDictionary.Remove(assetBundleName);
            onFinished.Invoke(result);
        }
Exemplo n.º 3
0
        IEnumerator OnAssetBundleLoadedAsync(LoaderResult result)
        {
            string            assetBundleName = result.AssetBundleRecord.AssetBundleName;
            AssetBundleRecord assetBundleRecord;

            if (!loadingAssetBundleRecords.TryGetValue(assetBundleName, out assetBundleRecord))
            {
                errorReceiver.OnError(AssetBundleErrorCode.MissingLoadingAssetBundleRecord, $"cannot find loading asset bundle record: {assetBundleName}");
                yield break;
            }

            byte[] bytes = Decrypt(result.Bytes);
            if (bytes == null)
            {
                errorReceiver.OnError(AssetBundleErrorCode.FailureToDecrypt, $"cannot decrypt asset bundle: {assetBundleName}");
                yield break;
            }

            uint crc = assetBundleRecord.Crc;
            var  assetBundleRequest = AssetBundle.LoadFromMemoryAsync(bytes, crc);

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

            AssetBundle assetBundle = assetBundleRequest.assetBundle;

            if (assetBundle == null)
            {
                errorReceiver.OnError(AssetBundleErrorCode.FailureToGetAssetBundle, $"cannot get asset bundle: {assetBundleName}");
                yield break;
            }

            loadedAssetBundles.Add(assetBundleName, assetBundle);

            if (!loadingAssetBundleRecords.TryRemove(assetBundleName))
            {
                errorReceiver.OnError(AssetBundleErrorCode.FailureToRemoveLoadingAssetBundleRecord, $"cannot remove loading asset bundle record: {assetBundleName}");
                yield break;
            }

            HashSet <int> taskIds;

            if (!loadingTaskIdSets.TryGetValue(assetBundleName, out taskIds))
            {
                errorReceiver.OnError(AssetBundleErrorCode.MissingTaskIdSetInCheckingCompletion, $"cannot get task id set: {assetBundleName}");
                yield break;
            }

            List <IEnumerator> enumeratorsToGetAsset = ListPool <IEnumerator> .Pool.Get();

            foreach (int taskId in taskIds)
            {
                LoadingTask?nullableLoadingTask = loadingTasks.GetNullableValue(taskId);
                if (!nullableLoadingTask.HasValue)
                {
                    errorReceiver.OnError(AssetBundleErrorCode.MissingLoadingTask, $"cannot get loading task: {assetBundleName}");
                    yield break;
                }

                LoadingTask loadingTask = nullableLoadingTask.Value;
                if (loadingTask.NecessaryAssetBundleRecords.All(r => loadedAssetBundles.ContainsKey(r.AssetBundleName)))
                {
                    enumeratorsToGetAsset.Add(loadingTask.EnumeratorToGetAsset);
                }
            }

            foreach (IEnumerator enumerator in enumeratorsToGetAsset)
            {
                coroutineOwner.Run(enumerator);
            }

            ListPool <IEnumerator> .Pool.Put(ref enumeratorsToGetAsset);
        }