using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
public static class InterfaceManager
{
private static string _IP = "192.168.1.4";
public static string IP
{
get { return _IP; }
set
{
if (_IP != value)
_IP = value;
}
}
private static string _Port = "48888";
public static string Port
{
get { return _Port; }
set
{
if (_Port != value)
_Port = value;
}
}
public static string IpAddress { get => string.Format("http://{0}:{1}", IP, Port); }
#region 接口
///
/// 想定Wbe接口
///
public static string Url_Action { get => IpAddress + "/Handler/Thinkingfile.ashx?action=all"; }
///
/// 修改想定设备参数
///
public static string Url_Updatedevicepara { get => IpAddress + "/Handler/Thinkingfile.ashx?action=updatedevicepara"; }
///
/// 查询想定设备参数
///
public static string Url_Querydevicepara { get => IpAddress + "/Handler/Thinkingfile.ashx?action=querydevicepara&"; }
///
/// 查询想定设备
///
public static string Url_Querydevice { get => IpAddress + "/Handler/Thinkingfile.ashx?action=querydevice&"; }
///
/// 添加设备
///
public static string Url_Adddevice { get => IpAddress + "/Handler/Thinkingfile.ashx?action=adddevice"; }
///
/// 添加设备参数
///
public static string Url_Adddevicepara { get => IpAddress + "/Handler/Thinkingfile.ashx?action=adddevicepara"; }
///
/// 修改想定接口
///
public static string Url_updatedevice { get => IpAddress + "/Handler/Thinkingfile.ashx?action=updatedevice"; }
///
/// 添加模型路径参数接口
///
public static string Url_updatecontent { get => IpAddress + "/Handler/Thinkingfile.ashx?action=updatecontent"; }
///
/// 修改环境
///
public static string Url_update_env { get => IpAddress + "/Handler/Thinkingfile.ashx?action=update_env"; }
///
/// 删除房间想定设备详情
///
public static string Url_Deletepracticedevicedetail { get => IpAddress + "/Handler/Thinkingfile.ashx?action=deletepracticedevicedetail"; }
///
/// 获取所有得房间信息
///
public static string Url_RoomList { get => IpAddress + "/Handler/Practice.ashx?action=query&state=0,1,2"; }
///
/// 学员信息
///
public static string Url_StudentList { get => IpAddress + "/Handler/User.ashx?action=all&role_code=04"; }
///
/// 查询房间科目
///
public static string Url_QueryPracticeSubject { get => IpAddress + "/Handler/Practice.ashx?action=querypracticesubject&PracticeId="; }
///
/// 查询科目席位
///
public static string Url_QueryPracticeSeat { get => IpAddress + "/Handler/Practice.ashx?action=querypracticeseat&PracticeId="; }
///
/// 编辑席位信息
///
public static string Url_EnditorSeatInfo { get => IpAddress + "/Handler/PracticeSeat.ashx?action=UpdatePracticeSeatOne&practiceseatId="; }
///
/// 获取房间ID并添加房间
///
public static string Url_GetRoomID{get => IpAddress + "/Handler/Practice.ashx?action=add&Name=";}
///
/// 更新房间状态
///
public static string Url_UpdateRoomState { get => IpAddress + "/Handler/Practice.ashx?action=updatestate&Id="; }
///
/// 获取房间设备
///
public static string Url_QueryPracticeDevice { get => IpAddress + "/Handler/Thinkingfile.ashx?action=querypracticedevicedetail&PracticeId="; }
///
/// 获取想定编辑中的设备
///
public static string Url_GetAllPracticeThinkDevice { get => IpAddress + "/Handler/Thinkingfile.ashx?action=practicethinkdevice&Id="; }
///
/// 获取所有想定
///
public static string Url_GetAllThinkData { get => IpAddress + "/Handler/Thinkingfile.ashx?action=all"; }
///
/// 获取房间信息
///
public static string Url_GetSceneInfo { get => IpAddress + "/Handler/Thinkingfile.ashx?action=practicethink&Id="; }
///
/// 添加设备并返回设备ID
///
public static string Url_AddDeviceAndGetDeviceId { get => IpAddress + "/Handler/Thinkingfile.ashx?action=addpracticedevicedetail"; }
///
/// 添加房间作战日志
///
public static string Url_Addpracticelog { get => IpAddress + "/Handler/Practice.ashx?action=addpracticelog"; }
///
/// 查询房间作战日志
///
public static string Url_Querypracticelog { get => IpAddress + "/Handler/Practice.ashx?action=querypracticelog&PracticeId="; }
#endregion
public static string GetLocalTxt(string path)
{
using (System.IO.StreamReader reader = new System.IO.StreamReader(path)) { return reader.ReadToEnd(); }
}
public static IEnumerator GetBytes(string url, Action callback)
{
using (UnityWebRequest www = UnityWebRequest.Get(url))
{
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
callback(null);
Debug.Log("网络请求失败了");
}
else
{
if (!string.IsNullOrEmpty(www.downloadHandler.text))
{
callback(www.downloadHandler.text);
}
else
{
callback(null);
}
}
}
}
public static IEnumerator GetString(string url, Action callback)
{
using (UnityWebRequest www = UnityWebRequest.Get(url))
{
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
callback(null);
Debug.Log("网络请求失败了");
}
else
{
if (!string.IsNullOrEmpty(www.downloadHandler.text))
{
callback(www.downloadHandler.text);
}
else
{
callback(null);
}
}
}
}
public static IEnumerator GetString(string url, int time, Action callback)
{
while (true)
{
using (UnityWebRequest www = UnityWebRequest.Get(url))
{
yield return new WaitForSeconds(time); // 每隔 time 秒调用一次接口
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
callback(null);
Debug.Log("网络请求失败了");
}
else
{
if (!string.IsNullOrEmpty(www.downloadHandler.text))
{
callback(www.downloadHandler.text);
}
else
{
callback(null);
}
}
}
}
}
public static IEnumerator PostString(string url, WWWForm formdata, Dictionary headers = null, Action callback = null)
{
using (UnityWebRequest www = UnityWebRequest.Post(url, formdata))
{
foreach (var item in headers)
{
www.SetRequestHeader(item.Key, item.Value);
}
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
callback(null);
Debug.Log("网络请求失败了");
}
else
{
if (!string.IsNullOrEmpty(www.downloadHandler.text))
{
callback(www.downloadHandler.text);
}
else
{
callback(null);
}
}
}
}
public static IEnumerator PostString(string url, WWWForm formdata, Action callback = null)
{
using (UnityWebRequest www = UnityWebRequest.Post(url, formdata))
{
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
callback(null);
Debug.Log("网络请求失败了");
}
else
{
if (!string.IsNullOrEmpty(www.downloadHandler.text))
{
callback(www.downloadHandler.text);
}
else
{
callback(null);
}
}
}
}
public static IEnumerator GetString(string url, Dictionary headers = null,int time=50,Action callback = null)
{
while (true)
{
using (UnityWebRequest www = UnityWebRequest.Get(url))
{
yield return new WaitForSeconds(time); // 每隔 time 秒调用一次接口
foreach (var item in headers)
{
www.SetRequestHeader(item.Key, item.Value);
}
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
callback(null);
Debug.Log("网络请求失败了");
}
else
{
if (!string.IsNullOrEmpty(www.downloadHandler.text))
{
callback(www.downloadHandler.text);
}
else
{
callback(null);
}
}
}
}
}
public static IEnumerator GetString(string url, Dictionary headers = null, Action callback = null)
{
using (UnityWebRequest www = UnityWebRequest.Get(url))
{
foreach (var item in headers)
{
www.SetRequestHeader(item.Key, item.Value);
}
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
callback(null);
Debug.Log("网络请求失败了");
}
else
{
if (!string.IsNullOrEmpty(www.downloadHandler.text))
{
callback(www.downloadHandler.text);
}
else
{
callback(null);
}
}
}
}
}