Last active
November 10, 2020 08:20
-
-
Save baba-s/b119cc3c4097ef5d6dade786c8de2417 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using JetBrains.Annotations; | |
using System; | |
using UnityEngine; | |
using UnityEngine.Networking; | |
namespace Kogane | |
{ | |
[Serializable] | |
public struct JsonUnityWebRequestAsyncOperation | |
{ | |
[SerializeField][UsedImplicitly] private bool isDone; | |
[SerializeField][UsedImplicitly] private float progress; | |
[SerializeField][UsedImplicitly] private int priority; | |
[SerializeField][UsedImplicitly] private bool allowSceneActivation; | |
[SerializeField][UsedImplicitly] private JsonUnityWebRequest webRequest; | |
public JsonUnityWebRequestAsyncOperation( UnityWebRequestAsyncOperation operation ) | |
{ | |
isDone = operation.isDone; | |
progress = operation.progress; | |
priority = operation.priority; | |
allowSceneActivation = operation.allowSceneActivation; | |
webRequest = new JsonUnityWebRequest( operation.webRequest ); | |
} | |
public override string ToString() | |
{ | |
return JsonUtility.ToJson( this, true ); | |
} | |
} | |
[Serializable] | |
public struct JsonUnityWebRequest | |
{ | |
[SerializeField][UsedImplicitly] private string method; | |
[SerializeField][UsedImplicitly] private bool isHttpError; | |
[SerializeField][UsedImplicitly] private UnityWebRequest.Result result; | |
[SerializeField][UsedImplicitly] private float downloadProgress; | |
[SerializeField][UsedImplicitly] private float uploadProgress; | |
[SerializeField][UsedImplicitly] private long responseCode; | |
[SerializeField][UsedImplicitly] private string url; | |
[SerializeField][UsedImplicitly] private bool useHttpContinue; | |
[SerializeField][UsedImplicitly] private string error; | |
[SerializeField][UsedImplicitly] private bool isNetworkError; | |
[SerializeField][UsedImplicitly] private bool disposeCertificateHandlerOnDispose; | |
[SerializeField][UsedImplicitly] private ulong downloadedBytes; | |
[SerializeField][UsedImplicitly] private int timeout; | |
[SerializeField][UsedImplicitly] private JsonDownloadHandler downloadHandler; | |
[SerializeField][UsedImplicitly] private JsonUploadHandler uploadHandler; | |
[SerializeField][UsedImplicitly] private int redirectLimit; | |
[SerializeField][UsedImplicitly] private bool isModifiable; | |
[SerializeField][UsedImplicitly] private ulong uploadedBytes; | |
[SerializeField][UsedImplicitly] private bool disposeDownloadHandlerOnDispose; | |
[SerializeField][UsedImplicitly] private bool disposeUploadHandlerOnDispose; | |
[SerializeField][UsedImplicitly] private bool isDone; | |
public JsonUnityWebRequest( UnityWebRequest request ) | |
{ | |
method = request.method; | |
isHttpError = request.isHttpError; | |
result = request.result; | |
downloadProgress = request.downloadProgress; | |
uploadProgress = request.uploadProgress; | |
responseCode = request.responseCode; | |
url = request.url; | |
useHttpContinue = request.useHttpContinue; | |
error = request.error; | |
isNetworkError = request.isNetworkError; | |
disposeCertificateHandlerOnDispose = request.disposeCertificateHandlerOnDispose; | |
downloadedBytes = request.downloadedBytes; | |
timeout = request.timeout; | |
downloadHandler = request.downloadHandler != null ? new JsonDownloadHandler( request.downloadHandler ) : default; | |
uploadHandler = request.uploadHandler != null ? new JsonUploadHandler( request.uploadHandler ) : default; | |
redirectLimit = request.redirectLimit; | |
isModifiable = request.isModifiable; | |
uploadedBytes = request.uploadedBytes; | |
disposeDownloadHandlerOnDispose = request.disposeDownloadHandlerOnDispose; | |
disposeUploadHandlerOnDispose = request.disposeUploadHandlerOnDispose; | |
isDone = request.isDone; | |
} | |
public override string ToString() | |
{ | |
return JsonUtility.ToJson( this, true ); | |
} | |
} | |
[Serializable] | |
public struct JsonDownloadHandler | |
{ | |
[SerializeField][UsedImplicitly] private bool isDone; | |
[SerializeField][UsedImplicitly] private string error; | |
[SerializeField][UsedImplicitly] private string text; | |
public JsonDownloadHandler( DownloadHandler handler ) | |
{ | |
isDone = handler.isDone; | |
error = handler.error; | |
text = handler.text; | |
} | |
public override string ToString() | |
{ | |
return JsonUtility.ToJson( this, true ); | |
} | |
} | |
[Serializable] | |
public struct JsonUploadHandler | |
{ | |
[SerializeField][UsedImplicitly] private string contentType; | |
[SerializeField][UsedImplicitly] private float progress; | |
public JsonUploadHandler( UploadHandler handler ) | |
{ | |
contentType = handler.contentType; | |
progress = handler.progress; | |
} | |
public override string ToString() | |
{ | |
return JsonUtility.ToJson( this, true ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment