init
This commit is contained in:
@@ -0,0 +1,186 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using GameFramework;
|
||||
using GameFramework.WebRequest;
|
||||
using System;
|
||||
#if UNITY_5_4_OR_NEWER
|
||||
using UnityEngine.Networking;
|
||||
#else
|
||||
using UnityEngine.Experimental.Networking;
|
||||
#endif
|
||||
using Utility = GameFramework.Utility;
|
||||
|
||||
namespace UnityGameFramework.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// 使用 UnityWebRequest 实现的 Web 请求代理辅助器。
|
||||
/// </summary>
|
||||
public class UnityWebRequestAgentHelper : WebRequestAgentHelperBase, IDisposable
|
||||
{
|
||||
private UnityWebRequest m_UnityWebRequest = null;
|
||||
private bool m_Disposed = false;
|
||||
|
||||
private EventHandler<WebRequestAgentHelperCompleteEventArgs> m_WebRequestAgentHelperCompleteEventHandler = null;
|
||||
private EventHandler<WebRequestAgentHelperErrorEventArgs> m_WebRequestAgentHelperErrorEventHandler = null;
|
||||
|
||||
/// <summary>
|
||||
/// Web 请求代理辅助器完成事件。
|
||||
/// </summary>
|
||||
public override event EventHandler<WebRequestAgentHelperCompleteEventArgs> WebRequestAgentHelperComplete
|
||||
{
|
||||
add
|
||||
{
|
||||
m_WebRequestAgentHelperCompleteEventHandler += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
m_WebRequestAgentHelperCompleteEventHandler -= value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Web 请求代理辅助器错误事件。
|
||||
/// </summary>
|
||||
public override event EventHandler<WebRequestAgentHelperErrorEventArgs> WebRequestAgentHelperError
|
||||
{
|
||||
add
|
||||
{
|
||||
m_WebRequestAgentHelperErrorEventHandler += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
m_WebRequestAgentHelperErrorEventHandler -= value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过 Web 请求代理辅助器发送请求。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">要发送的远程地址。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
public override void Request(string webRequestUri, object userData)
|
||||
{
|
||||
if (m_WebRequestAgentHelperCompleteEventHandler == null || m_WebRequestAgentHelperErrorEventHandler == null)
|
||||
{
|
||||
Log.Fatal("Web request agent helper handler is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
WWWFormInfo wwwFormInfo = (WWWFormInfo)userData;
|
||||
if (wwwFormInfo.WWWForm == null)
|
||||
{
|
||||
m_UnityWebRequest = UnityWebRequest.Get(webRequestUri);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_UnityWebRequest = UnityWebRequest.Post(webRequestUri, wwwFormInfo.WWWForm);
|
||||
}
|
||||
|
||||
#if UNITY_2017_2_OR_NEWER
|
||||
m_UnityWebRequest.SendWebRequest();
|
||||
#else
|
||||
m_UnityWebRequest.Send();
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过 Web 请求代理辅助器发送请求。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">要发送的远程地址。</param>
|
||||
/// <param name="postData">要发送的数据流。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
public override void Request(string webRequestUri, byte[] postData, object userData)
|
||||
{
|
||||
if (m_WebRequestAgentHelperCompleteEventHandler == null || m_WebRequestAgentHelperErrorEventHandler == null)
|
||||
{
|
||||
Log.Fatal("Web request agent helper handler is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
m_UnityWebRequest = UnityWebRequest.PostWwwForm(webRequestUri, Utility.Converter.GetString(postData));
|
||||
#if UNITY_2017_2_OR_NEWER
|
||||
m_UnityWebRequest.SendWebRequest();
|
||||
#else
|
||||
m_UnityWebRequest.Send();
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置 Web 请求代理辅助器。
|
||||
/// </summary>
|
||||
public override void Reset()
|
||||
{
|
||||
if (m_UnityWebRequest != null)
|
||||
{
|
||||
m_UnityWebRequest.Dispose();
|
||||
m_UnityWebRequest = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源。
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源。
|
||||
/// </summary>
|
||||
/// <param name="disposing">释放资源标记。</param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (m_Disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
if (m_UnityWebRequest != null)
|
||||
{
|
||||
m_UnityWebRequest.Dispose();
|
||||
m_UnityWebRequest = null;
|
||||
}
|
||||
}
|
||||
|
||||
m_Disposed = true;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (m_UnityWebRequest == null || !m_UnityWebRequest.isDone)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool isError = false;
|
||||
#if UNITY_2020_2_OR_NEWER
|
||||
isError = m_UnityWebRequest.result != UnityWebRequest.Result.Success;
|
||||
#elif UNITY_2017_1_OR_NEWER
|
||||
isError = m_UnityWebRequest.isNetworkError || m_UnityWebRequest.isHttpError;
|
||||
#else
|
||||
isError = m_UnityWebRequest.isError;
|
||||
#endif
|
||||
if (isError)
|
||||
{
|
||||
WebRequestAgentHelperErrorEventArgs webRequestAgentHelperErrorEventArgs = WebRequestAgentHelperErrorEventArgs.Create(m_UnityWebRequest.error);
|
||||
m_WebRequestAgentHelperErrorEventHandler(this, webRequestAgentHelperErrorEventArgs);
|
||||
ReferencePool.Release(webRequestAgentHelperErrorEventArgs);
|
||||
}
|
||||
else if (m_UnityWebRequest.downloadHandler.isDone)
|
||||
{
|
||||
WebRequestAgentHelperCompleteEventArgs webRequestAgentHelperCompleteEventArgs = WebRequestAgentHelperCompleteEventArgs.Create(m_UnityWebRequest.downloadHandler.data);
|
||||
m_WebRequestAgentHelperCompleteEventHandler(this, webRequestAgentHelperCompleteEventArgs);
|
||||
ReferencePool.Release(webRequestAgentHelperCompleteEventArgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e3014b70cd4acd41bed5c829dff3c30
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,54 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using GameFramework;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityGameFramework.Runtime
|
||||
{
|
||||
internal sealed class WWWFormInfo : IReference
|
||||
{
|
||||
private WWWForm m_WWWForm;
|
||||
private object m_UserData;
|
||||
|
||||
public WWWFormInfo()
|
||||
{
|
||||
m_WWWForm = null;
|
||||
m_UserData = null;
|
||||
}
|
||||
|
||||
public WWWForm WWWForm
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_WWWForm;
|
||||
}
|
||||
}
|
||||
|
||||
public object UserData
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_UserData;
|
||||
}
|
||||
}
|
||||
|
||||
public static WWWFormInfo Create(WWWForm wwwForm, object userData)
|
||||
{
|
||||
WWWFormInfo wwwFormInfo = ReferencePool.Acquire<WWWFormInfo>();
|
||||
wwwFormInfo.m_WWWForm = wwwForm;
|
||||
wwwFormInfo.m_UserData = userData;
|
||||
return wwwFormInfo;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
m_WWWForm = null;
|
||||
m_UserData = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 88d3d7e0a6b8b374783b6dc413adfbd7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,166 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
|
||||
using GameFramework;
|
||||
using GameFramework.WebRequest;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityGameFramework.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// WWW Web 请求代理辅助器。
|
||||
/// </summary>
|
||||
public class WWWWebRequestAgentHelper : WebRequestAgentHelperBase, IDisposable
|
||||
{
|
||||
private WWW m_WWW = null;
|
||||
private bool m_Disposed = false;
|
||||
|
||||
private EventHandler<WebRequestAgentHelperCompleteEventArgs> m_WebRequestAgentHelperCompleteEventHandler = null;
|
||||
private EventHandler<WebRequestAgentHelperErrorEventArgs> m_WebRequestAgentHelperErrorEventHandler = null;
|
||||
|
||||
/// <summary>
|
||||
/// Web 请求代理辅助器完成事件。
|
||||
/// </summary>
|
||||
public override event EventHandler<WebRequestAgentHelperCompleteEventArgs> WebRequestAgentHelperComplete
|
||||
{
|
||||
add
|
||||
{
|
||||
m_WebRequestAgentHelperCompleteEventHandler += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
m_WebRequestAgentHelperCompleteEventHandler -= value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Web 请求代理辅助器错误事件。
|
||||
/// </summary>
|
||||
public override event EventHandler<WebRequestAgentHelperErrorEventArgs> WebRequestAgentHelperError
|
||||
{
|
||||
add
|
||||
{
|
||||
m_WebRequestAgentHelperErrorEventHandler += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
m_WebRequestAgentHelperErrorEventHandler -= value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过 Web 请求代理辅助器发送请求。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">要发送的远程地址。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
public override void Request(string webRequestUri, object userData)
|
||||
{
|
||||
if (m_WebRequestAgentHelperCompleteEventHandler == null || m_WebRequestAgentHelperErrorEventHandler == null)
|
||||
{
|
||||
Log.Fatal("Web request agent helper handler is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
WWWFormInfo wwwFormInfo = (WWWFormInfo)userData;
|
||||
if (wwwFormInfo.WWWForm == null)
|
||||
{
|
||||
m_WWW = new WWW(webRequestUri);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_WWW = new WWW(webRequestUri, wwwFormInfo.WWWForm);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过 Web 请求代理辅助器发送请求。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">要发送的远程地址。</param>
|
||||
/// <param name="postData">要发送的数据流。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
public override void Request(string webRequestUri, byte[] postData, object userData)
|
||||
{
|
||||
if (m_WebRequestAgentHelperCompleteEventHandler == null || m_WebRequestAgentHelperErrorEventHandler == null)
|
||||
{
|
||||
Log.Fatal("Web request agent helper handler is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
m_WWW = new WWW(webRequestUri, postData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置 Web 请求代理辅助器。
|
||||
/// </summary>
|
||||
public override void Reset()
|
||||
{
|
||||
if (m_WWW != null)
|
||||
{
|
||||
m_WWW.Dispose();
|
||||
m_WWW = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源。
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源。
|
||||
/// </summary>
|
||||
/// <param name="disposing">释放资源标记。</param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (m_Disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
if (m_WWW != null)
|
||||
{
|
||||
m_WWW.Dispose();
|
||||
m_WWW = null;
|
||||
}
|
||||
}
|
||||
|
||||
m_Disposed = true;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (m_WWW == null || !m_WWW.isDone)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(m_WWW.error))
|
||||
{
|
||||
WebRequestAgentHelperErrorEventArgs webRequestAgentHelperErrorEventArgs = WebRequestAgentHelperErrorEventArgs.Create(m_WWW.error);
|
||||
m_WebRequestAgentHelperErrorEventHandler(this, webRequestAgentHelperErrorEventArgs);
|
||||
ReferencePool.Release(webRequestAgentHelperErrorEventArgs);
|
||||
}
|
||||
else
|
||||
{
|
||||
WebRequestAgentHelperCompleteEventArgs webRequestAgentHelperCompleteEventArgs = WebRequestAgentHelperCompleteEventArgs.Create(m_WWW.bytes);
|
||||
m_WebRequestAgentHelperCompleteEventHandler(this, webRequestAgentHelperCompleteEventArgs);
|
||||
ReferencePool.Release(webRequestAgentHelperCompleteEventArgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 58f7b74a3eef2eb478e90ba95fe21d9f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,49 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using GameFramework.WebRequest;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityGameFramework.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// Web 请求代理辅助器基类。
|
||||
/// </summary>
|
||||
public abstract class WebRequestAgentHelperBase : MonoBehaviour, IWebRequestAgentHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Web 请求代理辅助器完成事件。
|
||||
/// </summary>
|
||||
public abstract event EventHandler<WebRequestAgentHelperCompleteEventArgs> WebRequestAgentHelperComplete;
|
||||
|
||||
/// <summary>
|
||||
/// Web 请求代理辅助器错误事件。
|
||||
/// </summary>
|
||||
public abstract event EventHandler<WebRequestAgentHelperErrorEventArgs> WebRequestAgentHelperError;
|
||||
|
||||
/// <summary>
|
||||
/// 通过 Web 请求代理辅助器发送 Web 请求。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">Web 请求地址。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
public abstract void Request(string webRequestUri, object userData);
|
||||
|
||||
/// <summary>
|
||||
/// 通过 Web 请求代理辅助器发送 Web 请求。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">Web 请求地址。</param>
|
||||
/// <param name="postData">要发送的数据流。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
public abstract void Request(string webRequestUri, byte[] postData, object userData);
|
||||
|
||||
/// <summary>
|
||||
/// 重置 Web 请求代理辅助器。
|
||||
/// </summary>
|
||||
public abstract void Reset();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 435dc9e1aa25c4344b27aa10088d4f1a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,564 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using GameFramework;
|
||||
using GameFramework.WebRequest;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityGameFramework.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// Web 请求组件。
|
||||
/// </summary>
|
||||
[DisallowMultipleComponent]
|
||||
[AddComponentMenu("Game Framework/Web Request")]
|
||||
public sealed class WebRequestComponent : GameFrameworkComponent
|
||||
{
|
||||
private const int DefaultPriority = 0;
|
||||
|
||||
private IWebRequestManager m_WebRequestManager = null;
|
||||
private EventComponent m_EventComponent = null;
|
||||
|
||||
[SerializeField]
|
||||
private Transform m_InstanceRoot = null;
|
||||
|
||||
[SerializeField]
|
||||
private string m_WebRequestAgentHelperTypeName = "UnityGameFramework.Runtime.UnityWebRequestAgentHelper";
|
||||
|
||||
[SerializeField]
|
||||
private WebRequestAgentHelperBase m_CustomWebRequestAgentHelper = null;
|
||||
|
||||
[SerializeField]
|
||||
private int m_WebRequestAgentHelperCount = 1;
|
||||
|
||||
[SerializeField]
|
||||
private float m_Timeout = 30f;
|
||||
|
||||
/// <summary>
|
||||
/// 获取 Web 请求代理总数量。
|
||||
/// </summary>
|
||||
public int TotalAgentCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_WebRequestManager.TotalAgentCount;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取可用 Web 请求代理数量。
|
||||
/// </summary>
|
||||
public int FreeAgentCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_WebRequestManager.FreeAgentCount;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取工作中 Web 请求代理数量。
|
||||
/// </summary>
|
||||
public int WorkingAgentCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_WebRequestManager.WorkingAgentCount;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取等待 Web 请求数量。
|
||||
/// </summary>
|
||||
public int WaitingTaskCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_WebRequestManager.WaitingTaskCount;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置 Web 请求超时时长,以秒为单位。
|
||||
/// </summary>
|
||||
public float Timeout
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_WebRequestManager.Timeout;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_WebRequestManager.Timeout = m_Timeout = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 游戏框架组件初始化。
|
||||
/// </summary>
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
|
||||
m_WebRequestManager = GameFrameworkEntry.GetModule<IWebRequestManager>();
|
||||
if (m_WebRequestManager == null)
|
||||
{
|
||||
Log.Fatal("Web request manager is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
m_WebRequestManager.Timeout = m_Timeout;
|
||||
m_WebRequestManager.WebRequestStart += OnWebRequestStart;
|
||||
m_WebRequestManager.WebRequestSuccess += OnWebRequestSuccess;
|
||||
m_WebRequestManager.WebRequestFailure += OnWebRequestFailure;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
m_EventComponent = GameEntry.GetComponent<EventComponent>();
|
||||
if (m_EventComponent == null)
|
||||
{
|
||||
Log.Fatal("Event component is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_InstanceRoot == null)
|
||||
{
|
||||
m_InstanceRoot = new GameObject("Web Request Agent Instances").transform;
|
||||
m_InstanceRoot.SetParent(gameObject.transform);
|
||||
m_InstanceRoot.localScale = Vector3.one;
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_WebRequestAgentHelperCount; i++)
|
||||
{
|
||||
AddWebRequestAgentHelper(i);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据 Web 请求任务的序列编号获取 Web 请求任务的信息。
|
||||
/// </summary>
|
||||
/// <param name="serialId">要获取信息的 Web 请求任务的序列编号。</param>
|
||||
/// <returns>Web 请求任务的信息。</returns>
|
||||
public TaskInfo GetWebRequestInfo(int serialId)
|
||||
{
|
||||
return m_WebRequestManager.GetWebRequestInfo(serialId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据 Web 请求任务的标签获取 Web 请求任务的信息。
|
||||
/// </summary>
|
||||
/// <param name="tag">要获取信息的 Web 请求任务的标签。</param>
|
||||
/// <returns>Web 请求任务的信息。</returns>
|
||||
public TaskInfo[] GetWebRequestInfos(string tag)
|
||||
{
|
||||
return m_WebRequestManager.GetWebRequestInfos(tag);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据 Web 请求任务的标签获取 Web 请求任务的信息。
|
||||
/// </summary>
|
||||
/// <param name="tag">要获取信息的 Web 请求任务的标签。</param>
|
||||
/// <param name="results">Web 请求任务的信息。</param>
|
||||
public void GetAllWebRequestInfos(string tag, List<TaskInfo> results)
|
||||
{
|
||||
m_WebRequestManager.GetAllWebRequestInfos(tag, results);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有 Web 请求任务的信息。
|
||||
/// </summary>
|
||||
/// <returns>所有 Web 请求任务的信息。</returns>
|
||||
public TaskInfo[] GetAllWebRequestInfos()
|
||||
{
|
||||
return m_WebRequestManager.GetAllWebRequestInfos();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有 Web 请求任务的信息。
|
||||
/// </summary>
|
||||
/// <param name="results">所有 Web 请求任务的信息。</param>
|
||||
public void GetAllWebRequestInfos(List<TaskInfo> results)
|
||||
{
|
||||
m_WebRequestManager.GetAllWebRequestInfos(results);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加 Web 请求任务。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">Web 请求地址。</param>
|
||||
/// <returns>新增 Web 请求任务的序列编号。</returns>
|
||||
public int AddWebRequest(string webRequestUri)
|
||||
{
|
||||
return AddWebRequest(webRequestUri, null, null, null, DefaultPriority, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加 Web 请求任务。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">Web 请求地址。</param>
|
||||
/// <param name="postData">要发送的数据流。</param>
|
||||
/// <returns>新增 Web 请求任务的序列编号。</returns>
|
||||
public int AddWebRequest(string webRequestUri, byte[] postData)
|
||||
{
|
||||
return AddWebRequest(webRequestUri, postData, null, null, DefaultPriority, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加 Web 请求任务。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">Web 请求地址。</param>
|
||||
/// <param name="wwwForm">WWW 表单。</param>
|
||||
/// <returns>新增 Web 请求任务的序列编号。</returns>
|
||||
public int AddWebRequest(string webRequestUri, WWWForm wwwForm)
|
||||
{
|
||||
return AddWebRequest(webRequestUri, null, wwwForm, null, DefaultPriority, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加 Web 请求任务。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">Web 请求地址。</param>
|
||||
/// <param name="tag">Web 请求任务的标签。</param>
|
||||
/// <returns>新增 Web 请求任务的序列编号。</returns>
|
||||
public int AddWebRequest(string webRequestUri, string tag)
|
||||
{
|
||||
return AddWebRequest(webRequestUri, null, null, tag, DefaultPriority, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加 Web 请求任务。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">Web 请求地址。</param>
|
||||
/// <param name="priority">Web 请求任务的优先级。</param>
|
||||
/// <returns>新增 Web 请求任务的序列编号。</returns>
|
||||
public int AddWebRequest(string webRequestUri, int priority)
|
||||
{
|
||||
return AddWebRequest(webRequestUri, null, null, null, priority, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加 Web 请求任务。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">Web 请求地址。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>新增 Web 请求任务的序列编号。</returns>
|
||||
public int AddWebRequest(string webRequestUri, object userData)
|
||||
{
|
||||
return AddWebRequest(webRequestUri, null, null, null, DefaultPriority, userData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加 Web 请求任务。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">Web 请求地址。</param>
|
||||
/// <param name="postData">要发送的数据流。</param>
|
||||
/// <param name="tag">Web 请求任务的标签。</param>
|
||||
/// <returns>新增 Web 请求任务的序列编号。</returns>
|
||||
public int AddWebRequest(string webRequestUri, byte[] postData, string tag)
|
||||
{
|
||||
return AddWebRequest(webRequestUri, postData, null, tag, DefaultPriority, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加 Web 请求任务。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">Web 请求地址。</param>
|
||||
/// <param name="wwwForm">WWW 表单。</param>
|
||||
/// <param name="tag">Web 请求任务的标签。</param>
|
||||
/// <returns>新增 Web 请求任务的序列编号。</returns>
|
||||
public int AddWebRequest(string webRequestUri, WWWForm wwwForm, string tag)
|
||||
{
|
||||
return AddWebRequest(webRequestUri, null, wwwForm, tag, DefaultPriority, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加 Web 请求任务。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">Web 请求地址。</param>
|
||||
/// <param name="postData">要发送的数据流。</param>
|
||||
/// <param name="priority">Web 请求任务的优先级。</param>
|
||||
/// <returns>新增 Web 请求任务的序列编号。</returns>
|
||||
public int AddWebRequest(string webRequestUri, byte[] postData, int priority)
|
||||
{
|
||||
return AddWebRequest(webRequestUri, postData, null, null, priority, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加 Web 请求任务。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">Web 请求地址。</param>
|
||||
/// <param name="wwwForm">WWW 表单。</param>
|
||||
/// <param name="priority">Web 请求任务的优先级。</param>
|
||||
/// <returns>新增 Web 请求任务的序列编号。</returns>
|
||||
public int AddWebRequest(string webRequestUri, WWWForm wwwForm, int priority)
|
||||
{
|
||||
return AddWebRequest(webRequestUri, null, wwwForm, null, priority, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加 Web 请求任务。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">Web 请求地址。</param>
|
||||
/// <param name="postData">要发送的数据流。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>新增 Web 请求任务的序列编号。</returns>
|
||||
public int AddWebRequest(string webRequestUri, byte[] postData, object userData)
|
||||
{
|
||||
return AddWebRequest(webRequestUri, postData, null, null, DefaultPriority, userData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加 Web 请求任务。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">Web 请求地址。</param>
|
||||
/// <param name="wwwForm">WWW 表单。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>新增 Web 请求任务的序列编号。</returns>
|
||||
public int AddWebRequest(string webRequestUri, WWWForm wwwForm, object userData)
|
||||
{
|
||||
return AddWebRequest(webRequestUri, null, wwwForm, null, DefaultPriority, userData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加 Web 请求任务。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">Web 请求地址。</param>
|
||||
/// <param name="tag">Web 请求任务的标签。</param>
|
||||
/// <param name="priority">Web 请求任务的优先级。</param>
|
||||
/// <returns>新增 Web 请求任务的序列编号。</returns>
|
||||
public int AddWebRequest(string webRequestUri, string tag, int priority)
|
||||
{
|
||||
return AddWebRequest(webRequestUri, null, null, tag, priority, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加 Web 请求任务。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">Web 请求地址。</param>
|
||||
/// <param name="tag">Web 请求任务的标签。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>新增 Web 请求任务的序列编号。</returns>
|
||||
public int AddWebRequest(string webRequestUri, string tag, object userData)
|
||||
{
|
||||
return AddWebRequest(webRequestUri, null, null, tag, DefaultPriority, userData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加 Web 请求任务。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">Web 请求地址。</param>
|
||||
/// <param name="priority">Web 请求任务的优先级。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>新增 Web 请求任务的序列编号。</returns>
|
||||
public int AddWebRequest(string webRequestUri, int priority, object userData)
|
||||
{
|
||||
return AddWebRequest(webRequestUri, null, null, null, priority, userData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加 Web 请求任务。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">Web 请求地址。</param>
|
||||
/// <param name="postData">要发送的数据流。</param>
|
||||
/// <param name="tag">Web 请求任务的标签。</param>
|
||||
/// <param name="priority">Web 请求任务的优先级。</param>
|
||||
/// <returns>新增 Web 请求任务的序列编号。</returns>
|
||||
public int AddWebRequest(string webRequestUri, byte[] postData, string tag, int priority)
|
||||
{
|
||||
return AddWebRequest(webRequestUri, postData, null, tag, priority, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加 Web 请求任务。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">Web 请求地址。</param>
|
||||
/// <param name="wwwForm">WWW 表单。</param>
|
||||
/// <param name="tag">Web 请求任务的标签。</param>
|
||||
/// <param name="priority">Web 请求任务的优先级。</param>
|
||||
/// <returns>新增 Web 请求任务的序列编号。</returns>
|
||||
public int AddWebRequest(string webRequestUri, WWWForm wwwForm, string tag, int priority)
|
||||
{
|
||||
return AddWebRequest(webRequestUri, null, wwwForm, tag, priority, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加 Web 请求任务。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">Web 请求地址。</param>
|
||||
/// <param name="postData">要发送的数据流。</param>
|
||||
/// <param name="tag">Web 请求任务的标签。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>新增 Web 请求任务的序列编号。</returns>
|
||||
public int AddWebRequest(string webRequestUri, byte[] postData, string tag, object userData)
|
||||
{
|
||||
return AddWebRequest(webRequestUri, postData, null, tag, DefaultPriority, userData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加 Web 请求任务。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">Web 请求地址。</param>
|
||||
/// <param name="wwwForm">WWW 表单。</param>
|
||||
/// <param name="tag">Web 请求任务的标签。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>新增 Web 请求任务的序列编号。</returns>
|
||||
public int AddWebRequest(string webRequestUri, WWWForm wwwForm, string tag, object userData)
|
||||
{
|
||||
return AddWebRequest(webRequestUri, null, wwwForm, tag, DefaultPriority, userData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加 Web 请求任务。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">Web 请求地址。</param>
|
||||
/// <param name="postData">要发送的数据流。</param>
|
||||
/// <param name="priority">Web 请求任务的优先级。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>新增 Web 请求任务的序列编号。</returns>
|
||||
public int AddWebRequest(string webRequestUri, byte[] postData, int priority, object userData)
|
||||
{
|
||||
return AddWebRequest(webRequestUri, postData, null, null, priority, userData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加 Web 请求任务。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">Web 请求地址。</param>
|
||||
/// <param name="wwwForm">WWW 表单。</param>
|
||||
/// <param name="priority">Web 请求任务的优先级。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>新增 Web 请求任务的序列编号。</returns>
|
||||
public int AddWebRequest(string webRequestUri, WWWForm wwwForm, int priority, object userData)
|
||||
{
|
||||
return AddWebRequest(webRequestUri, null, wwwForm, null, priority, userData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加 Web 请求任务。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">Web 请求地址。</param>
|
||||
/// <param name="tag">Web 请求任务的标签。</param>
|
||||
/// <param name="priority">Web 请求任务的优先级。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>新增 Web 请求任务的序列编号。</returns>
|
||||
public int AddWebRequest(string webRequestUri, string tag, int priority, object userData)
|
||||
{
|
||||
return AddWebRequest(webRequestUri, null, null, tag, priority, userData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加 Web 请求任务。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">Web 请求地址。</param>
|
||||
/// <param name="postData">要发送的数据流。</param>
|
||||
/// <param name="tag">Web 请求任务的标签。</param>
|
||||
/// <param name="priority">Web 请求任务的优先级。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>新增 Web 请求任务的序列编号。</returns>
|
||||
public int AddWebRequest(string webRequestUri, byte[] postData, string tag, int priority, object userData)
|
||||
{
|
||||
return AddWebRequest(webRequestUri, postData, null, tag, priority, userData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加 Web 请求任务。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">Web 请求地址。</param>
|
||||
/// <param name="wwwForm">WWW 表单。</param>
|
||||
/// <param name="tag">Web 请求任务的标签。</param>
|
||||
/// <param name="priority">Web 请求任务的优先级。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>新增 Web 请求任务的序列编号。</returns>
|
||||
public int AddWebRequest(string webRequestUri, WWWForm wwwForm, string tag, int priority, object userData)
|
||||
{
|
||||
return AddWebRequest(webRequestUri, null, wwwForm, tag, priority, userData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据 Web 请求任务的序列编号移除 Web 请求任务。
|
||||
/// </summary>
|
||||
/// <param name="serialId">要移除 Web 请求任务的序列编号。</param>
|
||||
/// <returns>是否移除 Web 请求任务成功。</returns>
|
||||
public bool RemoveWebRequest(int serialId)
|
||||
{
|
||||
return m_WebRequestManager.RemoveWebRequest(serialId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据 Web 请求任务的标签移除 Web 请求任务。
|
||||
/// </summary>
|
||||
/// <param name="tag">要移除 Web 请求任务的标签。</param>
|
||||
/// <returns>移除 Web 请求任务的数量。</returns>
|
||||
public int RemoveWebRequests(string tag)
|
||||
{
|
||||
return m_WebRequestManager.RemoveWebRequests(tag);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除所有 Web 请求任务。
|
||||
/// </summary>
|
||||
/// <returns>移除 Web 请求任务的数量。</returns>
|
||||
public int RemoveAllWebRequests()
|
||||
{
|
||||
return m_WebRequestManager.RemoveAllWebRequests();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加 Web 请求代理辅助器。
|
||||
/// </summary>
|
||||
/// <param name="index">Web 请求代理辅助器索引。</param>
|
||||
private void AddWebRequestAgentHelper(int index)
|
||||
{
|
||||
WebRequestAgentHelperBase webRequestAgentHelper = Helper.CreateHelper(m_WebRequestAgentHelperTypeName, m_CustomWebRequestAgentHelper, index);
|
||||
if (webRequestAgentHelper == null)
|
||||
{
|
||||
Log.Error("Can not create web request agent helper.");
|
||||
return;
|
||||
}
|
||||
|
||||
webRequestAgentHelper.name = Utility.Text.Format("Web Request Agent Helper - {0}", index);
|
||||
Transform transform = webRequestAgentHelper.transform;
|
||||
transform.SetParent(m_InstanceRoot);
|
||||
transform.localScale = Vector3.one;
|
||||
|
||||
m_WebRequestManager.AddWebRequestAgentHelper(webRequestAgentHelper);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加 Web 请求任务。
|
||||
/// </summary>
|
||||
/// <param name="webRequestUri">Web 请求地址。</param>
|
||||
/// <param name="postData">要发送的数据流。</param>
|
||||
/// <param name="wwwForm">WWW 表单。</param>
|
||||
/// <param name="tag">Web 请求任务的标签。</param>
|
||||
/// <param name="priority">Web 请求任务的优先级。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>新增 Web 请求任务的序列编号。</returns>
|
||||
private int AddWebRequest(string webRequestUri, byte[] postData, WWWForm wwwForm, string tag, int priority, object userData)
|
||||
{
|
||||
return m_WebRequestManager.AddWebRequest(webRequestUri, postData, tag, priority, WWWFormInfo.Create(wwwForm, userData));
|
||||
}
|
||||
|
||||
private void OnWebRequestStart(object sender, GameFramework.WebRequest.WebRequestStartEventArgs e)
|
||||
{
|
||||
m_EventComponent.Fire(this, WebRequestStartEventArgs.Create(e));
|
||||
}
|
||||
|
||||
private void OnWebRequestSuccess(object sender, GameFramework.WebRequest.WebRequestSuccessEventArgs e)
|
||||
{
|
||||
m_EventComponent.Fire(this, WebRequestSuccessEventArgs.Create(e));
|
||||
}
|
||||
|
||||
private void OnWebRequestFailure(object sender, GameFramework.WebRequest.WebRequestFailureEventArgs e)
|
||||
{
|
||||
Log.Warning("Web request failure, web request serial id '{0}', web request uri '{1}', error message '{2}'.", e.SerialId, e.WebRequestUri, e.ErrorMessage);
|
||||
m_EventComponent.Fire(this, WebRequestFailureEventArgs.Create(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 02988897571ac8b49a59c1a50037bd88
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,109 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using GameFramework;
|
||||
using GameFramework.Event;
|
||||
|
||||
namespace UnityGameFramework.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// Web 请求失败事件。
|
||||
/// </summary>
|
||||
public sealed class WebRequestFailureEventArgs : GameEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// Web 请求失败事件编号。
|
||||
/// </summary>
|
||||
public static readonly int EventId = typeof(WebRequestFailureEventArgs).GetHashCode();
|
||||
|
||||
/// <summary>
|
||||
/// 初始化 Web 请求失败事件的新实例。
|
||||
/// </summary>
|
||||
public WebRequestFailureEventArgs()
|
||||
{
|
||||
SerialId = 0;
|
||||
WebRequestUri = null;
|
||||
ErrorMessage = null;
|
||||
UserData = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 Web 请求失败事件编号。
|
||||
/// </summary>
|
||||
public override int Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return EventId;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 Web 请求任务的序列编号。
|
||||
/// </summary>
|
||||
public int SerialId
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 Web 请求地址。
|
||||
/// </summary>
|
||||
public string WebRequestUri
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取错误信息。
|
||||
/// </summary>
|
||||
public string ErrorMessage
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户自定义数据。
|
||||
/// </summary>
|
||||
public object UserData
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建 Web 请求失败事件。
|
||||
/// </summary>
|
||||
/// <param name="e">内部事件。</param>
|
||||
/// <returns>创建的 Web 请求失败事件。</returns>
|
||||
public static WebRequestFailureEventArgs Create(GameFramework.WebRequest.WebRequestFailureEventArgs e)
|
||||
{
|
||||
WWWFormInfo wwwFormInfo = (WWWFormInfo)e.UserData;
|
||||
WebRequestFailureEventArgs webRequestFailureEventArgs = ReferencePool.Acquire<WebRequestFailureEventArgs>();
|
||||
webRequestFailureEventArgs.SerialId = e.SerialId;
|
||||
webRequestFailureEventArgs.WebRequestUri = e.WebRequestUri;
|
||||
webRequestFailureEventArgs.ErrorMessage = e.ErrorMessage;
|
||||
webRequestFailureEventArgs.UserData = wwwFormInfo.UserData;
|
||||
ReferencePool.Release(wwwFormInfo);
|
||||
return webRequestFailureEventArgs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理 Web 请求失败事件。
|
||||
/// </summary>
|
||||
public override void Clear()
|
||||
{
|
||||
SerialId = 0;
|
||||
WebRequestUri = null;
|
||||
ErrorMessage = null;
|
||||
UserData = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 582d860310370aa47b4fa671963e0200
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,96 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using GameFramework;
|
||||
using GameFramework.Event;
|
||||
|
||||
namespace UnityGameFramework.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// Web 请求开始事件。
|
||||
/// </summary>
|
||||
public sealed class WebRequestStartEventArgs : GameEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// Web 请求开始事件编号。
|
||||
/// </summary>
|
||||
public static readonly int EventId = typeof(WebRequestStartEventArgs).GetHashCode();
|
||||
|
||||
/// <summary>
|
||||
/// 初始化 Web 请求开始事件的新实例。
|
||||
/// </summary>
|
||||
public WebRequestStartEventArgs()
|
||||
{
|
||||
SerialId = 0;
|
||||
WebRequestUri = null;
|
||||
UserData = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 Web 请求开始事件编号。
|
||||
/// </summary>
|
||||
public override int Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return EventId;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 Web 请求任务的序列编号。
|
||||
/// </summary>
|
||||
public int SerialId
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 Web 请求地址。
|
||||
/// </summary>
|
||||
public string WebRequestUri
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户自定义数据。
|
||||
/// </summary>
|
||||
public object UserData
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建 Web 请求开始事件。
|
||||
/// </summary>
|
||||
/// <param name="e">内部事件。</param>
|
||||
/// <returns>创建的 Web 请求开始事件。</returns>
|
||||
public static WebRequestStartEventArgs Create(GameFramework.WebRequest.WebRequestStartEventArgs e)
|
||||
{
|
||||
WWWFormInfo wwwFormInfo = (WWWFormInfo)e.UserData;
|
||||
WebRequestStartEventArgs webRequestStartEventArgs = ReferencePool.Acquire<WebRequestStartEventArgs>();
|
||||
webRequestStartEventArgs.SerialId = e.SerialId;
|
||||
webRequestStartEventArgs.WebRequestUri = e.WebRequestUri;
|
||||
webRequestStartEventArgs.UserData = wwwFormInfo.UserData;
|
||||
return webRequestStartEventArgs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理 Web 请求开始事件。
|
||||
/// </summary>
|
||||
public override void Clear()
|
||||
{
|
||||
SerialId = 0;
|
||||
WebRequestUri = null;
|
||||
UserData = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3f73533092cec3d498691d5805a8f856
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,111 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using GameFramework;
|
||||
using GameFramework.Event;
|
||||
|
||||
namespace UnityGameFramework.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// Web 请求成功事件。
|
||||
/// </summary>
|
||||
public sealed class WebRequestSuccessEventArgs : GameEventArgs
|
||||
{
|
||||
private byte[] m_WebResponseBytes = null;
|
||||
|
||||
/// <summary>
|
||||
/// Web 请求成功事件编号。
|
||||
/// </summary>
|
||||
public static readonly int EventId = typeof(WebRequestSuccessEventArgs).GetHashCode();
|
||||
|
||||
/// <summary>
|
||||
/// 初始化 Web 请求成功事件的新实例。
|
||||
/// </summary>
|
||||
public WebRequestSuccessEventArgs()
|
||||
{
|
||||
SerialId = 0;
|
||||
WebRequestUri = null;
|
||||
m_WebResponseBytes = null;
|
||||
UserData = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 Web 请求成功事件编号。
|
||||
/// </summary>
|
||||
public override int Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return EventId;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 Web 请求任务的序列编号。
|
||||
/// </summary>
|
||||
public int SerialId
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 Web 请求地址。
|
||||
/// </summary>
|
||||
public string WebRequestUri
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户自定义数据。
|
||||
/// </summary>
|
||||
public object UserData
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 Web 响应的数据流。
|
||||
/// </summary>
|
||||
/// <returns>Web 响应的数据流。</returns>
|
||||
public byte[] GetWebResponseBytes()
|
||||
{
|
||||
return m_WebResponseBytes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建 Web 请求成功事件。
|
||||
/// </summary>
|
||||
/// <param name="e">内部事件。</param>
|
||||
/// <returns>创建的 Web 请求成功事件。</returns>
|
||||
public static WebRequestSuccessEventArgs Create(GameFramework.WebRequest.WebRequestSuccessEventArgs e)
|
||||
{
|
||||
WWWFormInfo wwwFormInfo = (WWWFormInfo)e.UserData;
|
||||
WebRequestSuccessEventArgs webRequestSuccessEventArgs = ReferencePool.Acquire<WebRequestSuccessEventArgs>();
|
||||
webRequestSuccessEventArgs.SerialId = e.SerialId;
|
||||
webRequestSuccessEventArgs.WebRequestUri = e.WebRequestUri;
|
||||
webRequestSuccessEventArgs.m_WebResponseBytes = e.GetWebResponseBytes();
|
||||
webRequestSuccessEventArgs.UserData = wwwFormInfo.UserData;
|
||||
ReferencePool.Release(wwwFormInfo);
|
||||
return webRequestSuccessEventArgs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理 Web 请求成功事件。
|
||||
/// </summary>
|
||||
public override void Clear()
|
||||
{
|
||||
SerialId = 0;
|
||||
WebRequestUri = null;
|
||||
m_WebResponseBytes = null;
|
||||
UserData = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 12523ea48f6be044592256bf32605f5d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user