Unityで複数LEAPの可能性を探していたので、ひとつの再現方法をメモ
内容はjsonデータをUnityで見えるようにしている状態にしただけなので、活用できるかは未検証。。
返り値floatが本当に正しい値?など。。
LEAPの設定は下記
UnityでWEBSocketは下記を参考にしました
###動作状態
###スクリプト
WsLeap.cs
using UnityEngine;
using WebSocketSharp;
public class WsLeap : MonoBehaviour
{
public WebSocket ws;
public string url = "ws://192.168.1.1:6437/";//環境ごとに変更
public float currentFrameRate;
public Devices[] devices;
public Hands[] hands;
public int id;
public Pointables[] pointables;
public int timestamp;
public void RecvText(string text)
{
string json = text.ToString();
LeapJson jsonData = new LeapJson();
JsonUtility.FromJsonOverwrite(json, jsonData);
currentFrameRate = jsonData.currentFrameRate;
devices = jsonData.devices;
hands = jsonData.hands;
id = jsonData.id;
pointables = jsonData.pointables;
timestamp = jsonData.timestamp;
}
public void RecvClose()
{
}
void Start()
{
ws = new WebSocket(url);
ws.Connect();
ws.OnMessage += (sender, e) => RecvText(e.Data);
ws.OnClose += (sender, e) => RecvClose();
}
}
LeapJson.cs
using System;
using UnityEngine;
[Serializable]
public class LeapJson
{
public float currentFrameRate;
public Devices[] devices;
public Hands[] hands;
public int id;
public Pointables[] pointables;
public int timestamp;
}
[Serializable]
public class Devices
{
}
[Serializable]
public class Hands
{
public float[] direction;
public int id;
public float[] palmNormal;
public float[] palmPosition;
public float[] palmVelocity;
public float timeVisible;
}
[Serializable]
public class Pointables
{
public string direction;
public int handId;
public int id;
public int length;
public int timeVisible;
public float[] tipPosition;
public float width;
}
###参考サイト