2023-06-05 19:57:17 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.Networking;
|
|
|
|
using System.Threading;
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
using System.Net;
|
|
|
|
using System.Net.Http;
|
|
|
|
using UnityEngine.UIElements;
|
|
|
|
using System.Text;
|
|
|
|
using System.Linq;
|
|
|
|
using BITKit.HttpNet;
|
2023-06-07 18:38:07 +08:00
|
|
|
#if UNITY_EDITOR
|
|
|
|
using UnityEditor;
|
|
|
|
#endif
|
|
|
|
|
2023-06-05 19:57:17 +08:00
|
|
|
namespace BITKit
|
|
|
|
{
|
2023-06-07 18:38:07 +08:00
|
|
|
public class NetworkPost : Provider
|
2023-06-05 19:57:17 +08:00
|
|
|
{
|
|
|
|
[SubclassSelector, SerializeReference] public References _url;
|
|
|
|
[SubclassSelector, SerializeReference] public WebProvider webProvider;
|
|
|
|
public string result;
|
|
|
|
public int postCount;
|
|
|
|
public int resultCount;
|
|
|
|
public string content;
|
2023-06-07 18:38:07 +08:00
|
|
|
private readonly LimitTimes limitTimes = new();
|
|
|
|
public async void Set(object value)
|
|
|
|
{
|
|
|
|
postCount++;
|
|
|
|
content = await webProvider.PostAsync(_url, value);
|
|
|
|
resultCount++;
|
|
|
|
}
|
2023-06-05 19:57:17 +08:00
|
|
|
public override async void Set<T>(T obj)
|
|
|
|
{
|
|
|
|
switch (obj)
|
|
|
|
{
|
|
|
|
case WWWForm formFields:
|
|
|
|
if (limitTimes)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
NetworkCore.Add(_url);
|
|
|
|
postCount++;
|
|
|
|
|
|
|
|
result = await webProvider.PostAsync(_url, formFields);
|
|
|
|
|
|
|
|
resultCount++;
|
|
|
|
limitTimes.Release();
|
|
|
|
|
|
|
|
content = JsonConvert.SerializeObject(formFields);
|
|
|
|
}
|
|
|
|
catch (System.Exception e)
|
|
|
|
{
|
|
|
|
if (e is not OperationCanceledException or TimeoutException)
|
|
|
|
{
|
|
|
|
Debug.LogException(e, this);
|
|
|
|
}
|
|
|
|
limitTimes.Release();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case string _string:
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
[UnityEditor.CustomEditor(typeof(NetworkPost))]
|
|
|
|
public class NetworkPostInspector : BITInspector<NetworkPost>
|
|
|
|
{
|
2023-06-07 18:38:07 +08:00
|
|
|
protected override void OnAwake()
|
|
|
|
{
|
|
|
|
var uss = AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/BITKit/UX/Common/NetworkPost");
|
|
|
|
root.root.styleSheets.Add(uss);
|
|
|
|
}
|
2023-06-05 19:57:17 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|