using LitJson; using System.Collections; using System.Collections.Generic; using UnityEngine; public class HttpSocket : MonoSingleton { public bool isOpen = true; private float times = 0; // Start is called before the first frame update void Start() { InvokeRepeating("SendIpToElectric", 0, 60f); } // Update is called once per frame void Update() { //times += Time.deltaTime; //if(times>1) //{ // times = 0; // Debug.Log("AAAAAAA"); // SendIpToInitialize(); //} } /// /// 初始化 获取初始JSON信息 /// public void SendIpToInitialize() { SendNetConnectProtocol sendNet = new SendNetConnectProtocol(); // Debug.Log(DeviceSN.Instance.SendSerialBy16()); sendNet.Tagid = DeviceSN.Instance.SendSerialBy16(); sendNet.Port = 9981; sendNet.ProjectID = 11; string jsonData = JsonMapper.ToJson(sendNet); //Debug.Log(jsonData); //SocketSend(jsonData); //JFSocket.GetInstance().SendMessage(jsonData); HttpTool.Instance.Post("regist", jsonData, AnalysisJson); //HttpTool.Instance.Get("regist", CallBack); } //reporter: '606bee3edfda85745b71348d', //sn: '3ewqeq2e2qewe', //cmd: 'insertPositionRecord', //positionTs: '1617690133', //project: '6067d03db492a38dfe6e2265', //position: '{"x":1.3,"y":3.3,"z":1.2}', //positionType: 'PointCloud', /// /// 同步当前位置 /// /// /// public void SendIpToPointPos(Vector3 pos, string PointionTs) { if (!isOpen) return; SendNetConnectPointCloud sendNet = new SendNetConnectPointCloud(); sendNet.reporter = "606bee3edfda85745b71348d"; sendNet.sn = DeviceSN.Instance.SendSerialBy16(); sendNet.cmd = "insertPositionRecord"; sendNet.positionTs = PointionTs; sendNet.project = "6067d03db492a38dfe6e2265"; sendNet.position.x = pos.x; sendNet.position.y = pos.y; sendNet.position.z = pos.z; sendNet.positionType = "PointCloud"; //sendNet.viewpointId = viewpointId; //viewpointId = "null"; string jsonData = JsonMapper.ToJson(sendNet); // Debug.Log(jsonData); // SocketSendPointCloud(jsonData); // JFSocket.GetInstance().SendMessage(jsonData); HttpTool.Instance.Post("regist", jsonData, CallBack); } //projectId:"", //sn:"", //cmdType:"increasePointTrigger", //viewpointId:"", //triggerTs: // /// /// 进入触发区域后向后台发送信息 /// /// /// public void SendIpToPointTrigger(string pointId, long ts) { if (!isOpen) return; SendNetConnectPointTrigger sendNet = new SendNetConnectPointTrigger(); sendNet.projectId = "606bee3edfda85745b71348d"; sendNet.sn = DeviceSN.Instance.SendSerialBy16(); sendNet.viewpointId = pointId; sendNet.triggerTs = ts; string jsonData = JsonMapper.ToJson(sendNet); Debug.Log(jsonData); //SocketSendPointCloud(jsonData); // JFSocket.GetInstance().SendMessage(jsonData); HttpTool.Instance.Post("regist", jsonData, CallBack); } //sn: '3ewqeq2e2qewe', //cmd: 'answer', //correct: 2, //incorrect: 1, /// /// 答题结束后向服务器发送结果信息 /// /// public void SendIpTOQuestion(SendQuestionInfor infor) { if (!isOpen) return; string jsonData = JsonMapper.ToJson(infor); //Debug.Log("========================================="+jsonData); //SocketSendPointCloud(jsonData); // JFSocket.GetInstance().SendMessage(jsonData); HttpTool.Instance.Post("regist", jsonData, CallBack); } /* 电量数据结构 * sn: '3ewqeq2e2qewe' * cmd: 'showElectricity' * electricity: 20 * status:"" */ /// /// 向服务器发送眼镜的剩余电量以及电池状态 /// 在start函数中使用InvokeRepeating60秒调用一次 /// public void SendIpToElectric() { if (!isOpen) return; int electricity = (int)((SystemInfo.batteryLevel) * 100f); BatteryStatus batterystate = SystemInfo.batteryStatus; string state = ""; switch (batterystate) { case BatteryStatus.Unknown: state = "无法确定设备的电池状态"; break; case BatteryStatus.Charging: state = "设备已插入并正在充电"; break; case BatteryStatus.Discharging: state = "设备已拔出并放电"; break; case BatteryStatus.NotCharging: state = "设备已插入,但无法充电"; break; case BatteryStatus.Full: state = "设备已插入并且电池已充满"; break; default: state = "无法确定设备的电池状态"; break; } SendNetConnectElectricity sendNet = new SendNetConnectElectricity(); sendNet.sn = DeviceSN.Instance.SendSerialBy16(); sendNet.electricity = electricity; sendNet.status = state; string jsonData = JsonMapper.ToJson(sendNet); // SocketSendPointCloud(jsonData); // JFSocket.GetInstance().SendMessage(jsonData); HttpTool.Instance.Post("regist", jsonData, CallBack); } /// /// Post 回调 /// /// public void CallBack(string str) { Debug.Log(str); } /// /// 获取初始Json成功后的回调 /// /// public void AnalysisJson(string str) { GameManage.Instance.AnalysisJson(str); } }