金铉Unity插件库 Unity版本2018.4.32f 目前包含本地化存储功能(根据类名存储读写),TCP客户端监听类型功能
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.2 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LitJson;
using System;
using JXSoft;
namespace DYData {
public struct BluetoothGatewayData:IResponse
{
/// <summary>
///
/// </summary>
public int v { get; set; }
/// <summary>
///
/// </summary>
public int mid { get; set; }
/// <summary>
///
/// </summary>
public int time { get; set; }
/// <summary>
/// 用时
/// </summary>
public string ip { get; set; }
/// <summary>
/// 地址
/// </summary>
public string mac { get; set; }
/// <summary>
/// 设备信息
/// </summary>
public List<List<object>> devices { get; set; }
private string exceptionMsg;
public string findDataByMac(string mac) {
foreach (List<object> deviceMsg in devices) {
if (mac.Equals(deviceMsg[1])) {
return deviceMsg[3].ToString();
}
}
return "no data";
}
public string toProtocolData()
{
string watchMac = "535708030130";
string counter_1Mac = "90380C3BEF1A";
string counter_2Mac = "90380C3C0416";
string result = "watch:" + findDataByMac(watchMac) + "\ncounter_1:" + findDataByMac(counter_1Mac) + "\ncounter_2:" + findDataByMac(counter_2Mac);
return result;
}
public bool trySetData(string protocolData)
{
try
{
BluetoothGatewayData blg = JsonMapper.ToObject<BluetoothGatewayData>(protocolData);
this.v = blg.v;
this.time = blg.time;
this.mid = blg.mid;
this.ip = blg.ip;
this.mac = blg.mac;
this.devices = blg.devices;
return true;
}
catch (Exception e) {
Debug.Log(e.ToString());
return false;
}
}
public string getException()
{
return exceptionMsg;
}
}
}