using LitJson; using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using SC.XR.Unity.Module_Device; using Newtonsoft.Json; public class HttpSocket : MonoSingleton { /// /// 同步当前位置 /// /// 位置 /// 时间 /// public void SendIpToPointPos(Vector3 pos, Action CallBack) { SendNetConnectPointCloud sendNet = new SendNetConnectPointCloud(); sendNet.sn = SendSN.GetSN(); //sendNet.sn = API_GSXR_Slam.SlamManager.plugin.SN; sendNet.projectId = DataManager.Instance.ProjectID; sendNet.position.x = pos.x; sendNet.position.y = pos.y; sendNet.position.z = pos.z; sendNet.positionType = "PointCloud"; string jsonData = JsonConvert.SerializeObject(sendNet); //Debug.Log("/sn/position"+jsonData); HttpTool.Instance.Post("/sn/position", jsonData, CallBack); } /// /// 向服务器发送眼镜的剩余电量以及电池状态 /// 在start函数中使用InvokeRepeating60秒调用一次 /// /// public void SendIpToElectric() { StartCoroutine(WaitSendElectric()); } IEnumerator WaitSendElectric() { while (true) { CalElectric(); yield return new WaitForSeconds(60f); } } private void CalElectric() { 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 = SendSN.GetSN(); //sendNet.sn = API_GSXR_Slam.SlamManager.plugin.SN; sendNet.projectId = DataManager.Instance.ProjectID; electricity = 100; sendNet.electricity = electricity; sendNet.status = state; string jsonData = JsonMapper.ToJson(sendNet); Debug.Log(jsonData); HttpTool.Instance.Post("/sn/electricity", jsonData, CallBack); } /// /// 进入触发区域后向后台发送信息 /// /// public void SendIpToPointTrigger(string pointId, string name, Action CallBack) { SendNetConnectPointTrigger sendNet = new SendNetConnectPointTrigger(); sendNet.sn =SendSN.GetSN(); //sendNet.sn = API_GSXR_Slam.SlamManager.plugin.SN; sendNet.projectId = DataManager.Instance.ProjectID; sendNet.name = name; string jsonData = JsonMapper.ToJson(sendNet); Debug.Log(jsonData); HttpTool.Instance.Post("/sn/viewpoint", jsonData, CallBack); } public void SendSnInfo(SceneValue scene, int index, Action CallBack) { SendSnInfo sendNet = new SendSnInfo(); sendNet.sn =SendSN.GetSN(); //sendNet.sn = API_GSXR_Slam.SlamManager.plugin.SN; sendNet.projectId = scene.id; string jsonData = JsonMapper.ToJson(sendNet); Debug.Log(jsonData); HttpTool.Instance.PostSnInfo("/client/snInfo", jsonData, index, CallBack); } private void CallBack(string message) { Debug.Log(message); } } public class SendNetConnectPointCloud { public string sn { get; set; } public int projectId { get; set; } public string positionType { get; set; } public Position position { get; set; } public SendNetConnectPointCloud() { position = new Position(); } } public class Position { /// /// /// public double x { get; set; } /// /// /// public double y { get; set; } /// /// /// public double z { get; set; } } public class SendNetConnectElectricity { public string sn { get; set; } public int projectId { get; set; } public int electricity { get; set; } public string status { get; set; } } public class SendNetConnectPointTrigger { public int projectId { get; set; } public string sn { get; set; } public string name { get; set; } } public class SendSnInfo { public string sn { get; set; } public int projectId { get; set; } }