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.
To set up the server, follow the following instructions:
- Create an empty GameObject in the scene you want to start up the server and attach component UCNetworkManager to it.
- Set the port number and maximum connections in UCNetworkManager.
- 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.
- Attach the script you just created to your player object, then make that as a prefab.
- Set the player prefab in UCNetworkManager.
- 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.
Below are the formats of each command that will be handled by the server once received from client:
* The client who registered that player will be disconnected.
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
- Closes the socket when disconnected.
- 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.
- Set up socket server in Unity.
- Includes test script for starting the server.
License & copyright
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.