/// <summary> /// Downloads text from a URL without caching it in Unity (browser will still cache normally) /// </summary> private IEnumerator <IYieldInstruction> DownloadText(string url, Action <string> wwwDataResult) { SpooledWWW assetWWW = new SpooledWWW(url); yield return(new YieldForSpooledWWW(assetWWW)); if (!String.IsNullOrEmpty(assetWWW.result.error)) { Console.LogError("Error while trying to download text: " + assetWWW.result.error + " From path: " + url); } wwwDataResult(assetWWW.result.data); }
/// <summary> /// Downloads text from a URL without caching it in Unity (browser will still cache normally) /// </summary> private IEnumerator <IYieldInstruction> GetServiceResult(string url, Action <XmlDocument> wwwDataResult) { SpooledWWW assetWWW = new SpooledWWW(url); yield return(new YieldForSpooledWWW(assetWWW)); if (!String.IsNullOrEmpty(assetWWW.result.error)) { Console.WriteLine("Error while trying to download text: " + assetWWW.result.error + " From path: " + url); } XmlDocument wwwDoc = new XmlDocument(); wwwDoc.LoadXml(assetWWW.result.data); GameFacade.Instance.RetrieveMediator <LoggerMediator>().Logger.Log("GetServiceResult xml = " + wwwDoc.OuterXml, LogLevel.Info); wwwDataResult(wwwDoc); }
//The coroutine to download asset using WWW class and convert to a Unity Object. private IEnumerator <IYieldInstruction> DownloadLateBoundAsset(string path, Action <UnityEngine.Object> loadedAssetCallback) { SpooledWWW assetWWW = new SpooledWWW(path); yield return(new YieldForSpooledWWW(assetWWW)); if (!String.IsNullOrEmpty(assetWWW.result.error)) { throw new Exception("Error while trying to download late bound asset: " + assetWWW.result.error); } UnityEngine.Object returnObject = assetWWW.result.assetBundle.mainAsset; if (returnObject == null) { throw new Exception("The WWW class could not load a UnityEngine.Object from path " + path); } DownloadFinishedExecuteCallbacks(path, loadedAssetCallback, returnObject); }
//The coroutine to download asset using WWW class and convert to Texture asset. private IEnumerator <IYieldInstruction> DownloadTextureAsset(string path, Action <UnityEngine.Object> loadedAssetCallback) { SpooledWWW assetWWW = new SpooledWWW(path); yield return(new YieldForSpooledWWW(assetWWW)); UnityEngine.Object returnObject = null; if (String.IsNullOrEmpty(assetWWW.result.error)) { returnObject = assetWWW.result.texture; } if (returnObject == null) { Console.LogError("The WWW class could not load a UnityEngine.Object from path (" + path + "): " + assetWWW.result.error); returnObject = Resources.Load("GUI/BrokenLink"); } DownloadFinishedExecuteCallbacks(path, loadedAssetCallback, returnObject); }
public YieldForSpooledWWW(SpooledWWW www) { mWWW = www; }