151 lines
3.9 KiB
C#
151 lines
3.9 KiB
C#
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
/// <summary>
|
|
/// 设备-删除
|
|
/// </summary>
|
|
public class DeleteDevice : MonoBehaviour
|
|
{
|
|
public Body mybody = new Body();
|
|
public Root URlreturn = new Root();
|
|
|
|
|
|
|
|
public IEnumerator SaveJsonCoroutine(Action<bool> callback = null)
|
|
{
|
|
yield return StartCoroutine(saveJson((w) =>
|
|
{
|
|
if (w != null && URlreturn != null && URlreturn.message == "操作成功")
|
|
{
|
|
callback?.Invoke(true);
|
|
StartCoroutine(Succeed((x) =>
|
|
{
|
|
if (x)
|
|
{
|
|
refurbish();
|
|
}
|
|
}));
|
|
}
|
|
else
|
|
{
|
|
SecondConfirmPanel.DeleteConform(null, "删除设备失败");
|
|
refurbish();
|
|
}
|
|
}));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 刷新
|
|
/// </summary>
|
|
public void refurbish()
|
|
{
|
|
Array.ForEach(GameManager.Inst.pop_ups.ToArray(), (itme) =>
|
|
{
|
|
itme.gameObject.SetActive(false);
|
|
});
|
|
//GameManager.Inst.objectToShow_add.gameObject.SetActive(true);
|
|
var SN1 = GameManager.Inst.objectToShow_add.GetComponent<SearchName1>();
|
|
SN1.hide_menu();
|
|
}
|
|
|
|
public IEnumerator Succeed(Action<bool> callback)
|
|
{
|
|
Array.ForEach(GameObject.FindObjectsOfType<UPosItem>(), (item) =>
|
|
{
|
|
item.isOccupied = false;
|
|
});
|
|
|
|
GameManager.Inst.isLoading = false;
|
|
|
|
//TransparentGlowManage.Inst.addScript();
|
|
|
|
//yield return StartCoroutine(GameManager.Inst.init_Device());
|
|
|
|
//yield return StartCoroutine(GameManager.Inst.init_Port());
|
|
|
|
|
|
//yield return StartCoroutine(LineQuery.Inst.getJsonCoroutine());
|
|
|
|
//GameManager.Inst.LoadScene();
|
|
//callback.Invoke(true);
|
|
yield return null;
|
|
StartCoroutine(GameManager.Inst.Initialize((x) =>
|
|
{
|
|
if (!string.IsNullOrEmpty(x))
|
|
callback.Invoke(true);
|
|
}));
|
|
}
|
|
|
|
|
|
public IEnumerator saveJson(Action<Root> callback = null)
|
|
{
|
|
string newData = null;
|
|
try
|
|
{
|
|
newData = JsonConvert.SerializeObject(mybody);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
callback.Invoke(null);
|
|
yield break;
|
|
}
|
|
|
|
|
|
//var jsonResult = await CombineJSON.UpdateJson_POST(GameManager.Inst.Jk_URL.sb_sc, GameManager.Inst.token, newData);
|
|
|
|
//URlreturn = JsonConvert.DeserializeObject<Root>(jsonResult);
|
|
|
|
yield return StartCoroutine(
|
|
CombineJSON.UpdateJson_POST(GameManager.Inst.Jk_URL.sb_sc, GameManager.Inst.arguments.token, newData, (jsonResult) =>
|
|
{
|
|
try
|
|
{
|
|
URlreturn = JsonConvert.DeserializeObject<Root>(jsonResult);
|
|
callback?.Invoke(URlreturn);
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
Debug.Log("删除设备错误:" + e.Message);
|
|
callback.Invoke(null);
|
|
}
|
|
})
|
|
);
|
|
}
|
|
|
|
#region JSON
|
|
[System.Serializable]
|
|
public class Body
|
|
{
|
|
/// <summary>
|
|
/// id
|
|
/// </summary>
|
|
public List<string> ids;
|
|
}
|
|
[System.Serializable]
|
|
public class Root
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public string code;
|
|
/// <summary>
|
|
/// 反馈结果
|
|
/// </summary>
|
|
public string message;
|
|
/// <summary>
|
|
/// 返回内容
|
|
/// </summary>
|
|
public string data;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public string serverTime;
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|