Added more functionality to Unity3D demo
This commit is contained in:
Binary file not shown.
@@ -3,6 +3,7 @@ using System.Collections;
|
||||
using System.Threading;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.IO;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class Demo : MonoBehaviour
|
||||
{
|
||||
@@ -52,8 +53,64 @@ public class Demo : MonoBehaviour
|
||||
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()
|
||||
{
|
||||
// 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
|
||||
zt = new ZeroTierNetworkInterface ("/Users/Joseph/utest2");
|
||||
|
||||
|
||||
Binary file not shown.
@@ -63,6 +63,20 @@ std::string netDir;
|
||||
extern "C" {
|
||||
#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)
|
||||
{
|
||||
std::string confFile = netDir + "/" + nwid + ".conf";
|
||||
@@ -80,11 +94,13 @@ extern "C" {
|
||||
zt1Service->leave(nwid);
|
||||
}
|
||||
|
||||
void zt_join_network(std::string nwid) {
|
||||
join_network(nwid.c_str());
|
||||
void zt_join_network(char * nwid) {
|
||||
//Debug(nwid.c_str());
|
||||
join_network(nwid);
|
||||
}
|
||||
void zt_leave_network(std::string nwid) {
|
||||
leave_network(nwid.c_str());
|
||||
void zt_leave_network(char * nwid) {
|
||||
//Debug(nwid.c_str());
|
||||
leave_network(nwid);
|
||||
}
|
||||
|
||||
bool zt_is_running() {
|
||||
@@ -94,21 +110,6 @@ extern "C" {
|
||||
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__)
|
||||
/*
|
||||
* Starts a service thread and performs basic setup tasks
|
||||
|
||||
Reference in New Issue
Block a user