115 lines
2.7 KiB
C#
115 lines
2.7 KiB
C#
using Mono.Cecil.Cil;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
|
|
/// <summary>
|
|
/// 机器人保存指令
|
|
/// </summary>
|
|
[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()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// 发送并机器人保存指令
|
|
/// </summary>
|
|
/// <param name="content"></param>
|
|
/// <param name="callback"></param>
|
|
public void sendInstruct(string content, Action<bool> 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<Root>(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
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public string content;
|
|
}
|
|
|
|
|
|
|
|
[System.Serializable]
|
|
public class Root
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public string code;
|
|
/// <summary>
|
|
/// 操作成功
|
|
/// </summary>
|
|
public string message;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public int data;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public string serverTime;
|
|
}
|
|
|
|
}
|