-
Notifications
You must be signed in to change notification settings - Fork 1
Code examples
Merijn Hendriks edited this page Jan 13, 2018
·
10 revisions
- creates a controller, add callback to UpdatePoorSignalEvent and store PoorSignal value
using UnityEngine;
public class Example1 : MonoBehaviour
{
private ThinkGearController controller;
private int poorSignal;
private void Start()
{
controller = GameObject.Find("ThinkGear").GetComponent<ThinkGearController>();
controller.UpdatePoorSignalEvent += OnUpdatePoorSignal;
}
void OnUpdatePoorSignal(int value)
{
poorSignal = value;
}
}- initialize/stop UnityThinkGear and start/stop stream in constructor/destructor
public class Example2
{
public Example2()
{
UnityThinkGear.Init(true);
UnityThinkGear.StartStream();
}
~Example2()
{
UnityThinkGear.StopStream();
UnityThinkGear.Close();
}
}- iOS-only, scans for devices and shows information of the found device
using UnityEngine;
public class Example3 : Monobehaviour
{
private ThinkGearController controller;
private string foundDevice;
private void Awake()
{
UnityThinkGear.Init(true);
UnityThinkGear.ScanDevice();
foundDevice = "";
}
private void Start()
{
controller = GameObject.Find("ThinkGear").GetComponent<ThinkGearController>();
controller.UpdateDeviceInfoEvent += OnUpdateDeviceInfo;
}
void OnUpdateDeviceInfo(string value)
{
GetDevice(value);
}
public void GetDevice(string deviceInfo)
{
string deviceId;
string deviceName;
string mfgId;
if (foundDevice != "")
{
return;
}
mfgId = deviceInfo.Split(";"[0])[0];
deviceName = deviceInfo.Split(";"[0])[1];
deviceId = deviceInfo.Split(";"[0])[2];
Debug.Log("FMG ID" + fmgId + "Device Name" + deviceName + "Device ID" + deviceId);
foundDevice = deviceId;
}
}- iOS-only, scans for devices and connect to the found device
using UnityEngine;
public class Example4 : Monobehaviour
{
private ThinkGearController controller;
private string foundDevice;
private void Awake()
{
UnityThinkGear.Init(true);
UnityThinkGear.ScanDevice();
foundDevice = "";
}
private void Start()
{
controller = GameObject.Find("ThinkGear").GetComponent<ThinkGearController>();
controller.UpdateDeviceInfoEvent += OnUpdateDeviceInfo;
}
void OnUpdateDeviceInfo(string value)
{
GetDevice(value);
}
public void GetDevice(string deviceInfo)
{
string deviceId;
if (foundDevice != "")
{
return;
}
deviceId = deviceInfo.Split(";"[0])[2];
ConnectDevice(deviceId);
}
public void ConnectDevice(string deviceId)
{
if (foundDevice == deviceId)
{
return;
}
UnityThinkGear.ConnectDevice(deviceId);
}
}