Skip to content

Instantly share code, notes, and snippets.

@tarukosu
Created December 17, 2017 13:06
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/5694ffe33a0234d3f110eaa7786645bb to your computer and use it in GitHub Desktop.
Save tarukosu/5694ffe33a0234d3f110eaa7786645bb to your computer and use it in GitHub Desktop.
UnetTangoController.cs
using System;
using System.Collections;
using UnetLLAPISample;
using UnityEngine;
using UnityEngine.Networking;
public class UnetTangoController : MonoBehaviour
{
public LLAPINetworkManager NetworkManager;
public bool SelectButton = false;
public void Start()
{
StartCoroutine(SendTransformCoroutine());
}
private IEnumerator SendTransformCoroutine()
{
while (true)
{
SendTransform();
yield return new WaitForSeconds(0.06f);
}
}
public void Update()
{
bool currentSelectButton = Input.GetKey("space");
if (Input.touchCount > 0)
{
currentSelectButton = true;
}
if (Input.GetMouseButton(0))
{
currentSelectButton = true;
}
if (SelectButton != currentSelectButton)
{
SelectButton = currentSelectButton;
SendInput(SelectButton);
}
}
void SendTransform()
{
int headerSize = 1;
byte[] buff = new byte[headerSize + sizeof(float) * 7];
buff[0] = 0;
var pos = Camera.main.transform.position;
Buffer.BlockCopy(BitConverter.GetBytes(pos.x), 0, buff, headerSize + 0 * sizeof(float), sizeof(float));
Buffer.BlockCopy(BitConverter.GetBytes(pos.y), 0, buff, headerSize + 1 * sizeof(float), sizeof(float));
Buffer.BlockCopy(BitConverter.GetBytes(pos.z), 0, buff, headerSize + 2 * sizeof(float), sizeof(float));
var rot = Camera.main.transform.rotation;
Buffer.BlockCopy(BitConverter.GetBytes(rot.x), 0, buff, headerSize + 3 * sizeof(float), sizeof(float));
Buffer.BlockCopy(BitConverter.GetBytes(rot.y), 0, buff, headerSize + 4 * sizeof(float), sizeof(float));
Buffer.BlockCopy(BitConverter.GetBytes(rot.z), 0, buff, headerSize + 5 * sizeof(float), sizeof(float));
Buffer.BlockCopy(BitConverter.GetBytes(rot.w), 0, buff, headerSize + 6 * sizeof(float), sizeof(float));
NetworkManager.SendPacketData(buff, QosType.Unreliable);
}
void SendInput(bool select)
{
byte[] buff = { 1, BitConverter.GetBytes(select)[0] };
NetworkManager.SendPacketData(buff, QosType.Reliable);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment