using Mono.Cecil.Cil; using Newtonsoft.Json; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// 机器人保存指令 /// [AddComponentMenu("SaveInstructRobot/机器人保存指令")] public class SaveInstructRobot : MonoBehaviour { public static SaveInstructRobot Inst; public Root myroot = new Root(); public int instructID = -1; private void Awake() { Inst = this; } // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } /// /// 发送并机器人保存指令 /// /// /// public void sendInstruct(string content, Action callback) { instructID = -1; Body mybody = new Body(); mybody.content = content; var newData = JsonConvert.SerializeObject(mybody); StartCoroutine(CombineJSON.UpdateJson_POST(GameManager.Inst.Jk_URL.jqr_bczl, GameManager.Inst.arguments.token, newData, (jsonResult) => { if (!string.IsNullOrEmpty(jsonResult)) { try { myroot = null; myroot = JsonConvert.DeserializeObject(jsonResult); if (myroot.message == "操作成功") { instructID = myroot.data; callback.Invoke(true); } else { SecondConfirmPanel.DeleteConform(null, myroot.message); callback.Invoke(false); } } catch (Exception e) { Debug.LogError(e.StackTrace); SecondConfirmPanel.DeleteConform(null, "机器人保存指令序列化错误"); callback.Invoke(false); } } else { callback.Invoke(false); } })); } [System.Serializable] public class Body { /// /// /// public string content; } [System.Serializable] public class Root { /// /// /// public string code; /// /// 操作成功 /// public string message; /// /// /// public int data; /// /// /// public string serverTime; } }