Skip to content

Instantly share code, notes, and snippets.

@tarukosu
Created December 18, 2017 00:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tarukosu/75b8a467967c4cddd6af9e04e297faed to your computer and use it in GitHub Desktop.
Save tarukosu/75b8a467967c4cddd6af9e04e297faed to your computer and use it in GitHub Desktop.
UnetTangoController.cs
using System;
using UnetLLAPISample;
using UnityEngine;
public class UnetTangoController : MonoBehaviour, ITangoController {
public LLAPINetworkManager NetworkManager;
public bool SelectButton { get; set; }
public GunScript GunScript;
private void Awake()
{
NetworkManager.OnDataReceived += OnDataReceived;
GunScript.TangoController = this;
}
void OnDataReceived(object o, LLAPINetworkEventArgs args)
{
DataHandler(args.data);
}
private void DataHandler(byte[] data)
{
if(data.Length == 0)
{
return;
}
var header = data[0];
var headerSize = 1;
Debug.Log(header);
switch (header)
{
case 0:
//transform
if (data.Length < headerSize + 7 * sizeof(float))
{
return;
}
byte[] buff = data;
Vector3 vec;
vec.x = BitConverter.ToSingle(buff, headerSize + 0 * sizeof(float));
vec.y = BitConverter.ToSingle(buff, headerSize + 1 * sizeof(float));
vec.z = BitConverter.ToSingle(buff, headerSize + 2 * sizeof(float));
Quaternion rot = Quaternion.identity;
rot.x = BitConverter.ToSingle(buff, headerSize + 3 * sizeof(float));
rot.y = BitConverter.ToSingle(buff, headerSize + 4 * sizeof(float));
rot.z = BitConverter.ToSingle(buff, headerSize + 5 * sizeof(float));
rot.w = BitConverter.ToSingle(buff, headerSize + 6 * sizeof(float));
transform.SetPositionAndRotation(vec, rot);
break;
case 1:
//select button
if(data.Length < 2)
{
return;
}
SelectButton = BitConverter.ToBoolean(data, headerSize);
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment