UTILITY SCRIPTS
UTILITY SCRIPTS
In addition to having a rich API to help with the core tasks of game networking, uLink includes a number of utility script components that a game developer can use right out-of-the-box. These scripts have been created to solve specific common tasks that are needed in many games. The scripts come as C# source files and are located in the
/Plugins/uLink/Utility Scripts folder in the project view after you have imported the uLink package. Just drag and drop the scripts onto a game object or prefab to start using them. They can also be found in the Unity Editor top menu, under
Component/uLink Utilities. You are also free to modify them or create your own scripts based on these source files.
Some of the available scripts are listed below, for a complete list, download uLink and check the folder /Plugins/uLink/Utility Scripts.
Chat GUI
This script is a simple example of a chat system for an authoritative uLink server.
When the server is authoritative, the clients can't force the server to broadcast
messages. Therfore the client sends a private RPC to the server. The server receives
this RPC and can check for bad language (and do other checks) before broadcasting
this message to all connected clients.
Client GUI
This displays a GUI dialog that allows the client player to choose a server to connect to, either by a public host address, LAN discovery or through the Master Server.
Instantiate For Others
Requires a non-authoritative server. The script reduces the amount of code you otherwise have to write manually. By attaching this scripts to a game object in the Hierarchy view, the game object will automatically be instantiated for me (the starting player) all others (opponents) over the network during startup. This scripts works for both clients and servers. You can specify different prefabs for proxy and owner. The owner will be the starting player.
Instantiate Pool
This wonderful script makes it possible to pool game objects (instantiated prefabs)
and uLink will use this pool of objects as soon as the gameplay code makes a call to
Network.Instantiate().
The purpose of the script is to avoid the costly object instantiation in the middle of the game.
Instead the object instantiations are done during startup, on the server and on all clients.
The wonderful part is that you do not have to change your code at all to use the pool
mechanism. This makes it very easy to check if your game is faster and more smooth
with a pool.
Don't use the pool for all game objects, use it for objects with a short lifespan and use it
for objects that are instantiated and destroyed often.
Object Label
This lets you easily show labels at your networked game objects. By attaching this script to a prefab you can send a string as initial data when instantiating the prefab, and the text will be displayed for everyone.
Observed List
Implementation for the script component uLinkNetworkObservedList.
This script component is used to set up a list of components to serialize for
a game object or prefab with a uLinkNetworkView.
One example of a game object with two components to serialize is a tank with a turret. The tank is
the game object, the turret is one component, the body of the tank is another component. When the state
of the tank is serialized the body includes position + velocity + rotation. The turret has another
rotation. The send the comple tank state over the network using uLink state synchronization it is
manadatory to add a uLinkNetworkView (script component) to the game object. Then add a
uLinkNetworkObservedList (script component) to the game object.
Add the tank body and the tank turret to the list in the uLinkNetworkObservedList component.
Make sure the observed property of the uLinkNetworkView component is the the uLinkNetworkObservedList component.
Another example is a game object with an animation script component. If the game designer wants to send animation
state and position state, the uLinkNetworkObservedList can be used. THis is how to do that:
Add a uLinkNetworkObservedList to the game object. Add the postions (your script) and the animation (your script)
to the list. Your two scripts must implement the callback uLink_OnSerializeNetworkView. Make sure the observed
property of the uLinkNetworkView component is the the uLinkNetworkObservedList component.
Override Settings
This script lets you override the default uLink settings.
P2P Connector
Attach this script component to a game object that needs to be able to make P2P connection attempts. Usually this is
a game object in the scene, for example the portal in the Snowbox game. When this script component is attached to a
game object a UDP socket will be opened at runtime and this socket will be used by uLink to send P2P connection
attempts to one other peer. The IP and port for the remote peer can be set using the public properties of this script.
If your game object needs to connect to several peers, just add more uLinkP2PConnector components and configure them.
You will need one uLinkP2PConnector for every remote peer you want to connect to.
It is not possible so send state synch over a P2P connection. Use the connection to send RPCs instead.
On the remote peer use the utility script NetworkP2P
Network P2P
Attach this script component to a game object that needs to be able to receive P2P connection attempts. Usually this is a game object in the scene, for example the portal in the server scene in the Snowbox example game.
The most important property of this script is the listener port. This is the port this peer (usually a server) will use to open a UDP socket and listen for incoming connection attempts. If you have several game servers with this script component running on the same host, they will all need one unique port number.
Simple Server
A utility script that can be used to start a very simple Unity server
listening for uLink connection attempts from clients.
The server is listening for UDP traffic on one port number. Default value is 7100.
The port number can be changed to whatever port number you like.
Another imporant property is
targetFrameRate. This value dictates
how many times per second the server reads incoming network traffic
and sends outgoing traffic. It also dictates the actual frame rate for
the server (sometimes called tick rate). Read more about tick rate in
the
Server Operations manual chapter.
The property called
registerHost dictates if this game server should
try to register itself in a uLink Master Server. Read the Master Server manual chapter for more info.
Smooth Character
A utility script that can be used for players' avatars in a 3d game where the server is authoritatve or non-authoritatve.
Since uLink 1.3 it can be used for NPCs too. (server owned objects)
When using this utility script, it should be added as a component to the game object that a player controls.
The game object must have a character controller component, not a ridgid body.
The observed property of the uLinkNetworkView for the game object should be set to this component.
Authoritative Server: The basic idea for this script is that the owner (controlling this object) sends unreliable "Move" RPCs to
the authoritative server with a rate dictated by
uLink.Network.sendRate. The authoritative server receives this RPC and moves the
character. If you want to add security checks in the server because it should be authoritative, you can do that. Make a
copy of the script and do your modifications.
Non-authoritative Server: The basic idea for this script is that the owner (controlling this object) sends statesync to the
non-authoritative server with a rate dictated by
uLink.Network.sendRate. The authoritative server receives this statesync and moves the
character. If you want to add security checks in the server because it should be authoritative, you can do that. Make a
copy of the script and do your modifications.
Both authoritative server and non-authoritative server sends statesync to clients with proxies.
This script component also makes sure the movement is smooth in the server and in the clients showing the proxy objects.
Statistics GUI
A graphical tool for the game client. Perfect for testers.
Add this script component to one of the game objects. After that, testers will be able to
press the
enabledByKey key and bring up a window showing some important numbers from uLink:
ping time, bandwidth in both directions, number of networkViews (objects), etc.
Strict Character
A utility script that can be use for players' objects in a 3d game without gravity.
The object is floating in space just like a spaceship or a submarine does.
When using this utility script, it should be added as a component to the game object that a player controls.
The server should be authoritative when using this script (uLink.Network.isAuthoritativeServer = true).
The basic idea is that the server simulates all physics and checks if any player tries to cheat by
sending movment orders as an RPC (The RPC name is ServerMove) with false coordinates to move faster than allowed in the game.
The server checks the incoming ServerMove RPC from the client and sends two kinds of RPCs back to the client.
If the client did move too fast (due to a cheating attempt or a bug or whatever) the server sends an RPC named
AdjustOwnerPos. If the position is good, the server sends an RPC named GoodOwnerPos. They are both sent as unreliable
RPCs from the server to the client to minimize server resources.
This script component also makes sure interpolation and extrapolation is used for the state synchronozation sent from
the server to clients. The state synchronization, arriving at the client, is stored in an internal array and the
public properties interpolationBackTime and extrapolationLimit can be used to tune the correct behavior for every game.
Please read the code for more details.
Strict Platformer
A utility script that can be use for players' avatars in a 3d platform game where
the avatar is moving on a surface/platform and affected by gravity.
When using this utility script, it should be added as a component to the game object that a player controls.
The server should be authoritative when using this script (uLink.Network.isAuthoritativeServer = true).
The basic idea is that the server simulates all physics including gravity and checks if any player tries to cheat by
sending movment orders as an RPC (The RPC name is ServerMove) with false coordinates to move faster than allowed in the game.
The server checks the incoming ServerMove RPC from the client and sends two kinds of RPCs back to the client.
If the client did move too fast (due to a cheating attempt or a bug or whatever) the server sends an RPC named
AdjustOwnerPos. If the position is good, the server sends an RPC named GoodOwnerPos. They are both sent as unreliable
RPCs from the server to the client to minimize server resources.
This script component also makes sure interpolation and extrapolation is used for the state synchronozation sent from
the server to clients. The state synchronization, arriving at the client, is stored in an internal array and the
public properties interpolationBackTime and extrapolationLimit can be used to tune the correct behavior for every game.
Please read the code for more details.