123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- 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<HttpSocket>
- {
- /// <summary>
- /// 同步当前位置
- /// </summary>
- /// <param name="pos">位置</param>
- /// <param name="PointionTs">时间</param>
- /// <param name="CallBack"></param>
- public void SendIpToPointPos(Vector3 pos, Action<string> 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);
- }
- /// <summary>
- /// 向服务器发送眼镜的剩余电量以及电池状态
- /// 在start函数中使用InvokeRepeating60秒调用一次
- /// </summary>
- /// <param name="CallBack"></param>
- 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);
- }
- /// <summary>
- /// 进入触发区域后向后台发送信息
- /// </summary>
- /// <param name="pointId"></param>
- public void SendIpToPointTrigger(string pointId, string name, Action<string> 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<int, string> 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
- {
- /// <summary>
- ///
- /// </summary>
- public double x { get; set; }
- /// <summary>
- ///
- /// </summary>
- public double y { get; set; }
- /// <summary>
- ///
- /// </summary>
- 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; }
- }
|