Exemple #1
0
        bool TryLoadFromLocalStorage(AssetBundleRecord assetBundleRecord, Action <LoaderResult> onFinished)
        {
            var localPath = AssetBundleUtility.GetLocalStoragePath(assetBundleRecord.AssetBundleName);

            if (!File.Exists(localPath))
            {
                return(false);
            }

            Debug.Log($"load from local storage: {localPath}");

            byte[] bytes;
            try
            {
                using (FileStream fileStream = new FileStream(localPath, FileMode.Open, FileAccess.Read))
                {
                    bytes = new byte[fileStream.Length];
                    fileStream.Read(bytes, 0, bytes.Length);
                    fileStream.Close();
                }
            }
            catch (Exception e)
            {
                Debug.LogError(e);
                return(false);
            }

            var result = new LoaderResult(assetBundleRecord, bytes, null);

            onFinished.Invoke(result);
            return(true);
        }
Exemple #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));
        }
Exemple #3
0
        static AsyncOperationSet GetAssetBundleRequestSceneAdditive(AssetBundle assetBundle, AssetEntryRecord assetEntryRecord)
        {
            string         sceneName = AssetBundleUtility.GetSceneName(assetEntryRecord.AssetName);
            AsyncOperation operation = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);

            return(AsyncOperationSet.CreateByAsyncOperation(operation));
        }
Exemple #4
0
        public IEnumerator LoadAsync(AssetBundleRecord assetBundleRecord, Action <LoaderResult> onFinished)
        {
            string path = $"{url}{assetBundleRecord.AssetBundleName}";

            Debug.Log($"download from web: {path}");

            var request = UnityWebRequest.Get(path);

            request.downloadHandler = new DownloadHandlerBuffer();
            request.SendWebRequest();
            yield return(null);

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

            if (request.isHttpError || request.isNetworkError)
            {
                var errorResult = new LoaderResult(assetBundleRecord, null, AssetBundleDownloadErrorType.Network);
                onFinished.Invoke(errorResult);
                yield break;
            }

            byte[] bytes     = request.downloadHandler.data;
            var    localPath = AssetBundleUtility.GetLocalStoragePath(assetBundleRecord.AssetBundleName);

            try
            {
                var dirPath = Path.GetDirectoryName(localPath);
                if (!Directory.Exists(dirPath))
                {
                    Directory.CreateDirectory(dirPath);
                }

                using (FileStream fileStream = new FileStream(localPath, FileMode.OpenOrCreate, FileAccess.Write))
                {
                    fileStream.Write(bytes, 0, bytes.Length);
                    fileStream.Close();
                }
            }
            catch (Exception e)
            {
                Debug.LogError(e);
                var errorResult = new LoaderResult(assetBundleRecord, bytes, AssetBundleDownloadErrorType.IO);
                onFinished.Invoke(errorResult);
                yield break;
            }

            var successResult = new LoaderResult(assetBundleRecord, bytes, null);

            onFinished.Invoke(successResult);
        }
        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);
        }
Exemple #6
0
 public Downloader(string url)
 {
     this.url = AssetBundleUtility.CheckEndSlash(url);
 }