///<summary>Retrieves an AssetBundle from a remote server. Wraps <see cref="UnityWebRequestAssetBundle.GetAssetBundle"/> and uses the default AssetBundle cache ///<param name="url">The absolute URL to the GET endpoint</param> ///<param name="bundle">The RemoteAssetBundle struct</param> ///<param name="callback">An Action with signature (string, AssetBundle) Note - string will be null if there's no error</param> ///<returns>Returns an enumerator. The AssetBundle is available via the callback</returns> ///</summary> public static IEnumerator DownloadAssetBundleAsync(string url, RemoteAssetBundle bundle, System.Action <string, AssetBundle> callback) { string endpoint = string.Format("{0}/{1}?versionhash={2}", url, bundle.info.name, bundle.versionHash); CachedAssetBundle cachedBundle = new CachedAssetBundle(); cachedBundle.hash = bundle.toHash128(); cachedBundle.name = bundle.info.name; using (UnityWebRequest req = UnityWebRequestAssetBundle.GetAssetBundle(endpoint, cachedBundle, 0)) { yield return(req.SendWebRequest()); if (req.isNetworkError || req.isHttpError) { callback(req.error, null); } else { try { AssetBundle ab = DownloadHandlerAssetBundle.GetContent(req); callback(null, ab); } catch (System.Exception ex) { callback(ex.Message, null); } } } }
public static async Task <AssetBundle> GetAssetBundle(string url, CancellationTokenSource cancelationToken, System.Action <float> progress = null, bool caching = true) { UnityWebRequest request; CachedAssetBundle assetBundleVersion = await GetAssetBundleVersion(url); if (Caching.IsVersionCached(assetBundleVersion) || (caching && ResourceCache.CheckFreeSpace(await GetSize(url)))) { request = UnityWebRequestAssetBundle.GetAssetBundle(url, assetBundleVersion, 0); } else { request = UnityWebRequestAssetBundle.GetAssetBundle(url); } UnityWebRequest uwr = await SendWebRequest(request, cancelationToken, Caching.IsVersionCached(assetBundleVersion)?null : progress); if (uwr != null && !uwr.isHttpError && !uwr.isNetworkError) { AssetBundle assetBundle = DownloadHandlerAssetBundle.GetContent(uwr); if (caching) { // Deleting old versions from the cache Caching.ClearOtherCachedVersions(assetBundle.name, assetBundleVersion.hash); } return(assetBundle); } else { throw new Exception(string.Format("Netowrk.GetAssetBundle - {0} {1}", uwr.error, uwr.url)); } }
string AssetBundlePath(CachedAssetBundle cachedAssetBundle) { string assetDir = Caching.currentCacheForWriting.path; string assetBundleName = cachedAssetBundle.name; string hash = cachedAssetBundle.hash.ToString(); return($"{assetDir}/{assetBundleName}/{hash}/__data"); }
//================================================================================ // 関数 //================================================================================ /// <summary> /// UnityWebRequest を作成して返します /// </summary> private UnityWebRequest CreateWebRequest(IResourceLocation location) { var url = m_provideHandle.ResourceManager.TransformInternalId(location); if (m_options == null) { return(UnityWebRequestAssetBundle.GetAssetBundle(url)); } UnityWebRequest webRequest; if (!string.IsNullOrEmpty(m_options.Hash)) { var cachedBundle = new CachedAssetBundle ( m_options.BundleName, Hash128.Parse(m_options.Hash) ); if (m_options.UseCrcForCachedBundle || !Caching.IsVersionCached(cachedBundle)) { webRequest = UnityWebRequestAssetBundle.GetAssetBundle(url, cachedBundle, m_options.Crc); } else { webRequest = UnityWebRequestAssetBundle.GetAssetBundle(url, cachedBundle); } } else { webRequest = UnityWebRequestAssetBundle.GetAssetBundle(url, m_options.Crc); } if (0 < m_options.Timeout) { webRequest.timeout = m_options.Timeout; } if (0 < m_options.RedirectLimit) { webRequest.redirectLimit = m_options.RedirectLimit; } #if !UNITY_2019_3_OR_NEWER webRequest.chunkedTransfer = m_Options.ChunkedTransfer; #endif if (m_provideHandle.ResourceManager.CertificateHandlerInstance == null) { return(webRequest); } webRequest.certificateHandler = m_provideHandle.ResourceManager.CertificateHandlerInstance; webRequest.disposeCertificateHandlerOnDispose = false; return(webRequest); }
public AssetBundleHandle( string name, ref CachedAssetBundle cachedAssetBundle, string path) { this.name = name; _cachedAssetBundle = cachedAssetBundle; _path = path; Update(); }
public static UnityWebRequest GetAssetBundle(Uri uri, CachedAssetBundle cachedAssetBundle, uint crc = 0) { UnityWebRequest request = new UnityWebRequest( uri, UnityWebRequest.kHttpVerbGET, new DownloadHandlerAssetBundle(uri.AbsoluteUri, cachedAssetBundle, crc), null ); return(request); }
public static UnityWebRequest GetAssetBundle(string uri, CachedAssetBundle cachedAssetBundle, uint crc) { UnityWebRequest request = new UnityWebRequest( uri, UnityWebRequest.kHttpVerbGET, new DownloadHandlerAssetBundle(uri, cachedAssetBundle.name, cachedAssetBundle.hash, crc), null ); return(request); }
static int LoadFromCacheOrDownload(IntPtr L) { int count = LuaDLL.lua_gettop(L); if (count == 2 && LuaScriptMgr.CheckTypes(L, 1, typeof(string), typeof(Hash128))) { string arg0 = LuaScriptMgr.GetString(L, 1); Hash128 arg1 = (Hash128)LuaScriptMgr.GetLuaObject(L, 2); WWW o = WWW.LoadFromCacheOrDownload(arg0, arg1); LuaScriptMgr.Push(L, o); return(1); } else if (count == 2 && LuaScriptMgr.CheckTypes(L, 1, typeof(string), typeof(int))) { string arg0 = LuaScriptMgr.GetString(L, 1); int arg1 = (int)LuaDLL.lua_tonumber(L, 2); WWW o = WWW.LoadFromCacheOrDownload(arg0, arg1); LuaScriptMgr.Push(L, o); return(1); } else if (count == 3 && LuaScriptMgr.CheckTypes(L, 1, typeof(string), typeof(CachedAssetBundle), typeof(uint))) { string arg0 = LuaScriptMgr.GetString(L, 1); CachedAssetBundle arg1 = (CachedAssetBundle)LuaScriptMgr.GetLuaObject(L, 2); uint arg2 = (uint)LuaDLL.lua_tonumber(L, 3); WWW o = WWW.LoadFromCacheOrDownload(arg0, arg1, arg2); LuaScriptMgr.Push(L, o); return(1); } else if (count == 3 && LuaScriptMgr.CheckTypes(L, 1, typeof(string), typeof(Hash128), typeof(uint))) { string arg0 = LuaScriptMgr.GetString(L, 1); Hash128 arg1 = (Hash128)LuaScriptMgr.GetLuaObject(L, 2); uint arg2 = (uint)LuaDLL.lua_tonumber(L, 3); WWW o = WWW.LoadFromCacheOrDownload(arg0, arg1, arg2); LuaScriptMgr.Push(L, o); return(1); } else if (count == 3 && LuaScriptMgr.CheckTypes(L, 1, typeof(string), typeof(int), typeof(uint))) { string arg0 = LuaScriptMgr.GetString(L, 1); int arg1 = (int)LuaDLL.lua_tonumber(L, 2); uint arg2 = (uint)LuaDLL.lua_tonumber(L, 3); WWW o = WWW.LoadFromCacheOrDownload(arg0, arg1, arg2); LuaScriptMgr.Push(L, o); return(1); } else { LuaDLL.luaL_error(L, "invalid arguments to method: WWW.LoadFromCacheOrDownload"); } return(0); }
public static IObservable <AssetBundle> GetAssetBundle(string url, CachedAssetBundle cachedAssetBundle, uint crc, Dictionary <string, string> requestHeaderMap = null, IProgress <float> progress = null) { return(GetAssetBundle( #if UNITY_2018_1_OR_NEWER () => UnityWebRequestAssetBundle.GetAssetBundle(url, cachedAssetBundle, crc), #else () => UnityWebRequest.GetAssetBundle(url, cachedAssetBundle, crc), #endif requestHeaderMap, progress )); }
IEnumerator LoadAsset() { modelManager.loadingBunles.Add(ABName); #if UNITY_IOS BundleFullURL = PlayerPrefs.GetString("ApiUrl") + "/media/3d/" + ABName + "/ios/bundle"; #endif #if PLATFORM_ANDROID BundleFullURL = PlayerPrefs.GetString("ApiUrl") + "/media/3d/" + ABName + "/android/bundle"; #endif Debug.Log("Load bundle by: " + BundleFullURL); CachedAssetBundle cab = new CachedAssetBundle(ABName, new Hash128(0, 0)); using (UnityWebRequest uwr = UnityWebRequestAssetBundle.GetAssetBundle(BundleFullURL, cab)) { preloader.LoadPercent(uwr); yield return(uwr.SendWebRequest()); if (uwr.isNetworkError || uwr.isHttpError) { Debug.Log(uwr.error); preloader.CantLoad(); preloader.Loaded(); GetComponent <Collider>().enabled = false; GetComponent <Mover>().enabled = false; } else { // Get downloaded asset bundle AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(uwr); if (bundle.Contains(AssetName)) { Instantiate(bundle.LoadAssetAsync(AssetName).asset, gameObject.transform); modelManager.bundles.Add(bundle); modelManager.loadingBunles.Remove(ABName); mover.modelName = ABName; Debug.Log("is OBJ"); preloader.Loaded(); } else { Debug.Log("Check !loaded Asset name: " + AssetName); preloader.CantLoad(); preloader.Loaded(); GetComponent <Collider>().enabled = false; GetComponent <Mover>().enabled = false; } } } }
internal UnityWebRequest CreateWebRequest(string url) { if (m_Options == null) { return(UnityWebRequestAssetBundle.GetAssetBundle(url)); } UnityWebRequest webRequest; if (!string.IsNullOrEmpty(m_Options.Hash)) { CachedAssetBundle cachedBundle = new CachedAssetBundle(m_Options.BundleName, Hash128.Parse(m_Options.Hash)); #if ENABLE_CACHING if (m_Options.UseCrcForCachedBundle || !Caching.IsVersionCached(cachedBundle)) { webRequest = UnityWebRequestAssetBundle.GetAssetBundle(url, cachedBundle, m_Options.Crc); } else { webRequest = UnityWebRequestAssetBundle.GetAssetBundle(url, cachedBundle); } #else webRequest = UnityWebRequestAssetBundle.GetAssetBundle(url, cachedBundle, m_Options.Crc); #endif } else { webRequest = UnityWebRequestAssetBundle.GetAssetBundle(url, m_Options.Crc); } if (m_Options.Timeout > 0) { webRequest.timeout = m_Options.Timeout; } if (m_Options.RedirectLimit > 0) { webRequest.redirectLimit = m_Options.RedirectLimit; } #if !UNITY_2019_3_OR_NEWER webRequest.chunkedTransfer = m_Options.ChunkedTransfer; #endif if (m_ProvideHandle.ResourceManager.CertificateHandlerInstance != null) { webRequest.certificateHandler = m_ProvideHandle.ResourceManager.CertificateHandlerInstance; webRequest.disposeCertificateHandlerOnDispose = false; } m_ProvideHandle.ResourceManager.WebRequestOverride?.Invoke(webRequest); return(webRequest); }
public Object GetCachedAsset() { if (!CachedAssetBundle) { return(null); } Object[] assets = CachedAssetBundle.LoadAllAssets(); if (assets.Length > 0) { ReplaceShader(assets[0], string.Empty); return(assets[0]); } return(null); }
private IEnumerator LoadBundleRoutine(CachedAssetBundle cacheInfo, bool shouldBeCached) { var isCached = Caching.IsVersionCached(cacheInfo); Debug.Assert( isCached == shouldBeCached, $"Bundle was not cached when it should have been, should be cached: {shouldBeCached}, is cached: {isCached}"); using (var request = UnityWebRequestAssetBundle.GetAssetBundle(_bundleUrl, cacheInfo)) { yield return(request.SendWebRequest()); var bundle = DownloadHandlerAssetBundle.GetContent(request); bundle.Unload(true); } }
private IEnumerator Start() { // Define the caching information once. The same caching information is used for // every load, so we know the same version will be cached after the first load // completes. var cacheInfo = new CachedAssetBundle(_bundleUrl, Hash128.Compute(_bundleUrl)); do { // Ensure that we're starting with a clean cache each time. while (!Caching.ClearCache()) { yield return(true); } // Load the bundle once to populate the cache. We make sure this load // finishes before starting subsequent loads. Debug.Log("Loading bundle first time"); yield return(LoadBundleRoutine(cacheInfo, false)); Debug.Assert( Caching.IsVersionCached(cacheInfo), "Bundle was not cached after first load"); // Load the bundle from the cache twice concurrently. We use SpawnCoroutine() // to ensure that both loads will happen concurrently. The inner coroutine // yields while waiting for the bundle to load, so the third load is // guaranteed to start while the second one is in progress. Debug.Log("Spawning second load"); var secondLoad = StartCoroutine(LoadBundleRoutine(cacheInfo, true)); Debug.Assert( Caching.IsVersionCached(cacheInfo), "Bundle was not cached after second load"); Debug.Log("Spawning third load"); var thirdLoad = StartCoroutine(LoadBundleRoutine(cacheInfo, true)); Debug.Assert( Caching.IsVersionCached(cacheInfo), "Bundle was not cached after third load"); // Make sure all loading has finished before starting the next iteration. yield return(secondLoad); yield return(thirdLoad); } while (_runInLoop); }
HashSet <CachedAssetBundle> GetAllEntries(Func <int, string> keyNaming) { var cacheEntries = new HashSet <CachedAssetBundle>(); for (int i = 0; i < kAssetCount; i++) { var result = GetCacheEntries(keyNaming(i)); foreach (var entry in result) { CachedAssetBundle cab = new CachedAssetBundle(entry.Key, Hash128.Parse(entry.Value)); if (!cacheEntries.Contains(cab)) { cacheEntries.Add(cab); } } } return(cacheEntries); }
// ------------------------------------------- /* * Load the asset bundle */ public bool LoadAssetBundle(string _url, int _version) { if (!m_urlsBundle.Contains(_url)) { m_urlsBundle.Add(_url); #if UNITY_WEBGL DispatchAssetBundleEvent(EVENT_ASSETBUNDLE_ONE_TIME_LOADING_ASSETS); CachedAssetBundle cacheBundle = new CachedAssetBundle(); StartCoroutine(WebRequestAssetBundle(UnityWebRequestAssetBundle.GetAssetBundle(_url, cacheBundle))); #else StartCoroutine(DownloadAssetBundle(WWW.LoadFromCacheOrDownload(_url, _version))); #endif return(false); } else { Invoke("AllAssetsLoaded", 0.01f); return(true); } }
public static IEnumerator CheckPatch() { foreach (CachedAssetBundle item in AssetManager.EnumerateCachedAssetBundles()) { CachedAssetBundle current = item; if (!Caching.IsVersionCached(current)) { string assetBundleName = current.get_name(); AssetBundleLoadRequest loadRequest = AssetManager.LoadAssetBundle(assetBundleName); while (!loadRequest.get_isDone()) { yield return(null); } AssetBundleUnloadRequest unloadRequest = AssetManager.UnloadAssetBundle(assetBundleName); while (!unloadRequest.get_isDone()) { yield return(null); } } } }
public static int constructor(IntPtr l) { int result; try { string name; LuaObject.checkType(l, 2, out name); Hash128 hash; LuaObject.checkValueType <Hash128>(l, 3, out hash); CachedAssetBundle cachedAssetBundle = new CachedAssetBundle(name, hash); LuaObject.pushValue(l, true); LuaObject.pushValue(l, cachedAssetBundle); result = 2; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
public static UnityWebRequest GetAssetBundle(Uri uri, CachedAssetBundle cachedAssetBundle, uint crc = 0u) { return(new UnityWebRequest(uri, "GET", new DownloadHandlerAssetBundle(uri.AbsoluteUri, cachedAssetBundle, crc), null)); }
internal UnityWebRequest CreateWebRequest(IResourceLocation loc) { var url = m_ProvideHandle.ResourceManager.TransformInternalId(loc); UnityWebRequest webRequest = null; if (m_dataProc == null) { if (m_Options == null) { return(UnityWebRequestAssetBundle.GetAssetBundle(url)); } if (!string.IsNullOrEmpty(m_Options.Hash)) { CachedAssetBundle cachedBundle = new CachedAssetBundle(m_Options.BundleName, Hash128.Parse(m_Options.Hash)); #if ENABLE_CACHING if (m_Options.UseCrcForCachedBundle || !Caching.IsVersionCached(cachedBundle)) { webRequest = UnityWebRequestAssetBundle.GetAssetBundle(url, cachedBundle, m_Options.Crc); } else { webRequest = UnityWebRequestAssetBundle.GetAssetBundle(url, cachedBundle); } #else webRequest = UnityWebRequestAssetBundle.GetAssetBundle(url, cachedBundle, m_Options.Crc); #endif } else { webRequest = UnityWebRequestAssetBundle.GetAssetBundle(url, m_Options.Crc); } } else { webRequest = new UnityWebRequest(loc.InternalId); DownloadHandlerBuffer dH = new DownloadHandlerBuffer(); webRequest.downloadHandler = dH; } if (webRequest == null) { return(webRequest); } if (m_Options != null) { if (m_Options.Timeout > 0) { webRequest.timeout = m_Options.Timeout; } if (m_Options.RedirectLimit > 0) { webRequest.redirectLimit = m_Options.RedirectLimit; } #if !UNITY_2019_3_OR_NEWER webRequest.chunkedTransfer = m_Options.ChunkedTransfer; #endif } if (m_ProvideHandle.ResourceManager.CertificateHandlerInstance != null) { webRequest.certificateHandler = m_ProvideHandle.ResourceManager.CertificateHandlerInstance; webRequest.disposeCertificateHandlerOnDispose = false; } return(webRequest); }
public LoadHandle Load( string identifier, OnComplete onComplete = null, GameObject holderGameObject = null) { string assetBundleName, assetName; _database.ParseIdentifier(out assetBundleName, out assetName, identifier); var abHandleDictionaryKey = assetBundleName; var assetHandleDictionaryKey = identifier; AssetHandle assetHandle = null; lock (_lock) { // まず完了済みから探す if (!_completeHandles.TryGetValue(assetHandleDictionaryKey, out assetHandle)) { // ロード中から探す _loadingHandles.TryGetValue(assetHandleDictionaryKey, out assetHandle); } } // みつからなかったので生成 if (assetHandle == null) { // ないのでハンドル生成が確定 AssetBundleHandle abHandle = null; if (!_abHandles.TryGetValue(abHandleDictionaryKey, out abHandle)) { Hash128 hash; uint crc; _database.GetAssetBundleMetaData(out hash, out crc, assetBundleName); var cachedAssetBundle = new CachedAssetBundle(); cachedAssetBundle.hash = hash; cachedAssetBundle.name = assetBundleName; var path = _downloadRoot + assetBundleName; abHandle = new AssetBundleHandle( assetBundleName, ref cachedAssetBundle, path); _abHandles.Add(abHandleDictionaryKey, abHandle); } assetHandle = new AssetHandle(abHandle, assetName, assetHandleDictionaryKey); _loadingHandles.Add(assetHandleDictionaryKey, assetHandle); } if (onComplete != null) { if (assetHandle.isDone) { onComplete(assetHandle.asset); } else { assetHandle.AddCallback(onComplete); } } assetHandle.IncrementReferenceThreadSafe(); var handle = new LoadHandle(assetHandleDictionaryKey, this); if (holderGameObject != null) { var holder = holderGameObject.GetComponent <LoadHandleHolder>(); if (holder == null) { holder = holderGameObject.AddComponent <LoadHandleHolder>(); } holder.Add(handle); } return(handle); }
IEnumerator LoadAsset() { modelManager.loadingBunles.Add(ABName); /*while (!Caching.ready) * yield return null; * * WWW www = WWW.LoadFromCacheOrDownload(BundleFullURL + ABName, 1); * yield return www; * * if (!string.IsNullOrEmpty(www.error)) * { * preloader.LoadPercent(www); * Debug.Log(www.error); * yield return null; * } * AssetBundle bundle = www.assetBundle; * if (bundle.Contains(AssetName)) * { * Instantiate(bundle.LoadAssetAsync(AssetName).asset, gameObject.transform); * modelManager.bundles.Add(bundle); * modelManager.loadingBunles.Remove(ABName); * mover.modelName = ABName; * Debug.Log("is OBJ"); * preloader.Loaded(); * } * else * { * Debug.Log("Check asset name"); * }*/ #if UNITY_IOS BundleFullURL = PlayerPrefs.GetString("ApiUrl") + "/media/3d/" + ABName + "/ios/bundle"; #endif #if PLATFORM_ANDROID BundleFullURL = PlayerPrefs.GetString("ApiUrl") + "/media/3d/" + ABName + "/android/bundle"; #endif Debug.Log("Load Bundle Path = " + BundleFullURL); CachedAssetBundle cab = new CachedAssetBundle(ABName, new Hash128(0, 0)); using (UnityWebRequest uwr = UnityWebRequestAssetBundle.GetAssetBundle(BundleFullURL, cab)) { preloader.LoadPercent(uwr); yield return(uwr.SendWebRequest()); if (uwr.isNetworkError || uwr.isHttpError) { Debug.Log(uwr.error); preloader.CantLoad(); preloader.Loaded(); GetComponent <Collider>().enabled = false; GetComponent <Mover>().enabled = false; } else { // Get downloaded asset bundle AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(uwr); if (bundle.Contains(AssetName)) { Instantiate(bundle.LoadAssetAsync(AssetName).asset, gameObject.transform); modelManager.bundles.Add(bundle); modelManager.loadingBunles.Remove(ABName); mover.modelName = ABName; Debug.Log("is OBJ"); preloader.Loaded(); } else { Debug.Log("Check asset name"); preloader.CantLoad(); preloader.Loaded(); GetComponent <Collider>().enabled = false; GetComponent <Mover>().enabled = false; } } } }
public DownloadHandlerAssetBundle(string url, CachedAssetBundle cachedBundle, uint crc) { this.InternalCreateAssetBundleCached(url, cachedBundle.name, cachedBundle.hash, crc); }
public static UnityWebRequest GetAssetBundle(string uri, CachedAssetBundle cachedAssetBundle, uint crc) { return(new UnityWebRequest(uri, "GET", new DownloadHandlerAssetBundle(uri, cachedAssetBundle.name, cachedAssetBundle.hash, crc), null)); }
void LoadCard(Uri uri, string assetBundleName, Hash128 hash, uint crc, int cardID, bool isDish) { Debug.Log(Caching.ready); //構造体生成 var cachedAssetBundle = new CachedAssetBundle(assetBundleName, hash); //指定バージョン以外削除 //新しいCRCの場合は古いほうを削除 Caching.ClearOtherCachedVersions(cachedAssetBundle.name, cachedAssetBundle.hash); Debug.Log("cardID " + cardID); if (Caching.IsVersionCached(cachedAssetBundle)) { Debug.Log("キャッシュから"); //キャッシュ存在 string dataPath = AssetBundlePath(cachedAssetBundle); Debug.Log(dataPath); var op = UnityEngine.AssetBundle.LoadFromFileAsync(dataPath); op.completed += (obj) => { Debug.Log("ダウンロード成功"); AssetBundle bundle = op.assetBundle; var prefab = bundle.LoadAllAssets <CardEntity>(); CardEntity cardEntity = new CardEntity(); cardEntity = prefab[0] as CardEntity; Sprite[] icon = bundle.LoadAllAssets <Sprite>(); if (icon[0] != null) { cardEntity.icon = icon[0]; } if (!isDish) { if (icon[1] != null) { cardEntity.glowIcon = icon[1]; } } if (isDish) { cardData.dishCardEntity[cardID] = cardEntity; } else { cardData.ingCardEntity[cardID] = cardEntity; } ShowLoad(); GenerateCard(cardID + 1, isDish); }; } else { Debug.Log("サーバーから"); var request = UnityWebRequestAssetBundle.GetAssetBundle(uri, cachedAssetBundle, crc); var op = request.SendWebRequest(); op.completed += (obj) => { if (op.webRequest.isHttpError || op.webRequest.isNetworkError) { Debug.Log($"ダウンロードに失敗しました!! error:{op.webRequest.error}"); LoadFailed(); } else { Debug.Log("ダウンロード成功"); AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(request); var prefab = bundle.LoadAllAssets <CardEntity>(); CardEntity cardEntity = new CardEntity(); cardEntity = prefab[0] as CardEntity; Sprite[] icon = bundle.LoadAllAssets <Sprite>(); if (icon[0] != null) { cardEntity.icon = icon[0]; } if (!isDish) { if (icon[1] != null) { cardEntity.glowIcon = icon[1]; } } if (isDish) { cardData.dishCardEntity[cardID] = cardEntity; } else { cardData.ingCardEntity[cardID] = cardEntity; } ShowLoad(); GenerateCard(cardID + 1, isDish); } }; } }
public static IObservable <AssetBundle> GetAssetBundleAsObservable(Uri uri, CachedAssetBundle cachedAssetBundle, uint crc = 0U, IDictionary <string, string> requestHeaders = default, IProgress <float> progress = default) { return(RequestAsObservable(() => UnityWebRequestAssetBundle.GetAssetBundle(uri, cachedAssetBundle, crc).ApplyRequestHeaders(requestHeaders), FetchAssetBundle, progress)); }
void LoadBGM(Uri uri, string assetBundleName, Hash128 hash, uint crc, int bgmID) { Debug.Log(Caching.ready); //構造体生成 var cachedAssetBundle = new CachedAssetBundle(assetBundleName, hash); //指定バージョン以外削除 //新しいCRCの場合は古いほうを削除 Caching.ClearOtherCachedVersions(cachedAssetBundle.name, cachedAssetBundle.hash); if (Caching.IsVersionCached(cachedAssetBundle)) { Debug.Log("キャッシュから"); //キャッシュ存在 string dataPath = AssetBundlePath(cachedAssetBundle); Debug.Log(dataPath); var op = UnityEngine.AssetBundle.LoadFromFileAsync(dataPath); op.completed += (obj) => { Debug.Log("ダウンロード成功"); AssetBundle bundle = op.assetBundle; var prefab = bundle.LoadAllAssets <AudioClip>(); SoundManager.instance.SetAudioClip(bgmID, prefab[0]); GenerateBGM(bgmID + 1); ShowLoad(); }; } else { Debug.Log("サーバーから"); var request = UnityWebRequestAssetBundle.GetAssetBundle(uri, cachedAssetBundle, crc); var op = request.SendWebRequest(); op.completed += (obj) => { if (op.webRequest.isHttpError || op.webRequest.isNetworkError) { Debug.Log($"ダウンロードに失敗しました!! error:{op.webRequest.error}"); LoadFailed(); } else { Debug.Log("ダウンロード成功"); AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(request); var prefab = bundle.LoadAllAssets <AudioClip>(); SoundManager.instance.SetAudioClip(bgmID, prefab[0]); GenerateBGM(bgmID + 1); ShowLoad(); } }; } }
public static UnityWebRequest GetAssetBundle(string uri, CachedAssetBundle cachedAssetBundle, uint crc) { return(null); }
void LoadTable(Uri uri, string assetBundleName, Hash128 hash, uint crc = 0) { Debug.Log(Caching.ready); //構造体生成 var cachedAssetBundle = new CachedAssetBundle(assetBundleName, hash); //全てのtableのキャッシュ削除 Caching.ClearAllCachedVersions(assetBundleName); //if (Caching.IsVersionCached(cachedAssetBundle)) //{ // Debug.Log("キャッシュから"); // //キャッシュ存在 // string dataPath = AssetBundlePath(cachedAssetBundle); // Debug.Log(dataPath); // var op = UnityEngine.AssetBundle.LoadFromFileAsync(dataPath); // op.completed += (obj) => // { // // ダウンロード成功 // Debug.Log("ダウンロード成功"); // AssetBundle bundle = op.assetBundle; // var prefab = bundle.LoadAllAssets(); // string text = prefab[0].ToString(); // table = JsonUtility.FromJson<AssetBundleTable>(text); // Debug.Log("バージョン" + table.Version); // int preVersion = PlayerPrefs.GetInt("DOWNLOAD", -1); // if (preVersion != table.Version) // { // Debug.Log("新しいバージョンがあります"); // } // LoadEnd(LOAD.TABLE); // }; //} //else //{ Debug.Log("サーバーから"); var request = UnityWebRequestAssetBundle.GetAssetBundle(uri, cachedAssetBundle, crc); var op = request.SendWebRequest(); op.completed += (obj) => { if (op.webRequest.isHttpError || op.webRequest.isNetworkError) { Debug.Log($"ダウンロードに失敗しました!! error:{op.webRequest.error}"); LoadFailed(); } else { // ダウンロード成功 Debug.Log("ダウンロード成功"); var bundle = DownloadHandlerAssetBundle.GetContent(request); var prefab = bundle.LoadAllAssets(); string text = prefab[0].ToString(); table = JsonUtility.FromJson <AssetBundleTable>(text); Debug.Log("バージョン" + table.Version); int preVersion = PlayerPrefs.GetInt("VERSION", -1); if (preVersion != table.Version) { Debug.Log("新しいバージョンがあります"); newDataObj.SetActive(true); } else { Debug.Log("同じバージョン"); downLoadObj.SetActive(true); LoadEnd(LOAD.TABLE); } } }; //} }