Added more functionality to Unity3D demo

This commit is contained in:
Joseph Henry
2016-06-16 14:06:20 -07:00
parent 246c85720a
commit 614cdf03ce
4 changed files with 77 additions and 19 deletions

View File

@@ -3,6 +3,7 @@ using System.Collections;
using System.Threading; using System.Threading;
using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization.Formatters.Binary;
using System.IO; using System.IO;
using UnityEngine.UI;
public class Demo : MonoBehaviour public class Demo : MonoBehaviour
{ {
@@ -52,8 +53,64 @@ public class Demo : MonoBehaviour
networkTestThread.Start(); networkTestThread.Start();
} }
// Demo button methods
public void Join()
{
GameObject go = GameObject.Find ("inputNetworkID");
InputField input = go.GetComponents<InputField> () [0];
Debug.Log ("Joining: " + input.text);
zt.JoinNetwork (input.text);
}
public void Leave()
{
GameObject go = GameObject.Find ("inputNetworkID");
InputField input = go.GetComponents<InputField> () [0];
Debug.Log ("Leaving: " + input.text);
zt.LeaveNetwork (input.text);
}
public void Connect()
{
GameObject go = GameObject.Find ("inputServerAddress");
//Text text = go.GetComponents<Text> ()[0];
InputField input = go.GetComponents<InputField> () [0];
Debug.Log ("Connecting to: " + input.text);
//zt.Connect(0, input.text
}
public void Disconnect()
{
GameObject go = GameObject.Find ("inputServerAddress");
InputField text = go.GetComponents<InputField> () [0];
Debug.Log ("Disconnecting from: " + text.text);
}
public void SendMessage()
{
GameObject go = GameObject.Find ("inputMessage");
InputField text = go.GetComponents<InputField> () [0];
Debug.Log ("Sending Message: " + text.text);
}
void Start() void Start()
{ {
// Set defaults
InputField input;
GameObject go;
go = GameObject.Find ("inputNetworkID");
input = go.GetComponents<InputField> () [0];
input.text = "565799d8f6e1c11a";
go = GameObject.Find ("inputServerAddress");
input = go.GetComponents<InputField> () [0];
input.text = "172.22.211.245";
go = GameObject.Find ("inputMessage");
input = go.GetComponents<InputField> () [0];
input.text = "Welcome to the machine";
// Create new instance of ZeroTier in separate thread // Create new instance of ZeroTier in separate thread
zt = new ZeroTierNetworkInterface ("/Users/Joseph/utest2"); zt = new ZeroTierNetworkInterface ("/Users/Joseph/utest2");

View File

@@ -63,6 +63,20 @@ std::string netDir;
extern "C" { extern "C" {
#endif #endif
#if defined(__UNITY_3D__)
// .NET Interop-friendly debug mechanism
typedef void (*FuncPtr)( const char * );
FuncPtr Debug;
void SetDebugFunction( FuncPtr fp ) { Debug = fp; }
// Starts a service at the specified path
void unity_start_service(char * path, int len) {
Debug(path);
init_service(INTERCEPT_DISABLED, path);
}
#endif
void join_network(const char * nwid) void join_network(const char * nwid)
{ {
std::string confFile = netDir + "/" + nwid + ".conf"; std::string confFile = netDir + "/" + nwid + ".conf";
@@ -80,11 +94,13 @@ extern "C" {
zt1Service->leave(nwid); zt1Service->leave(nwid);
} }
void zt_join_network(std::string nwid) { void zt_join_network(char * nwid) {
join_network(nwid.c_str()); //Debug(nwid.c_str());
join_network(nwid);
} }
void zt_leave_network(std::string nwid) { void zt_leave_network(char * nwid) {
leave_network(nwid.c_str()); //Debug(nwid.c_str());
leave_network(nwid);
} }
bool zt_is_running() { bool zt_is_running() {
@@ -94,21 +110,6 @@ extern "C" {
zt1Service->terminate(); zt1Service->terminate();
} }
#if defined(__UNITY_3D__)
// .NET Interop-friendly debug mechanism
typedef void (*FuncPtr)( const char * );
FuncPtr Debug;
void SetDebugFunction( FuncPtr fp ) { Debug = fp; }
// Starts a service at the specified path
void unity_start_service(char * path, int len) {
Debug(path);
init_service(INTERCEPT_DISABLED, path);
}
#endif
#if !defined(__ANDROID__) #if !defined(__ANDROID__)
/* /*
* Starts a service thread and performs basic setup tasks * Starts a service thread and performs basic setup tasks