예제 #1
0
        private IEnumerator LoadBytesCo(string fileUri, LoadBytesCallback loadBytesCallback)
        {
            WWW www = new WWW(fileUri);

            yield return(www);

            byte[] bytes        = www.bytes;
            string errorMessage = www.error;

            www.Dispose();

            loadBytesCallback?.Invoke(fileUri, bytes, errorMessage);
        }
예제 #2
0
        //内部协程从文件路径中读取数据流
        private IEnumerator LoadBytesCo(string fileUri, LoadBytesCallback loadBytesCallback)
        {
            byte[] bytes        = null;
            string errorMessage = null;

#if UNITY_5_4_OR_NEWER
            UnityWebRequest unityWebRequest = UnityWebRequest.Get(fileUri);
#if UNITY_2017_2_OR_NEWER
            yield return(unityWebRequest.SendWebRequest());
#else
            yield return(unityWebRequest.Send());
#endif

            bool isError = false;
#if UNITY_2017_1_OR_NEWER
            isError = unityWebRequest.isNetworkError;
#else
            isError = unityWebRequest.isError;
#endif
            bytes        = unityWebRequest.downloadHandler.data;
            errorMessage = isError ? unityWebRequest.error : null;
            unityWebRequest.Dispose();
#else
            WWW www = new WWW(fileUri);
            yield return(www);

            bytes        = www.bytes;
            errorMessage = www.error;
            www.Dispose();
#endif

            if (loadBytesCallback != null)
            {
                loadBytesCallback.Invoke(fileUri, bytes, errorMessage);
            }
        }