API doumentation

Please note, you will need Unity Pro in order to use One Touch Connect. Please ensure you are also familiar with Unity’s networking functionality, details of which can be found here.

To avoid general networking bugs, it is recommended to check Run In Background in Resolution and Presentation of the Player Settings. This should only be required for Mac.

OneTouchConnectEventHandler

You will need to link events to your code. These events are fired when there the status of   services are changed. These events are:

public delegate void ServiceChangeEventHandler( ServiceInfo info );
public static event ServiceChangeEventHandler ServiceFound;
Fired when a service is found by OneTouchConnect. The service that is found is passed as a parameter allowing you to use the name, the ip address and the port number.

 

public static event ServiceChangeEventHandler ServiceLost;
Fired when a service is lost. A service can be lost for a number of reasons including the service being closed by the a broadcasting device and a broadcasting device leaving a wi-fi network or if devices are locked. Should this be called unexpectedly, check your wi-fi connection and your devices.

 

public static event ServiceChangeEventHandler ServiceResolutionFailed;
Fired when a service can’t be resolved. Should this be called, this would usually be called because of an issue with the device or how a service is created, e.g. a service type doesn’t meet expected standards.

 

public delegate void BrowsingChangeEventHandler(string message);
public static event BrowsingChangeEventHandler BrowsingStarted;
Fired when a search has successfully started. This could be used to feedback to your user that a search has started.

 

public static event BrowsingChangeEventHandler BrowsingEnded;
Fired when a search has stopped. This could be used to feedback to your user that a search has finished.

 

public delegate void ServiceRegistrationEventHandler(string serviceName);
public static event ServiceRegistrationEventHandler ServiceRegistrationSucceeded;
Fired when an attempted service registration has succeeded. The name is passed as a parameter for you to use if needed.

 

public static event ServiceRegistrationEventHandler ServiceRegistrationFailed;
Fired when an attempted service registration has failed. Should this occur please check your wi-fi and check your device is connected and close and restart the application.

 

These events use delegates. For more information please see here for more information about delegates. The supplied example should show how to link the OneTouchConnectEventHandler with your own code.

If these events are not firing please ensure that the OneTouchConnectManager is in the scene. The object must be in the scene you are using in order for all the events to fire.

There also are other public functions. You do not need to use them. These are public to allow OneTouchConnect to communicate with Unity.

OneTouchConnectInterface

This is the interface used to create services and perform searches. Please note that when using these functions, the importance of naming is imperative.

For service type parameters, please ensure that the passed string conforms to the required naming convention. The correct convention follows should follow “_nameOfServiceType.tcp.”, where nameOfServiceType can be replaced with your own name. Should the naming convention not be followed, unexpected behaviour could occur. Should you experience errors, please check your variables and ensure they follow the naming convention defined.

Please also note that services can be registered either using tcp or udp. As an example, a service could be registered as “_nameOfServiceType.udp.” Unity’s networking connects via udp, so the choice of network protocol you choose to use has no bearing on the connection to the server.

Also when registering services, the device name will be appended automatically.

Theses are the functions that you need to use:

public static void BrowseForServices(typeOfService)
This will start a search for the type of service you pass. As an example, if you called BrowseForServices(“_test._tcp.”); a search would begin searching for registered services with the type specified in the parameter. A search will then be performed to find services with the same type.Please note that when browsing for services, registered services can take a reasonable amount of time to be found. The amount of time it takes is out of our control.

 

public static void PublishAService (string nameOfService, string typeOfService, int portNumber)
This will attempt to publish a service. An example of this will be: PublishAService(“DeviceName”, “_test._tcp.”, 25000); You should then initialise your server in the same function using the same port. There’s a final function that will initialise a service and search.

 

public static void PublishAServiceAndBrowse(string serviceName, string serviceType, int port)
This calls PublishAService and BrowseForServices. It’s presumed that you want to create and search for services of the same time.

 

public static void UnregisterAService()
This unregisters a service. This should be called when you no longer need the service

 

public static void StopSearching()
This stops a search. This should be called when a search is longer required.

Integration with other plugins for Android

If other plugins are being used with your application, there may be a little bit of work required to integrate it correctly. The activity class derives off Unity’s base activity class. Other plugins may choose to do this too. Should this be the case, you’ll need to edit the Activity to derive off the other plugin’s activity.

For example, if a plugin has it’s own activity called APluginActivity, you would need to edit the OneTouchConnect Activity file to derive off APluginActivity. You would then just use the Android manifest file that comes with this package as usual. You shouldn’t need to edit either the manifest nor the activity classes.

For more information please read this documentation. Should you have any questions or have any suggestions on how we can further improve our documentation please contact us.