“Why is there nothing appearing in the Unity GUI? 5DTgloves-Unity integration attempt, is it possible to integrate these two?”
I’ve been trying to integrate my 5DT gloves with Unity using the GloveSampleApp C# (Monodevelop) code provided in the 5dt website. Here are the code, splitted into 2 parts:
FIRST PART:
using UnityEngine;
using System.Collections;
using System;
using System.Timers;
using Gtk;
using FDTGloveUltraCSharpWrapper;
public class NewBehaviourScript : MonoBehaviour
{
//do not modify
public partial class MainWindow
{
private global::Gtk.Fixed fixed1;
private global::Gtk.Button btnConnect;
private global::Gtk.Entry txtGlovePort;
private global::Gtk.Label label2;
private global::Gtk.Label label3;
private global::Gtk.Label label4;
private global::Gtk.Label label5;
private global::Gtk.Entry txtPacketRate;
private global::Gtk.Entry txtFirmWareVersion;
private global::Gtk.Entry txtLR;
private global::Gtk.Entry txtType;
private global::Gtk.Label label1;
private global::Gtk.CheckButton chkUseCallback;
private global::Gtk.TextView lstSensors;
private global::Gtk.Label label6;
private global::Gtk.Entry txtGesture;
private global::Gtk.Button btnQuit;
protected virtual void Build ()
{
global::Stetic.Gui.Initialize (this);
// Widget MainWindow
this.Name = "MainWindow";
this.Title = global::Mono.Unix.Catalog.GetString ("5DT C# Glove Sample App");
this.WindowPosition = ((global::Gtk.WindowPosition)(4));
// Container child MainWindow.Gtk.Container+ContainerChild
this.fixed1 = new global::Gtk.Fixed ();
this.fixed1.Name = "fixed1";
this.fixed1.HasWindow = false;
// Container child fixed1.Gtk.Fixed+FixedChild
this.btnConnect = new global::Gtk.Button ();
this.btnConnect.CanFocus = true;
this.btnConnect.Name = "btnConnect";
this.btnConnect.UseUnderline = true;
this.btnConnect.Label = global::Mono.Unix.Catalog.GetString ("Connect");
this.fixed1.Add (this.btnConnect);
global::Gtk.Fixed.FixedChild w1 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.btnConnect]));
w1.X = 180;
w1.Y = 20;
// Container child fixed1.Gtk.Fixed+FixedChild
this.txtGlovePort = new global::Gtk.Entry ();
this.txtGlovePort.CanFocus = true;
this.txtGlovePort.Name = "txtGlovePort";
this.txtGlovePort.Text = global::Mono.Unix.Catalog.GetString ("USB0");
this.txtGlovePort.IsEditable = true;
this.txtGlovePort.InvisibleChar = '*';
this.fixed1.Add (this.txtGlovePort);
global::Gtk.Fixed.FixedChild w2 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.txtGlovePort]));
w2.X = 15;
w2.Y = 21;
// Container child fixed1.Gtk.Fixed+FixedChild
this.label2 = new global::Gtk.Label ();
this.label2.Name = "label2";
this.label2.LabelProp = global::Mono.Unix.Catalog.GetString ("Type:");
this.fixed1.Add (this.label2);
global::Gtk.Fixed.FixedChild w3 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.label2]));
w3.X = 21;
w3.Y = 80;
// Container child fixed1.Gtk.Fixed+FixedChild
this.label3 = new global::Gtk.Label ();
this.label3.Name = "label3";
this.label3.LabelProp = global::Mono.Unix.Catalog.GetString ("Left/Right:");
this.fixed1.Add (this.label3);
global::Gtk.Fixed.FixedChild w4 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.label3]));
w4.X = 20;
w4.Y = 107;
// Container child fixed1.Gtk.Fixed+FixedChild
this.label4 = new global::Gtk.Label ();
this.label4.Name = "label4";
this.label4.LabelProp = global::Mono.Unix.Catalog.GetString ("Packet Rate:");
this.fixed1.Add (this.label4);
global::Gtk.Fixed.FixedChild w5 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.label4]));
w5.X = 22;
w5.Y = 130;
// Container child fixed1.Gtk.Fixed+FixedChild
this.label5 = new global::Gtk.Label ();
this.label5.Name = "label5";
this.label5.LabelProp = global::Mono.Unix.Catalog.GetString ("FW Version:");
this.fixed1.Add (this.label5);
global::Gtk.Fixed.FixedChild w6 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.label5]));
w6.X = 20;
w6.Y = 155;
// Container child fixed1.Gtk.Fixed+FixedChild
this.txtPacketRate = new global::Gtk.Entry ();
this.txtPacketRate.CanFocus = true;
this.txtPacketRate.Name = "txtPacketRate";
this.txtPacketRate.IsEditable = true;
this.txtPacketRate.InvisibleChar = '*';
this.fixed1.Add (this.txtPacketRate);
global::Gtk.Fixed.FixedChild w7 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.txtPacketRate]));
w7.X = 98;
w7.Y = 134;
// Container child fixed1.Gtk.Fixed+FixedChild
this.txtFirmWareVersion = new global::Gtk.Entry ();
this.txtFirmWareVersion.CanFocus = true;
this.txtFirmWareVersion.Name = "txtFirmWareVersion";
this.txtFirmWareVersion.IsEditable = true;
this.txtFirmWareVersion.InvisibleChar = '*';
this.fixed1.Add (this.txtFirmWareVersion);
global::Gtk.Fixed.FixedChild w8 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.txtFirmWareVersion]));
w8.X = 98;
w8.Y = 159;
// Container child fixed1.Gtk.Fixed+FixedChild
this.txtLR = new global::Gtk.Entry ();
this.txtLR.CanFocus = true;
this.txtLR.Name = "txtLR";
this.txtLR.IsEditable = true;
this.txtLR.InvisibleChar = '*';
this.fixed1.Add (this.txtLR);
global::Gtk.Fixed.FixedChild w9 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.txtLR]));
w9.X = 98;
w9.Y = 108;
// Container child fixed1.Gtk.Fixed+FixedChild
this.txtType = new global::Gtk.Entry ();
this.txtType.CanFocus = true;
this.txtType.Name = "txtType";
this.txtType.IsEditable = true;
this.txtType.InvisibleChar = '*';
this.fixed1.Add (this.txtType);
global::Gtk.Fixed.FixedChild w10 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.txtType]));
w10.X = 98;
w10.Y = 84;
// Container child fixed1.Gtk.Fixed+FixedChild
this.label1 = new global::Gtk.Label ();
this.label1.Name = "label1";
this.label1.LabelProp = global::Mono.Unix.Catalog.GetString ("Sensors:");
this.fixed1.Add (this.label1);
global::Gtk.Fixed.FixedChild w11 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.label1]));
w11.X = 290;
w11.Y = 64;
// Container child fixed1.Gtk.Fixed+FixedChild
this.chkUseCallback = new global::Gtk.CheckButton ();
this.chkUseCallback.CanFocus = true;
this.chkUseCallback.Name = "chkUseCallback";
this.chkUseCallback.Label = global::Mono.Unix.Catalog.GetString ("Use Callback instead of 250ms timer");
this.chkUseCallback.DrawIndicator = true;
this.chkUseCallback.UseUnderline = true;
this.fixed1.Add (this.chkUseCallback);
global::Gtk.Fixed.FixedChild w12 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.chkUseCallback]));
w12.X = 286;
w12.Y = 19;
// Container child fixed1.Gtk.Fixed+FixedChild
this.lstSensors = new global::Gtk.TextView ();
this.lstSensors.WidthRequest = 228;
this.lstSensors.HeightRequest = 247;
this.lstSensors.CanFocus = true;
this.lstSensors.Name = "lstSensors";
this.lstSensors.Editable = false;
this.fixed1.Add (this.lstSensors);
global::Gtk.Fixed.FixedChild w13 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.lstSensors]));
w13.X = 290;
w13.Y = 80;
// Container child fixed1.Gtk.Fixed+FixedChild
this.label6 = new global::Gtk.Label ();
this.label6.Name = "label6";
this.label6.LabelProp = global::Mono.Unix.Catalog.GetString ("Current Gesture:");
this.fixed1.Add (this.label6);
global::Gtk.Fixed.FixedChild w14 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.label6]));
w14.X = 290;
w14.Y = 333;
// Container child fixed1.Gtk.Fixed+FixedChild
this.txtGesture = new global::Gtk.Entry ();
this.txtGesture.CanFocus = true;
this.txtGesture.Name = "txtGesture";
this.txtGesture.IsEditable = false;
this.txtGesture.WidthChars = 3;
this.txtGesture.InvisibleChar = '*';
this.fixed1.Add (this.txtGesture);
global::Gtk.Fixed.FixedChild w15 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.txtGesture]));
w15.X = 376;
w15.Y = 331;
// Container child fixed1.Gtk.Fixed+FixedChild
this.btnQuit = new global::Gtk.Button ();
this.btnQuit.CanFocus = true;
this.btnQuit.Name = "btnQuit";
this.btnQuit.UseUnderline = true;
this.btnQuit.Label = global::Mono.Unix.Catalog.GetString ("Quit");
this.fixed1.Add (this.btnQuit);
global::Gtk.Fixed.FixedChild w16 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.btnQuit]));
w16.X = 486;
w16.Y = 337;
this.Add (this.fixed1);
if ((this.Child != null)) {
this.Child.ShowAll ();
}
this.DefaultWidth = 549;
this.DefaultHeight = 380;
this.Show ();
this.DeleteEvent += new global::Gtk.DeleteEventHandler (this.OnDeleteEvent);
this.btnConnect.Clicked += new global::System.EventHandler (this.OnBtnConnectClicked);
this.chkUseCallback.Toggled += new global::System.EventHandler (this.OnChkUseCallbackToggled);
this.btnQuit.Clicked += new global::System.EventHandler (this.OnBtnQuitClicked);
}
}
//until here
public static void Main (string[] args)
{
{
Gtk.Application.Init ();
MainWindow win = new MainWindow ();
win.Show ();
Gtk.Application.Run ();
}
}
public partial class MainWindow : Gtk.Window
{
CfdGlove fdGlove;
private static System.Timers.Timer tmrUpdate;
public MainWindow () : base(Gtk.WindowType.Toplevel)
{
Build ();
// creat the glove
fdGlove = new CfdGlove();
// setup the timer
tmrUpdate = new System.Timers.Timer();
tmrUpdate.Elapsed += new ElapsedEventHandler(OurTimerCallback);
tmrUpdate.Disposed += new EventHandler(OurTimerDisposed);
tmrUpdate.Interval = 250;
tmrUpdate.Enabled = true;
}
delegate void UpdateListDelegate(); // used by Update function to create delegate to update sensor list
public void OurTimerCallback(object source, ElapsedEventArgs e)
{
Update(this,new EventArgs());
}
public void OurTimerDisposed(object source, EventArgs e)
{
}
private void Update(object sender, EventArgs e)
{
Gtk.Application.Invoke (delegate {UpdateDataOnForm();});
}
private void UpdateDataOnForm()
{
if (fdGlove == null)
return;
lstSensors.Buffer.Text = "";
ushort[] arr = new ushort[20];
float[] farr = new float[20];
// Get all the scaled values
fdGlove.GetSensorScaledAll(ref farr);
fdGlove.GetSensorRawAll(ref arr);
//for (int i = 0; i < fdGlove.GetNumSensors(); ++i)
if (fdGlove.IsOpen())
{
for (int i = 0; i < 18; ++i)
{
lstSensors.Buffer.Text += "Sensor " + i + " - Scaled: " + String.Format("{0:0.00}", farr_) + " ( Raw: " + arr *+ ")
";_
_}*_
}
txtGesture.Text = fdGlove.GetGesture().ToString();
txtPacketRate.Text = fdGlove.GetPacketRate().ToString();
}
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Gtk.Application.Quit ();
a.RetVal = true;
}
protected virtual void OnBtnConnectClicked (object sender, System.EventArgs e)
{
chkUseCallback.Active = false;
fdGlove.Open(txtGlovePort.Text);
//tmrUpdate.Enabled = true;
switch(fdGlove.GetGloveType())
{
case (int)EGloveTypes.FD_GLOVE14UW: txtType.Text = “Data Glove 14 Ultra Wireless”; break;
case (int)EGloveTypes.FD_GLOVE14U_USB: txtType.Text = “Data Glove 14 Ultra USB”; break;
case (int)EGloveTypes.FD_GLOVE14U: txtType.Text = “Data Glove 14 Ultra”; break;
case (int)EGloveTypes.FD_GLOVE16: txtType.Text = “Data Glove 16-sensor”; break;
case (int)EGloveTypes.FD_GLOVE16W: txtType.Text = “Data Glove 16-sensor Wireless”; break;
case (int)EGloveTypes.FD_GLOVE5U: txtType.Text = “Data Glove 5 Ultra”; break;
case (int)EGloveTypes.FD_GLOVE5U_USB: txtType.Text = “Data Glove 5 Ultra USB”; break;
case (int)EGloveTypes.FD_GLOVE5UW: txtType.Text = “Data Glove 5 Ultra Wireless”; break;
case (int)EGloveTypes.FD_GLOVE7: txtType.Text = “Data Glove 7-sensor”; break;
case (int)EGloveTypes.FD_GLOVE7W: txtType.Text = “Data Glove 7-sensor Wireless”; break;
case (int)EGloveTypes.FD_GLOVENONE: txtType.Text = “No Glove”; break;
default: txtType.Text = “Unknown”; break;
}
switch(fdGlove.GetGloveHand())
{
case (int)EGloveHand.FD_HAND_RIGHT: txtLR.Text = “Right”; break;
case (int)EGloveHand.FD_HAND_LEFT: txtLR.Text = “Left”; break;
}
txtFirmWareVersion.Text = fdGlove.fdGetFWVersionMajor() + “.” + fdGlove.fdGetFWVersionMinor();
}
protected virtual void OnBtnQuitClicked (object sender, System.EventArgs e)
{
if (fdGlove != null)
fdGlove.Close();
Gtk.Application.Quit();
}
protected virtual void OnChkUseCallbackToggled (object sender, System.EventArgs e)
{
if (chkUseCallback.Active)
{
fdGlove.SetCallBack(new EventHandler(Update));
tmrUpdate.Enabled = false;
}
else
{
fdGlove.RemoveCallBack(new EventHandler(Update));
tmrUpdate.Enabled = true;
}
}
}
}
SECOND PART:
using Gtk;
// This file has been generated by the GUI designer. Do not modify.
namespace Stetic
{
internal class Gui
{
private static bool initialized;
static internal void Initialize (Gtk.Widget iconRenderer)
{
if ((Stetic.Gui.initialized == false)) {
Stetic.Gui.initialized = true;
}
}
}
internal class ActionGroups
{
public static Gtk.ActionGroup GetActionGroup (System.Type type)
{
return Stetic.ActionGroups.GetActionGroup (type.FullName);
}
public static Gtk.ActionGroup GetActionGroup (string name)
{
return null;
}
}
}
And I’m putting the FIRST PART script (NewBehaviourScript) into an empty gameobject but why there’s no response in the GUI Layout?
oh and I’m also using a Windows Form provided by Gtk.gui and from the “shredder2500” UnityAnswer, I know it’s possible to do it, so why is there nothing in my Unity GUI now?
I am very grateful for anyone who could help me, and thanks for the answer… I’ve been doing this for about 6 months and I’ve got no clue at all now…
also, is it even possible to integrate Unity and 5DT technologies? if it’s possible, please give some clue / specific place to learn how to integrate these two technology
I would also very thankful if “Dewald” from 5DT could give some specific help, not just redirecting to download the C# file (again) in 5dt’s website, because it’s useless…