Files
MuHua-Core/Packages/Network/Runtime/DataRequestGet.cs
T
MuHua-123 e373ec09e5 修改网络工具包
增加协程调用方法
2025-03-22 14:48:18 +08:00

33 lines
880 B
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
namespace MuHua {
/// <summary>
/// Get请求数据
/// </summary>
public class DataRequestGet : DataRequest {
public readonly string url;
public Action<string> OnError;
public Action<string> OnCallback;
public override string Url => url;
public override WebRequestType RequestType => WebRequestType.GET;
/// <summary> Web Get请求数据 </summary>
public DataRequestGet(string url, Action<string> OnCallback = null) {
this.url = url;
this.OnCallback = OnCallback;
}
public override void RequestResultHandle(bool isDone, UnityWebRequest web) {
DownloadHandler downloadHandler = web.downloadHandler;
if (!isDone) { OnError?.Invoke(downloadHandler.text); return; }
OnCallback?.Invoke(downloadHandler.text);
}
}
}