Provides easy way to use Zig Sim on Unity.
https://zig-project.com
Using this assets, Unity receives Json data from Zig Sim over the UDP protocol. This asset uses Json Utility. So you can deserialize quickly.
The data received is limited to the free version of ZigSim.
Because this asset rely on C# 6.0, required Unity version is after Unity2017.1. If you use this asset with Unity2018.1 or earlier, you have to confirm that you use .NET 4.x scripting runtime. Please reference Edit > Project Settings > Player > Configuretion > Scripting Runtime Version.
Install package(ZigSimToolsforUnity.unitypackage) is available in ZigSimToolsforUnity/releases page.
To start using this assets, you might try to execute ObjectRotationSample Scene. Before run this scene, you have to confirm some settings.
-
Download ZigSim App for your mobile device from App store or Google Play.
-
Launch the app. Press the Settings button and set as follows:
Settings
- DATA DESTINATION: OTHER APP
- PROTOCOL: UDP
- IP ADDRESS: Your PC's IP address.
- PORT NUMBER: 50000
- MESSAGE FORMAT: JSON
- MESSAGE RATE: 30
- DEVICE UUID: Don't edit
- COMPASS ANGLE: Don't edit
- BEACON: Don't edit
-
Press the Sensor button and check only QUATERNION.
-
Press Start button on Zig Sim and Run Unity scene. The Object starts rotating same as your mobile device.
The ZigSimDataManager class has a callback function that takes each sensor data as an argument.
public Action<Device, string> BasicDataCallBack;
public Action<Accel> AccelCallBack;
public Action<Gravity> GravityCallBack;
public Action<Gyro> GyroCallBack;
public Action<Quaternion> QuaternionCallBack;
public Action<Compass> CompassCallBack;
public Action<Pressure> PressureCallBack;
public Action<Gps> GpsCallBack;
public Action<MicLevel> MicLevelCallBack;
public Action<Touch[]> TouchCallBack;The sensor data received using this callback function can be used by other classes. Since the ZigSimDataManager class is a singleton class, it can be accessed from any class in the same scene.
ex) ObjectRotator.cs
using UnityEngine;
using ZigSimTools;
using Quaternion = UnityEngine.Quaternion;
public class ObjectRotator : MonoBehaviour
{
private Quaternion targetRotation;
void Start ()
{
ZigSimDataManager.Instance.StartReceiving ();
ZigSimDataManager.Instance.QuaternionCallBack += (ZigSimTools.Quaternion q) =>
{
// Debug.Log (q.ToString ());
var newQut = new Quaternion ((float) - q.x, (float) - q.z, (float) - q.y, (float) q.w);
var newRot = newQut * Quaternion.Euler (90f, 0, 0);
targetRotation = newRot;
};
}
void Update ()
{
transform.localRotation = targetRotation;
if (Input.GetKeyDown (KeyCode.Escape))
{
ZigSimDataManager.Instance.StopReceiving ();
}
}
}Basic Data
ZigSimDataManager.Instance.BasicDataCallBack += (Device d, string timestamp) =>
{
Debug.Log (d.ToString ());
Debug.Log (timestamp);
};Touch Sensor
ZigSimDataManager.Instance.TouchCallBack += (ZigSimTools.Touch[] touches) =>
{
var count = 0;
foreach (var t in touches)
{
Debug.Log ($"{count} : {t.ToString()}");
count++;
}
};This software is released under the MIT License, see LICENSE.txt.