// // Private Methods // #if UNITY_STANDALONE || UNITY_IOS || (UNITY_WEBGL && UNITY_EDITOR) private static void GetFromFile(string filename, FileRequestCallback callback, UnityAction errCallback = null) { if (!File.Exists(filename)) { Debug.LogError(filename + " does not exist!"); errCallback?.Invoke(); return; } callback(File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)); }
// // Public Methods // public static IEnumerator GetStream(string filename, FileRequestCallback callback, UnityAction errCallback = null) { #if UNITY_WEBGL && !UNITY_EDITOR yield return(GetFromURL(Web.GetUrl(filename), callback, errCallback)); #else #if UNITY_WEBGL yield return(WebGLDelay); #endif GetFromFile(filename, callback, errCallback); yield break; #endif }
private static IEnumerator GetFromURL(string url, FileRequestCallback callback, UnityAction errCallback = null) { byte[] data = null; yield return(GetFromURL(url, d => data = d)); if (data == null) { Debug.LogError("Could not download " + url); errCallback?.Invoke(); yield break; } callback(new MemoryStream(data)); }
private static IEnumerator GetFromURL(string url, string saveAs, FileRequestCallback callback, UnityAction errCallback = null) { byte[] data = null; yield return(GetFromURL(url, d => data = d)); if (data == null) { Debug.LogError("Could not download " + url); if (errCallback != null) { errCallback(); } yield break; } if (!string.IsNullOrEmpty(saveAs)) { File.WriteAllBytes(saveAs, data); } callback(new MemoryStream(data)); }