Пример #1
0
        static AsyncOperationSet GetAssetBundleRequestTable(AssetBundle assetBundle, AssetEntryRecord assetEntryRecord)
        {
            string             assetName = assetBundle.GetAllAssetNames().FirstOrDefault();
            AssetBundleRequest request   = assetBundle.LoadAssetAsync(assetName);

            return(AsyncOperationSet.CreateByAssetBundleRequest(request));
        }
Пример #2
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));
        }
Пример #3
0
        static AsyncOperationSet GetAssetBundleRequestScene(AssetBundle assetBundle, AssetEntryRecord assetEntryRecord)
        {
            string         sceneName = AssetBundleUtility.GetSceneName(assetEntryRecord.AssetName);
            AsyncOperation operation = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Single);

            return(AsyncOperationSet.CreateByAsyncOperation(operation));
        }
Пример #4
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);
        }
Пример #5
0
 public void LoadScene(
     AssetEntryRecord assetEntryRecord,
     IReadOnlyList <AssetBundleRecord> necessaryAssetBundleRecords)
 {
     AddLodingTask(
         assetEntryRecord,
         necessaryAssetBundleRecords,
         null,
         LinkerFuncs.Scene.GetAssetBundleRequestFunc,
         LinkerFuncs.Scene.GetAssetFunc);
 }
Пример #6
0
 public void LoadPrefab <T>(
     AssetEntryRecord assetEntryRecord,
     IReadOnlyList <AssetBundleRecord> necessaryAssetBundleRecords,
     Action <T> onLoaded) where T : Component
 {
     AddLodingTask(
         assetEntryRecord,
         necessaryAssetBundleRecords,
         onLoaded,
         LinkerFuncs.Prefab <T> .GetAssetBundleRequestFunc,
         LinkerFuncs.Prefab <T> .GetAssetFunc);
 }
Пример #7
0
 public void LoadMultipleAssets <T>(
     AssetEntryRecord assetEntryRecord,
     IReadOnlyList <AssetBundleRecord> necessaryAssetBundleRecords,
     Action <T[]> onLoaded) where T : UnityEngine.Object
 {
     AddLodingTask(
         assetEntryRecord,
         necessaryAssetBundleRecords,
         onLoaded,
         LinkerFuncs.Multiple <T> .GetAssetBundleRequestFunc,
         LinkerFuncs.Multiple <T> .GetAssetFunc);
 }
Пример #8
0
 public void LoadAsset <T>(
     AssetEntryRecord assetEntryRecord,
     FixedList <AssetBundleRecord> necessaryAssetBundleRecords,
     Action <T> onLoaded) where T : UnityEngine.Object
 {
     AddLodingTask(
         assetEntryRecord,
         necessaryAssetBundleRecords,
         onLoaded,
         LinkerFuncs.Single <T> .GetAssetBundleRequestFunc,
         LinkerFuncs.Single <T> .GetAssetFunc);
 }
Пример #9
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);
        }
Пример #10
0
        public static AssetEntryRecordCandidate Create(string assetPath, string assetBundleName)
        {
            // enumerate files in "resources" folder only
            int keyWordPosition = assetPath.IndexOf(ResourcesKeyWord);

            if (keyWordPosition < 0)
            {
                return(null);
            }

            string assetEntryKey = RemoveTags(assetPath.Substring(keyWordPosition + ResourcesKeyWord.Length));

            var assetEntryRecord = new AssetEntryRecord(assetEntryKey, assetBundleName, assetPath);

            return(new AssetEntryRecordCandidate(assetEntryRecord, GetTags(assetPath)));
        }
Пример #11
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);
        }
Пример #12
0
        AssetEntryRecord GetAssetEntryRecord <T>(string assetEntryKey, Action <T> onLoaded) where T : class
        {
            if (!IsTableLoaded)
            {
                errorReceiver.OnError(AssetBundleErrorCode.TableNotFound, "has not loaded asset bundle table");
                return(null);
            }

            AssetEntryRecord assetEntryRecord = this.Table.AssetEntryRecordMap.Get(assetEntryKey);

            if (assetEntryRecord == null)
            {
                errorReceiver.OnNotFoundError(AssetBundleErrorCode.EntryKeyNotFound, $"cannot find asset entry key: {assetEntryKey}", onLoaded);
                return(null);
            }

            return(assetEntryRecord);
        }
