コード例 #1
0
    //
    // 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));
    }
コード例 #2
0
    //
    // 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
    }
コード例 #3
0
    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));
    }
コード例 #4
0
ファイル: FileRequest.cs プロジェクト: cuulee/ur-scape
    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));
    }