IEnumerator LoadUIPackage() { string url = Application.streamingAssetsPath.Replace("\\", "/") + "/fairygui-examples/bundleusage.ab"; if (Application.platform != RuntimePlatform.Android) { url = "file:///" + url; } #if UNITY_2017_2_OR_NEWER #if UNITY_2018_1_OR_NEWER UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle(url); #else UnityWebRequest www = UnityWebRequest.GetAssetBundle(url); #endif yield return(www.SendWebRequest()); if (!www.isNetworkError && !www.isHttpError) { AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(www); #else WWW www = new WWW(url); yield return(www); if (string.IsNullOrEmpty(www.error)) { AssetBundle bundle = www.assetBundle; #endif if (bundle == null) { Debug.LogWarning("Run Window->Build FairyGUI example Bundles first."); yield return(0); } UIPackage.AddPackage(bundle); _mainView = UIPackage.CreateObject("BundleUsage", "Main").asCom; _mainView.fairyBatching = true; _mainView.SetSize(GRoot.inst.width, GRoot.inst.height); _mainView.AddRelation(GRoot.inst, RelationType.Size); GRoot.inst.AddChild(_mainView); _mainView.GetTransition("t0").Play(); } else { Debug.LogError(www.error); } } void OnKeyDown(EventContext context) { if (context.inputEvent.keyCode == KeyCode.Escape) { Application.Quit(); } } }
public virtual async Task <Dictionary <string, object> > Load(CultureInfo cultureInfo) { Dictionary <string, object> dict = new Dictionary <string, object>(); using (UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle(this.assetBundleUrl)) { await www.SendWebRequest(); DownloadHandlerAssetBundle handler = (DownloadHandlerAssetBundle)www.downloadHandler; AssetBundle bundle = handler.assetBundle; if (bundle == null) { if (log.IsWarnEnabled) { log.WarnFormat("Failed to load Assetbundle from \"{0}\".", this.assetBundleUrl); } return(dict); } try { List <string> assetNames = new List <string>(bundle.GetAllAssetNames()); foreach (string filename in filenames) { try { string defaultPath = assetNames.Find(p => p.Contains(string.Format("/default/{0}", filename))); //eg:default string twoLetterISOpath = assetNames.Find(p => p.Contains(string.Format("/{0}/{1}", cultureInfo.TwoLetterISOLanguageName, filename))); //eg:zh en string path = cultureInfo.Name.Equals(cultureInfo.TwoLetterISOLanguageName) ? null : assetNames.Find(p => p.Contains(string.Format("/{0}/{1}", cultureInfo.Name, filename))); //eg:zh-CN en-US FillData(dict, bundle, defaultPath); FillData(dict, bundle, twoLetterISOpath); FillData(dict, bundle, path); } catch (Exception e) { if (log.IsWarnEnabled) { log.WarnFormat("An error occurred when loading localized data from \"{0}\".Error:{1}", filename, e); } } } } finally { try { if (bundle != null) { bundle.Unload(true); } } catch (Exception) { } } return(dict); } }
private IEnumerator LoadAssetBundle() { // Clear any cached versions. bool cacheCleared = Caching.ClearCache(); if (!cacheCleared) { Debug.Log("Failed to clear cache. AssetBundle may not have been updated."); } // Fetch AssetBundle. using (var request = UnityWebRequestAssetBundle.GetAssetBundle(DatabaseLocation, 0)) { yield return(request.SendWebRequest()); if (request.isHttpError || request.isNetworkError) { Debug.Log("Web request failed."); } else { DatabaseAssetBundle = DownloadHandlerAssetBundle.GetContent(request); } } // Downloading finished. Process AssetBundle. if (DatabaseAssetBundle == null) { Debug.Log("Failed to load database."); yield break; } else { // Load element prefabs. ElementPrefabs = new Dictionary <long, GameObject>(); foreach (GameObject asset in DatabaseAssetBundle.LoadAllAssets <GameObject>()) { var elementMetadata = asset.GetComponent <ElementMetadata>(); if (elementMetadata != null) { ElementPrefabs.Add(elementMetadata.FeatureId, asset); } } // Load materials. Textures = new Dictionary <string, Texture2D>(); foreach (Texture2D texture in DatabaseAssetBundle.LoadAllAssets <Texture2D>()) { Textures.Add(texture.name, texture); } // Set up the Configuration Manager. var featureModelAsset = DatabaseAssetBundle.LoadAsset <TextAsset>("featuremodel.asset"); FindObjectOfType <ConfigurationManager>().OnDatabaseLoaded(featureModelAsset.text); } }
private AssetRequest DownloadCompleteListenr(AssetRequest req) { mLoadCompleteNum++; var assetBundle = DownloadHandlerAssetBundle.GetContent(req.LoadRequest); mBundleDict[req.LoadName] = assetBundle; return(req); }
private static async IPandaTask <AssetBundle> FullLoadAssetBundleInternal(string uri, IProgressTracker <float> progressTracker = default, CancellationToken cancellationToken = default) { using (var webRequest = UnityWebRequestAssetBundle.GetAssetBundle(uri)) { await webRequest.SendWebRequest().WaitAsync(progressTracker, cancellationToken); return(DownloadHandlerAssetBundle.GetContent(webRequest)); } }
/// <summary> /// Get the asset bundle object managed by this resource. This call may force the bundle to load if not already loaded. /// </summary> /// <returns>The asset bundle.</returns> public AssetBundle GetAssetBundle() { if (m_AssetBundle == null && m_downloadHandler != null) { m_AssetBundle = m_downloadHandler.assetBundle; m_downloadHandler.Dispose(); m_downloadHandler = null; } return(m_AssetBundle); }
internal UnityHttpResponseAssetBundle(UnityWebRequest unityWebRequest, object stateObject = null) : base(unityWebRequest, stateObject) { DownloadHandlerAssetBundle downloadHandler = (DownloadHandlerAssetBundle)unityWebRequest.downloadHandler; if (downloadHandler != null) { AssetBundle = downloadHandler.assetBundle; } }
public AssetBundle GetAssetBundle() { if (assetBundle == null && downloadHandler != null) { assetBundle = downloadHandler.assetBundle; downloadHandler.Dispose(); downloadHandler = null; } return(assetBundle); }
static IEnumerator ReloadBundle(string bundleName, LoadedBundle loadedBundle) { if (LogMessages) { Debug.Log($"Start Reloading Bundle {bundleName}"); } var bundleReq = loadedBundle.IsLocalBundle? UnityWebRequestAssetBundle.GetAssetBundle(loadedBundle.LoadPath) : UnityWebRequestAssetBundle.GetAssetBundle(loadedBundle.LoadPath, new CachedAssetBundle(bundleName, loadedBundle.Hash)); loadedBundle.IsReloading = true; yield return(bundleReq.SendWebRequest()); loadedBundle.IsReloading = false; if (bundleReq.isNetworkError || bundleReq.isHttpError) { Debug.LogError($"Bundle reload error { bundleReq.error }"); yield break; } if (!s_AssetBundles.TryGetValue(bundleName, out var currentLoadedBundle) || currentLoadedBundle.Hash != loadedBundle.Hash) { if (LogMessages) { Debug.Log("Bundle To Reload does not exist(changed during loaing)"); } bundleReq.Dispose(); yield break; } //if we can swap now if (!s_BundleRefCounts.TryGetValue(bundleName, out var refCount) || refCount == 0) { if (LogMessages) { Debug.Log($"Reloaded Bundle {bundleName}"); } loadedBundle.Bundle.Unload(true); loadedBundle.Bundle = DownloadHandlerAssetBundle.GetContent(bundleReq); bundleReq.Dispose(); } else { if (LogMessages) { Debug.Log($"Reloaded Bundle Cached for later use {bundleName}"); } //store request for laster use loadedBundle.RequestForReload = bundleReq; } }
static IEnumerator <object> InstantiateShieldLocation(string assetBundleName, ShieldLocation keySelection, Vector3 position = default, int parentIndex = -1) { if (string.IsNullOrEmpty(assetBundleName)) { Logger.Log("Skipping empty asset bundle"); yield break; } AssetBundle downloadedAssetBundle = null; UnityWebRequest request = null; cachedAssetBundles = AssetBundle.GetAllLoadedAssetBundles().ToList(); AssetBundle cachedAssetBundle = cachedAssetBundles.FirstOrDefault(a => a.name == assetBundleName); if (cachedAssetBundle == null) { string uri = Constants.Routes.BackendIp + assetBundleName; Logger.Log($"Request {uri}", Logger.LogLevel.Info); request = UnityWebRequestAssetBundle.GetAssetBundle(uri, 0); yield return(request.SendWebRequest()); if (request.isNetworkError || request.isHttpError) { DebugText.text += "NetworkError, HttpError " + request.error; Logger.Log($"NetworkError, HttpError : " + request.error, Logger.LogLevel.Error); yield break; } downloadedAssetBundle = DownloadHandlerAssetBundle.GetContent(request); } else { downloadedAssetBundle = cachedAssetBundle; } if (downloadedAssetBundle == null) { Logger.Log("Failed to load AssetBundle! Download failed for " + assetBundleName + request.error + request.downloadHandler.text, Logger.LogLevel.Error); yield break; } try { var go = Utils.InstantiateAssetBundle(downloadedAssetBundle, position, parentIndex < 0 ? CurrentParent : CaptureParents[parentIndex]); var importablePrefab = go.GetComponent <ImportablePrefab>(); var assetBundleDef = importablePrefab.AssetBundleDefinition; } catch (Exception e) { Logger.Log(e.Message + e.StackTrace, Logger.LogLevel.Error); DebugText.text += e.Message; } }
public static IEnumerator DownloadAndCache() { while (!Caching.ready) { yield return(null); } running = true; //checking version var request = UnityWebRequest.Get(manifestURL); yield return(request.SendWebRequest()); running = false; Hash128 hash = default; var hashRow = request.downloadHandler.text.ToString().Split("\n".ToCharArray())[5]; hash = Hash128.Parse(hashRow.Split(':')[1].Trim()); if (hash.isValid == true) { request.Dispose(); //checking hash version and download new if needed request = UnityWebRequestAssetBundle.GetAssetBundle(bundleURL, hash, 0); yield return(request.SendWebRequest()); running = false; if (request.result != UnityWebRequest.Result.ProtocolError && request.result != UnityWebRequest.Result.ConnectionError) { Settings.assetBundle = DownloadHandlerAssetBundle.GetContent(request); request.Dispose(); yield return(null); running = false; } else { yield return(null); running = false; } } else { yield return(null); running = false; } }
IEnumerator LoadAssetBundle(string dir) { var uwr = UnityWebRequest.GetAssetBundle(dir); yield return(uwr.SendWebRequest()); GameObject c = DownloadHandlerAssetBundle.GetContent(uwr).LoadAsset <GameObject>("Cube"); // Get the designated main asset and instantiate it. Instantiate(c); }
public IEnumerator GetAssetBundle(string assetBundlePath, Action <GameObject> OnObjectLoaded, string audioPath) { Debug.Log("called enum " + assetBundlePath); UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle(assetBundlePath); yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); } else { Debug.Log(www.downloadedBytes); AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(www); foreach (string go in bundle.GetAllAssetNames()) { Debug.Log("asdlkjfalskdjfh = " + go); } GameObject newGameObject = bundle.LoadAsset <GameObject>("dave"); Debug.Log("name = " + newGameObject.name); newGameObject.GetComponent <Animation>().playAutomatically = false; Animation[] a = newGameObject.GetComponentsInChildren <Animation>(); Animator animator = newGameObject.AddComponent <Animator>(); AnimationClip aniClip = a[0].GetClip("Armature.002|Armature.002Action"); animator.runtimeAnimatorController = Resources.Load("DefaultAnimator") as RuntimeAnimatorController; using (UnityWebRequest www1 = UnityWebRequestMultimedia.GetAudioClip(audioPath, AudioType.WAV)) { yield return(www1.SendWebRequest()); if (www1.isNetworkError) { Debug.Log(www.error); } else { AudioClip myClip = DownloadHandlerAudioClip.GetContent(www1); AudioSource asource = newGameObject.AddComponent <AudioSource>(); asource.clip = myClip; } } // put some parameters on the AnimationEvent // - call the function called PrintEvent() // - the animation on this object lasts 2 seconds // and the new animation created here is // set up to happen 1.3s into the animation OnObjectLoaded(newGameObject); } }
public IEnumerator LoadSceneBundle(string bundleName, string resName) { string url = Application.dataPath + "bundleScene.unity"; UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(url); yield return(request.SendWebRequest()); AssetBundle ab = DownloadHandlerAssetBundle.GetContent(request); SceneManager.LoadScene("BundleScene"); }
IEnumerator OnLoadAssetBundle(string abName, Type type) { string url = m_BaseDownloadingURL + abName; // Debug.Log("OnLoadAssetBundle : url:"+url+" m_AssetBundleManifest:"+(m_AssetBundleManifest!=null) + new System.Diagnostics.StackTrace().ToString()); UnityWebRequest webRequest = null; if (type == typeof(AssetBundleManifest)) { webRequest = UnityWebRequestAssetBundle.GetAssetBundle(url); } else { Hash128 hash = new Hash128(); if (m_AssetBundleManifest != null) { string[] dependencies = m_AssetBundleManifest.GetAllDependencies(abName); if (dependencies.Length > 0) { m_Dependencies.Add(abName, dependencies); for (int i = 0; i < dependencies.Length; i++) { string depName = dependencies[i]; AssetBundleInfo bundleInfo = null; if (m_LoadedAssetBundles.TryGetValue(depName, out bundleInfo)) { bundleInfo.m_ReferencedCount++; } else if (m_LoadRequests.ContainsKey(depName)) { yield return(WaitForAssetBundleLoaded(depName)); } else { m_LoadRequests.Add(depName, null); yield return(StartCoroutine(OnLoadAssetBundle(depName, type))); m_LoadRequests.Remove(depName); } } } hash = m_AssetBundleManifest.GetAssetBundleHash(abName); } webRequest = UnityWebRequestAssetBundle.GetAssetBundle(url, hash, 0); } yield return(webRequest.SendWebRequest()); AssetBundle assetObj = DownloadHandlerAssetBundle.GetContent(webRequest); // Debug.Log("assetObj : "+(assetObj!=null)+" abName:"+abName+" isDone:"+webRequest.isDone); if (assetObj != null) { m_LoadedAssetBundles.Add(abName, new AssetBundleInfo(assetObj)); } }
internal void Start(ProvideHandle provideHandle) { m_Retries = 0; m_AssetBundle = null; m_downloadHandler = null; m_ProvideHandle = provideHandle; m_Options = m_ProvideHandle.Location.Data as AssetBundleRequestOptions; m_RequestOperation = null; BeginOperation(); provideHandle.SetProgressCallback(PercentComplete); }
IEnumerator LoadAssets() { UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle("file:///" + Path.Combine(Application.dataPath, "../") + "/AssetBundles/waterball.unity3d"); yield return(request.SendWebRequest()); AssetBundle ab = DownloadHandlerAssetBundle.GetContent(request); GameObject asset = ab.LoadAsset <GameObject>("Sphere"); Instantiate(asset); }
void Update() { // Collect all the finished WWWs. keysToRemove.Clear(); foreach (var keyValue in m_DownloadingWWWs) { UnityWebRequest download = keyValue.Value; // If downloading fails. if (download.isNetworkError || download.isHttpError) { m_DownloadingErrors.Add(keyValue.Key, string.Format("Failed downloading bundle {0} from {1}: {2}", keyValue.Key, download.url, download.error)); keysToRemove.Add(keyValue.Key); continue; } // If downloading succeeds. if (download.isDone) { keysToRemove.Add(keyValue.Key); AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(download); if (bundle == null) { m_DownloadingErrors.Add(keyValue.Key, string.Format("{0} is not a valid asset bundle.", keyValue.Key)); continue; } //Debug.Log("Downloading " + keyValue.Key + " is done at frame " + Time.frameCount); m_LoadedAssetBundles.Add(keyValue.Key, new LoadedAssetBundle(bundle, abRefCounts[keyValue.Key])); } } // Remove the finished WWWs. foreach (var key in keysToRemove) { UnityWebRequest download = m_DownloadingWWWs[key]; m_DownloadingWWWs.Remove(key); abRefCounts.Remove(key); download.Dispose(); } // Update all in progress operations for (int i = 0; i < m_InProgressOperations.Count;) { if (!m_InProgressOperations[i].Update()) { m_InProgressOperations.RemoveAt(i); } else { i++; } } }
private bool llamadr2() { string urlx = "https://cgtfiles.s3.amazonaws.com/uploads/files/778160/can.obj"; var uwr = UnityWebRequestAssetBundle.GetAssetBundle(urlx); //yield return uwr.SendWebRequest(); // Get the designated main asset and instantiate it. Instantiate(DownloadHandlerAssetBundle.GetContent(uwr).mainAsset); return(true); }
/// <summary> /// 从服务器获取Manifest,记录依赖 /// </summary> /// <returns></returns> internal IEnumerator LoadManifest() { //如果使用服务器资源 if (!string.IsNullOrEmpty(pather.WebServeMainManifest)) { var webBundleRequest = UnityWebRequestAssetBundle.GetAssetBundle(pather.WebServeMainManifest); yield return(webBundleRequest.SendWebRequest()); var serverAssetBundle = DownloadHandlerAssetBundle.GetContent(webBundleRequest); if (!serverAssetBundle) { throw new Exception("server assetBundle is null"); } var assetR = serverAssetBundle.LoadAssetAsync <AssetBundleManifest>("AssetBundleManifest"); yield return(assetR); var manifest = assetR.asset as AssetBundleManifest; Assert.IsTrue(manifest); foreach (var bundlesName in manifest.GetAllAssetBundles()) { bundleDependencies.Add(bundlesName, manifest.GetAllDependencies(bundlesName)); } serverAssetBundle.Unload(true); } //如果使用StreamingAsset资源 if (!string.IsNullOrEmpty(pather.OriginMainManifest)) { var originBundleRequest = UnityWebRequestAssetBundle.GetAssetBundle(pather.OriginMainManifest); yield return(originBundleRequest.SendWebRequest()); var originAssetBundle = DownloadHandlerAssetBundle.GetContent(originBundleRequest); if (!originAssetBundle) { throw new Exception("Streaming AssetBundle is null"); } var assetR = originAssetBundle.LoadAssetAsync <AssetBundleManifest>("AssetBundleManifest"); yield return(assetR); var manifest = assetR.asset as AssetBundleManifest; Assert.IsTrue(manifest); foreach (var bundlesName in manifest.GetAllAssetBundles()) { bundleDependencies.Add(bundlesName, manifest.GetAllDependencies(bundlesName)); } originAssetBundle.Unload(true); } }
IEnumerator LoaderResourceCorotine(string resName, string filePath) { UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(@"http://localhost/AssetBundles/" + filePath); yield return(request.SendWebRequest()); AssetBundle ab = DownloadHandlerAssetBundle.GetContent(request); GameObject gameObject = ab.LoadAsset <GameObject>(resName); prefabDict.Add(resName, gameObject); }
private void StateRequest(UnityWebRequest request, ref AssetBundle assetBundle) { if (request.error == null) { assetBundle = DownloadHandlerAssetBundle.GetContent(request); Debug.Log("Complete"); } else { Debug.Log(request.error); } }
public IEnumerator LoadAssetBundle(string bundleName, UnityAction onSucceed, UnityAction onFailed, bool bLoadAssetBundleFromStreamingAssets) { if (IsBundleExist(bundleName)) { LoggerManager.Instance().LogFormat("DownLoadAssetBundle {0} Failed , this bundle has already loaded ...", bundleName); if (null != onSucceed) { onSucceed.Invoke(); } yield break; } var bundleUrl = CommonFunction.getAssetBundleSavePath(string.Format("{0}/{1}", CommonFunction.getPlatformString(), bundleName), true, bLoadAssetBundleFromStreamingAssets); LoggerManager.Instance().LogProcessFormat("[LoadAssetBundle]: bundleName = {0} bundleUrl = {1}", bundleName, bundleUrl); using (UnityWebRequest www = UnityWebRequest.Get(bundleUrl)) { DownloadHandlerAssetBundle handler = new DownloadHandlerAssetBundle(www.url, 0); www.downloadHandler = handler; yield return(www.Send()); if (www.error != null) { LoggerManager.Instance().LogErrorFormat("DownLoadAssetBundle Failed:{0} url={1}", www.error, bundleUrl); if (null != onFailed) { onFailed.Invoke(); } } else { AssetBundle bundle = handler.assetBundle; if (null == bundle) { LoggerManager.Instance().LogErrorFormat("DownLoadAssetBundle Failed: Bundle Downloaded is null ..."); if (null != onFailed) { onFailed.Invoke(); } yield break; } AddBundleToDic(bundleName, bundle); if (null != onSucceed) { onSucceed.Invoke(); } } } }
public static IEnumerator LoadFromWebRequest(string path, Action <AssetBundle> callback, int version) { UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(path, (uint)version, 0); yield return(request.SendWebRequest()); AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(request); callback(bundle); request.Dispose(); request = null; }
IEnumerator LoadAssetBundle() { while (!Caching.ready) { yield return(null); } Caching.ClearCache(); using (UnityWebRequest uwr = UnityWebRequestAssetBundle.GetAssetBundle(BundleManagerURL)) { yield return(uwr.SendWebRequest()); if (uwr.isNetworkError || uwr.isHttpError) { Debug.Log(uwr.error); } else { AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(uwr); AssetBundleRequest request = bundle.LoadAssetAsync("LoadSceneManager", typeof(GameObject)); yield return(request); GameObject obj = Instantiate(request.asset, this.transform) as GameObject; obj.transform.position = Vector3.zero; bundle.Unload(false); } } Debugging.Log("매니저 에셋 번들 로드성공"); using (UnityWebRequest uwr = UnityWebRequestAssetBundle.GetAssetBundle(BundleHeroURL)) { yield return(uwr.SendWebRequest()); if (uwr.isNetworkError || uwr.isHttpError) { Debug.Log(uwr.error); } else { AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(uwr); for (int i = 0; i < 7; i++) { AssetBundleRequest request = bundle.LoadAssetAsync("Hero00" + (i + 1), typeof(GameObject)); yield return(request); PrefabsDatabaseManager.instance.AddPrefabToHeroList(request.asset as GameObject); } PrefabsDatabaseManager.instance.GetPrefabList(); bundle.Unload(false); } } Debugging.Log("영웅 에셋 번들 로드성공"); // using문은 File 및 Font 처럼 컴퓨터 에서 관리되는 리소스들을 쓰고 나서 쉽게 자원을 되돌려줄수 있도록 기능을 제공 }
IEnumerator webReq(string urlLink) { if (anim == 1) { anim = 0; } if (urlLink == "https://drive.google.com/uc?export=download&id=1udOxYcO_IlJigSNC-s38kCFl946z-pUF") { anim = 1; offset = 0.5f; offset2 = 0.5f; offset3 = 0.5f; offsetRot = 5; } UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle(urlLink); yield return(www.SendWebRequest()); if (www.isNetworkError) { Debug.Log("Network error"); } else { AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(www); if (bundle != null) { if (go != null && go2 != null && go3 != null) { go.SetActive(false); go2.SetActive(false); go3.SetActive(false); } string rootAssetPath = bundle.GetAllAssetNames()[0]; Debug.Log("numele fisier" + rootAssetPath); m_RegionPrefab = (GameObject)bundle.LoadAsset(rootAssetPath); go = Instantiate(m_RegionPrefab, m_SessionOrigin.trackablesParent); go2 = Instantiate(m_RegionPrefab, m_SessionOrigin.trackablesParent); go3 = Instantiate(m_RegionPrefab, m_SessionOrigin.trackablesParent); bundle.Unload(false); go.SetActive(true); go2.SetActive(true); go3.SetActive(true); rotatiemisto = m_RegionPrefab.transform.localRotation; pozitiemisto = m_RegionPrefab.transform.localPosition; flag = 1 - flag; initializare = true; startGame = true; } else { Debug.LogError("Not a valid asset bundle"); } } }
private void Completed(AsyncOperation obj) { if (request.isNetworkError) { ThrowError(request.error); } else { m_ab = DownloadHandlerAssetBundle.GetContent(request); } m_isdone = true; }
public override IAsyncOperation Awake(IRequest request) { var verb = request.ResolveVerb(); var url = request.ResolveUrl(); var headers = request.ResolveHeaders()?.ToList(); currentBundleUrl = url; var crc = headers.FetchHeader <uint>(InternalHeaders.AssetBundleCrc); var version = headers.FetchHeader <uint>(InternalHeaders.AssetBundleVersion); var hash = headers.FetchHeader <Hash128>(InternalHeaders.AssetBundleHash); var isCacheEnabled = headers.FetchHeader <bool>(InternalHeaders.NativeCacheEnabled); var cache = Context.NativeCache; var cacheVersion = 0 != version ? version : cache.Version; var handler = new DownloadHandlerAssetBundle(url, crc); if (0 != cacheVersion && isCacheEnabled) { handler = new DownloadHandlerAssetBundle(url, cacheVersion, crc); } if (default != hash) { handler = new DownloadHandlerAssetBundle(url, hash, crc); } var requestImpl = new UnityWebRequest(url, verb) { downloadHandler = handler }; var isManifestRequest = headers.FetchHeader <bool>(InternalHeaders.AssetBundleLoadManifest); var requestOperation = new Func <IAsyncOperation, IAsyncOperation>(_ => { AssetBundlePool.Instance.Release(url, false, Context); return(new UnityAsyncOperation(() => Send(requestImpl, headers))); }); if (!isManifestRequest) { return(requestOperation(null)); } var manifestOperation = new Func <IAsyncOperation, IAsyncOperation>(previous => { var bundle = MapAssetBundle(url, previous); return(new UnityAsyncOperation(() => bundle.LoadAssetAsync <AssetBundleManifest>(ManifestAsset))); }); return(new AsyncOperationQueue(requestOperation, manifestOperation)); }
/// <summary> /// 网络请求ab包 /// </summary> /// <returns></returns> IEnumerator LoadAssets() { string url = "file:///" + Application.dataPath + "/AssetBundle/assets_prefab_common_model_model_a.ab"; UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(url); yield return(request.SendWebRequest()); AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(request); GameObject cube = bundle.LoadAsset <GameObject>("Cube"); Instantiate(cube); }
IEnumerator LoadABAsync() { string uri = "file:///" + Application.streamingAssetsPath + "/AssetBundles/tex/icon/wings"; UnityWebRequest request = UnityWebRequest.GetAssetBundle(uri, 0); yield return(request.Send()); AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(request); Sprite s = bundle.LoadAsset <Sprite>("ico_wing_fengchitianxiang"); GetComponent <UINode>().GetRef("Image").GetComponent <Image>().sprite = s; }