123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- 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>
- {
-
-
-
-
-
-
- public void SendIpToPointPos(Vector3 pos, Action<string> CallBack)
- {
- SendNetConnectPointCloud sendNet = new SendNetConnectPointCloud();
- sendNet.sn = SendSN.GetSN();
-
- 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);
-
- HttpTool.Instance.Post("/sn/position", jsonData, CallBack);
- }
-
-
-
-
-
- public void SendIpToElectric()
- {
- StartCoroutine(WaitSendElectric());
- }
- IEnumerator WaitSendElectric()
- {
- while (true)
- {
- CalElectric();
- yield return new WaitForSeconds(6f);
- }
- }
- 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.projectId = DataManager.Instance.ProjectID;
- electricity = (int)SystemInfo.batteryLevel*100;
- sendNet.electricity = electricity;
- sendNet.status = state;
- string jsonData = JsonMapper.ToJson(sendNet);
- Debug.Log("电量===》"+jsonData);
- HttpTool.Instance.Post(HttpAction.sn_electricity, jsonData, CallBack);
- }
-
-
-
-
- public void SendIpToPointTrigger(string pointId, int id, Action<string> CallBack)
- {
- SendNetConnectPointTrigger sendNet = new SendNetConnectPointTrigger();
- sendNet.sn =SendSN.GetSN();
-
- sendNet.projectId = DataManager.Instance.ProjectID;
- sendNet.id = id;
- string jsonData = JsonMapper.ToJson(sendNet);
- Debug.Log(jsonData);
- HttpTool.Instance.Post("/sn/viewpoint", jsonData, 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 float x { get; set; }
-
-
-
- public float y { get; set; }
-
-
-
- public float 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 int id { get; set; }
- }
- public class SendSnInfo
- {
- public string sn { get; set; }
- public int projectId { get; set; }
- }
|