Пример #13
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);
        }
Пример #14
0
        static AssetBundleRequest GetAssetBundleRequestTable(AssetBundle assetBundle, AssetEntryRecord assetEntryRecord)
        {
            string assetName = assetBundle.GetAllAssetNames().FirstOrDefault();

            return(assetBundle.LoadAssetAsync(assetName));
        }
Пример #15
0
        static AssetBundleRequest GetAssetBundleRequestMultiple <T>(AssetBundle assetBundle, AssetEntryRecord assetEntryRecord) where T : UnityEngine.Object
        {
            string assetName = assetEntryRecord.AssetName;

            return(assetBundle.LoadAssetWithSubAssetsAsync <T>(assetName));
        }
Пример #16
0
        public AssetEntryRecordCandidate(AssetEntryRecord assetEntryRecord, IEnumerable <string> tags)
        {
            this.AssetEntryRecord = assetEntryRecord;

            this.tags = new FixedHashSet <string>(tags.Distinct());
        }
Пример #17
0
        void AddLodingTask <T>(
            AssetEntryRecord assetEntryRecord,
            IReadOnlyList <AssetBundleRecord> necessaryAssetBundleRecords,
            Action <T> onLoaded,
            Func <AssetBundle, AssetEntryRecord, AsyncOperationSet> getAssetBundleRequestFunc,
            Func <AssetBundleRequest, T> getAssetFunc)
        {
            if (isDestructed)
            {
                return;
            }

            int         loadingTaskId        = loadingTaskIdGenerator.Get();
            IEnumerator enumeratorToGetAsset = GetAsset(
                loadingTaskId,
                assetEntryRecord,
                necessaryAssetBundleRecords,
                onLoaded,
                getAssetBundleRequestFunc,
                getAssetFunc);
            var loadingTask = new LoadingTask(necessaryAssetBundleRecords, enumeratorToGetAsset);

            loadingTasks.Add(loadingTaskId, loadingTask);

            foreach (AssetBundleRecord assetBundleRecord in necessaryAssetBundleRecords)
            {
                string        assetBundleName = assetBundleRecord.AssetBundleName;
                HashSet <int> taskIds;
                if (!loadingTaskIdSets.TryGetValue(assetBundleName, out taskIds))
                {
                    taskIds = HashSetPool <int> .Pool.Get();

                    loadingTaskIdSets.Add(assetBundleName, taskIds);
                }

                taskIds.Add(loadingTaskId);
            }

            if (loadingTask.NecessaryAssetBundleRecords.All(r => loadedAssetBundles.ContainsKey(r.AssetBundleName)))
            {
                coroutineOwner.Run(loadingTask.EnumeratorToGetAsset);
                return;
            }

            foreach (AssetBundleRecord assetBundleRecord in loadingTask.NecessaryAssetBundleRecords)
            {
                string assetBundleName = assetBundleRecord.AssetBundleName;

                if (loadedAssetBundles.ContainsKey(assetBundleName))
                {
                    continue;
                }

                if (loadingAssetBundleRecords.ContainsKey(assetBundleName))
                {
                    continue;
                }

                loadingAssetBundleRecords.Add(assetBundleName, assetBundleRecord);
                storageChecker.Load(assetBundleRecord, onAssetBundleLoaded);
            }
        }
Пример #18
0
        static AsyncOperationSet GetAssetBundleRequestMultiple <T>(AssetBundle assetBundle, AssetEntryRecord assetEntryRecord) where T : UnityEngine.Object
        {
            string             assetName = assetEntryRecord.AssetName;
            AssetBundleRequest request   = assetBundle.LoadAssetWithSubAssetsAsync <T>(assetName);

            return(AsyncOperationSet.CreateByAssetBundleRequest(request));
        }