1
This commit is contained in:
75
Unity/Scripts/Network/NetworkPost.cs
Normal file
75
Unity/Scripts/Network/NetworkPost.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
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;
|
||||
namespace BITKit
|
||||
{
|
||||
public class NetworkPost : Provider, ICustomInspector
|
||||
{
|
||||
[SubclassSelector, SerializeReference] public References _url;
|
||||
[SubclassSelector, SerializeReference] public WebProvider webProvider;
|
||||
public string result;
|
||||
public int postCount;
|
||||
public int resultCount;
|
||||
public string content;
|
||||
public VisualTreeAsset customTreeAsset;
|
||||
public VisualTreeAsset GetCustomTreeAsset() => customTreeAsset;
|
||||
StringBuilder stringBuilder = new();
|
||||
LimitTimes limitTimes = new();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public VisualElement GetVisualElement() => customTreeAsset?.CloneTree();
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.CustomEditor(typeof(NetworkPost))]
|
||||
public class NetworkPostInspector : BITInspector<NetworkPost>
|
||||
{
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
Reference in New Issue
Block a user