Inputs

Universal Controller Server

Universal Controller Server

Universal Controller is a SDK that allows developers to use their customised controller on mobile devices or tailor made hardware controllers with Unity. This package doesn’t limited the mobile side application to be an Unity app. It’s aimed to support native Android, iOS apps, and single board computers like Arduino boards & Raspberry Pi for the controller side.

This repo is the server side Unity package which hosts a socket server within the Unity app by using native .NET socket APIs.

For the client side library, please refer to here for Java based client and here for Android client library.


Getting start

To set up the server, follow the following instructions:

  1. Create an empty GameObject in the scene you want to start up the server and attach component UCNetworkManager to it.
  2. Set the port number and maximum connections in UCNetworkManager.
  3. Create a new C# script as a child class of UCPlayer, override methods from UCPlayer (see SamplePlayer.cs for reference) and implement your own logics for each command received.
  4. Attach the script you just created to your player object, then make that as a prefab.
  5. Set the player prefab in UCNetworkManager.
  6. You are now good to go.

There is a sample scene included in the Sample folder with everything set up properly that you can use it as an example.

The server will shutdown by itself on application quit. Alternatively you can call UCNetworkManager.ServerShutDown() to shutdown the server anytime you want, the server will then shutdown after all data is sent and received.

To test the server, you can use this Java cmd tool. It is a fairly simple cmd line program to test out your server. Just type in your server IP and type in the commands. One thing to mention is this tool will throw the IOException and terminate itself if there is any error on the connection between the tool and the socket server.


Commands

Below are the formats of each command that will be handled by the server once received from client:

Register player

REGISTER:{player_id}

Deregister player

DEREGISTER:{player_id}
* The client who registered that player will be disconnected.

Key pressed

{player_id}:KEY_DOWN:{custom_key}

or

{player_id}:KEY_DOWN:{custom_key}:{extra_content}

Joystick data

{player_id}:JOYSTICK:{x}:{y}

Gyro data

{player_id}:GYRO:{x}:{y}:{z}

Type of parameters

  • player_id : int
  • custom_key : string
  • extra_content : string
  • x : float
  • y : float
  • z : float
  • value of float x, y, z must be between -1.0f & 1.0f

Version history

v2.0.1

  • Closes the socket when disconnected.

v2.0.0

  • Reimplemented socket server with better structure and resources management.
  • Added function GetIPv4Address() in NetworkUtilities for fetching the local IPv4 address.
  • Implemented callbacks for data received from the clients.
  • Introduces UC-Commands (Register, Deregister, KeyDown, Joystick, Gyro).
  • Added component UCNetworkManager & UCPlayer.
  • Includes sample scene.

v1.0.0-alpha pre-release

  • Set up socket server in Unity.
  • Includes test script for starting the server.

Copyright © 2018 Wing Chau & AlphaOwl.co.uk
All rights reserved.

This software may be modified and distributed under the terms of the MIT license. See the LICENSE file for details.