264 lines
6.8 KiB
C#
264 lines
6.8 KiB
C#
using Newtonsoft.Json;
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Threading.Tasks;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using static GameManager;
|
||
/// <summary>
|
||
/// 端口-新增
|
||
/// </summary>
|
||
public class AddPort : MonoBehaviour
|
||
{
|
||
public Root URlreturn;
|
||
public Body mybody;
|
||
public Button save_bt;
|
||
|
||
|
||
public InputField port;
|
||
|
||
public InputField portCode;
|
||
|
||
public InputField portName;
|
||
|
||
public InputField portType;
|
||
|
||
public Dropdown deviceId;
|
||
|
||
//public InputField portModel;
|
||
|
||
public Dropdown status;
|
||
|
||
public Dropdown conDevice;
|
||
|
||
public Dropdown conPort;
|
||
|
||
public InputField remark;
|
||
|
||
private void OnEnable()
|
||
{
|
||
init();
|
||
}
|
||
|
||
private void init()
|
||
{
|
||
deviceId.options.Clear();
|
||
List<string> deviceId_ops = new List<string>();
|
||
//for (int i = 0; i < GameManager.Inst.Racks_go.Count; i++)
|
||
//{
|
||
// var n = GameManager.Inst.Racks_go[i].GetComponent<DeviceQuery>().deviceList.id;
|
||
// deviceId_ops.Add(n);
|
||
//}
|
||
//for (int i = 0; i < GameManager.Inst.MachineSlots_go.Count; i++)
|
||
//{
|
||
// var n = GameManager.Inst.MachineSlots_go[i].GetComponent<DeviceQuery>().deviceList.id;
|
||
// deviceId_ops.Add(n);
|
||
//}
|
||
//for (int i = 0; i < GameManager.Inst.TmsCards_go.Count; i++)
|
||
//{
|
||
// var n = GameManager.Inst.TmsCards_go[i].GetComponent<DeviceQuery>().deviceList.id;
|
||
// deviceId_ops.Add(n);
|
||
//}
|
||
var list = Array.FindAll(GameObject.FindObjectsOfType<PortQuery>(), itme =>
|
||
{
|
||
var n = itme.transform.parent.GetComponent<DeviceQuery>().deviceList;
|
||
if (!string.IsNullOrEmpty(itme.portList.id) && n != null)
|
||
return true;
|
||
return false;
|
||
}).ToList();
|
||
for (int i = 0; i < list.Count; i++)
|
||
{
|
||
deviceId_ops.Add(list[i].transform.parent.GetComponent<DeviceQuery>().deviceList.id);
|
||
}
|
||
deviceId.AddOptions(deviceId_ops);
|
||
|
||
conDevice.options.Clear();
|
||
conDevice.AddOptions(deviceId_ops);
|
||
}
|
||
|
||
private void Start()
|
||
{
|
||
//deviceId.onValueChanged.AddListener(deviceId_fuc);//所属设备
|
||
conDevice.onValueChanged.AddListener(conDevice_fuc);//对联设备
|
||
save_bt.onClick.AddListener(() =>
|
||
{
|
||
StartCoroutine(SaveJsonCoroutine());
|
||
});
|
||
}
|
||
|
||
private IEnumerator SaveJsonCoroutine()
|
||
{
|
||
yield return StartCoroutine(saveJson());
|
||
|
||
if (URlreturn.message == "操作成功")
|
||
{
|
||
yield return StartCoroutine(GameManager.Inst.LoadAddress((ct) =>
|
||
{
|
||
if (ct != null)
|
||
{
|
||
GameManager.Inst.Jk_URL = new webURL(ct);
|
||
StartCoroutine(GameManager.Inst.Initialize());
|
||
}
|
||
else
|
||
{
|
||
Debug.Log("获取穿透错误!");
|
||
}
|
||
}));
|
||
|
||
Array.ForEach(GameManager.Inst.pop_ups.ToArray(), (itme) =>
|
||
{
|
||
itme.gameObject.SetActive(false);
|
||
});
|
||
}
|
||
else
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
private void conDevice_fuc(int arg0)
|
||
{
|
||
List<string> conPort_ops = new List<string>();
|
||
//对联设备下所有端口
|
||
//conDevice.options[arg0].text//对联设备id
|
||
//Array.FindAll(FindObjectsOfType<PortQuery>(), itme =>
|
||
//{
|
||
// if (itme.portList.deviceId== conDevice.options[arg0].text)
|
||
// return true;
|
||
// return false;
|
||
//}).ToList();
|
||
for (int i = 0; i < GameManager.Inst.TmsPorts_go.Count; i++)
|
||
{
|
||
var n = GameManager.Inst.TmsPorts_go[i].GetComponent<PortQuery>().portList;
|
||
if (n.deviceId == conDevice.options[arg0].text)
|
||
conPort_ops.Add(n.port);
|
||
}
|
||
}
|
||
|
||
private void deviceId_fuc(int arg0)
|
||
{
|
||
//deviceId.options[arg0].text//所属设备ID
|
||
|
||
}
|
||
|
||
private void Update()
|
||
{
|
||
|
||
mybody.port = port.text;
|
||
|
||
mybody.portCode = portCode.text;
|
||
|
||
mybody.portName = portName.text;
|
||
|
||
mybody.portType = portType.text;
|
||
|
||
mybody.deviceId = deviceId.options[deviceId.value].text;
|
||
|
||
//mybody.portModel = portModel;
|
||
|
||
mybody.status = status.value;
|
||
|
||
mybody.conDevice = conDevice.options[conDevice.value].text;
|
||
|
||
mybody.conPort = conPort.options[conPort.value].text;
|
||
|
||
mybody.remark = remark.text;
|
||
}
|
||
|
||
public IEnumerator saveJson()
|
||
{
|
||
var newData = JsonConvert.SerializeObject(mybody);
|
||
|
||
//var jsonResult = await CombineJSON.UpdateJson_POST(GameManager.Inst.Jk_URL.dk_xz, GameManager.Inst.token, newData);
|
||
|
||
//URlreturn = JsonConvert.DeserializeObject<Root>(jsonResult);
|
||
|
||
yield return StartCoroutine(
|
||
CombineJSON.UpdateJson_POST(GameManager.Inst.Jk_URL.dk_xz, GameManager.Inst.arguments.token, newData, (jsonResult) =>
|
||
{
|
||
try
|
||
{
|
||
URlreturn = JsonConvert.DeserializeObject<Root>(jsonResult);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
}
|
||
})
|
||
);
|
||
}
|
||
|
||
#region JSON
|
||
[System.Serializable]
|
||
public class Body
|
||
{
|
||
/// <summary>
|
||
/// 端口
|
||
/// </summary>
|
||
public string port;
|
||
/// <summary>
|
||
/// 编号
|
||
/// </summary>
|
||
public string portCode;
|
||
/// <summary>
|
||
/// 名称
|
||
/// </summary>
|
||
public string portName;
|
||
/// <summary>
|
||
/// 类型
|
||
/// </summary>
|
||
public string portType;
|
||
/// <summary>
|
||
/// 端口位置
|
||
/// </summary>
|
||
public string portPosition;
|
||
/// <summary>
|
||
/// 所属设备
|
||
/// </summary>
|
||
public string deviceId;
|
||
/// <summary>
|
||
/// 型号
|
||
/// </summary>
|
||
public string portModel;
|
||
/// <summary>
|
||
/// 状态:1-正常;0-禁用
|
||
/// </summary>
|
||
public int status;
|
||
/// <summary>
|
||
/// 对联设备
|
||
/// </summary>
|
||
public string conDevice;
|
||
/// <summary>
|
||
/// 对联端口
|
||
/// </summary>
|
||
public string conPort;
|
||
/// <summary>
|
||
/// 备注
|
||
/// </summary>
|
||
public string remark;
|
||
}
|
||
[System.Serializable]
|
||
public class Root
|
||
{
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public string code;
|
||
/// <summary>
|
||
/// 反馈结果
|
||
/// </summary>
|
||
public string message;
|
||
/// <summary>
|
||
/// 返回内容(ID)
|
||
/// </summary>
|
||
public string data;
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public string serverTime;
|
||
}
|
||
#endregion
|
||
}
|