コード例 #1
0
        void FinishLoadingTask(int loadingTaskId, FixedList <AssetBundleRecord> necessaryAssetBundleRecords)
        {
            foreach (AssetBundleRecord assetBundleRecord in necessaryAssetBundleRecords)
            {
                string assetBundleName = assetBundleRecord.AssetBundleName;

                HashSet <int> taskIds = loadingTaskIdSets.GetValue(assetBundleName);
                if (taskIds == null)
                {
                    errorReceiver.OnError(AssetBundleErrorCode.MissingTaskIdSetInTermination, $"cannot get task id set: {assetBundleName}");
                    return;
                }

                if (!taskIds.TryRemove(loadingTaskId))
                {
                    errorReceiver.OnError(AssetBundleErrorCode.FailureToRemoveTaskId, $"cannot remove task id: {assetBundleName}");
                    return;
                }

                if (taskIds.IsEmpty())
                {
                    if (!loadingTaskIdSets.TryRemove(assetBundleName))
                    {
                        errorReceiver.OnError(AssetBundleErrorCode.FailureToRemoveLoadingTaskIdSet, $"cannot remove loading task id set: {assetBundleName}");
                        return;
                    }
                    intHashSetPool.Put(taskIds);

                    AssetBundle unusingAssetBundle = loadedAssetBundles.GetValue(assetBundleName);
                    if (unusingAssetBundle == null)
                    {
                        errorReceiver.OnError(AssetBundleErrorCode.MissingLoadedAssetBundle, $"cannot get loaded asset bundle: {assetBundleName}");
                        return;
                    }

                    unusingAssetBundle.Unload(false);

                    if (!loadedAssetBundles.TryRemove(assetBundleName))
                    {
                        errorReceiver.OnError(AssetBundleErrorCode.FailureToRemoveLoadedAssetBundle, $"cannot remove loaded asset bundle: {assetBundleName}");
                        return;
                    }
                }
            }

            if (!loadingTasks.TryRemove(loadingTaskId))
            {
                errorReceiver.OnError(AssetBundleErrorCode.FailureToRemoveLoadingTask, "cannot remove loading task");
                return;
            }
        }