using LitJson; using QFramework; using System.Collections; using System.Collections.Generic; using UnityEngine; public class HttpSocket : MonoSingleton { public bool isOpen = false; public int projectid; 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; SendIpToPointPos(Vector3.zero); // SendIpToPointTrigger(projectid, "博物馆"); } } /// /// 同步当前位置 /// /// /// public void SendIpToPointPos(Vector3 pos) { if (!isOpen) return; SendNetConnectPointCloud sendNet = new SendNetConnectPointCloud(); sendNet.sn = DeviceSN.Instance.SendSerialBy16(); sendNet.projectId = projectid; sendNet.position.x = pos.x; sendNet.position.y = pos.y; sendNet.position.z = pos.z; sendNet.positionType = "PointCloud"; string jsonData = JsonMapper.ToJson(sendNet); // HttpTool.Instance.PostTest("/sn/position", jsonData, CallBack); } /// /// 进入触发区域后向后台发送信息 /// /// /// public void SendIpToPointTrigger(string Name) { if (!isOpen) return; SendNetConnectPointTrigger sendNet = new SendNetConnectPointTrigger(); sendNet.projectId = projectid; sendNet.sn = DeviceSN.Instance.SendSerialBy16(); sendNet.name = Name; string jsonData = JsonMapper.ToJson(sendNet); // Debug.Log(jsonData); //SocketSendPointCloud(jsonData); // JFSocket.GetInstance().SendMessage(jsonData); HttpTool.Instance.PostTest("/sn/viewpoint", jsonData, CallBack); } /// /// 向服务器发送眼镜的剩余电量以及电池状态 /// 在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; sendNet.projectId = projectid; string jsonData = JsonMapper.ToJson(sendNet); // SocketSendPointCloud(jsonData); // JFSocket.GetInstance().SendMessage(jsonData); HttpTool.Instance.PostTest("/sn/electricity", jsonData, CallBack); if(electricity<20) { SendNetConnectAlert sendAlert = new SendNetConnectAlert(); sendAlert.sn = DeviceSN.Instance.SendSerialBy16(); sendAlert.projectId = projectid; sendAlert.message = "电量过低"; string json = JsonMapper.ToJson(sendAlert); HttpTool.Instance.PostTest("/alert/create", json, CallBack); } } /// /// Post 回调 /// /// public void CallBack(string str) { // Debug.Log(str); } ///// ///// 获取初始Json成功后的回调 ///// ///// //public void AnalysisJson(string str) //{ // GameManage.Instance.AnalysisJson(str); //} }