» Unity/C# examples

In this section of the documentation we provide a series of brief tutorials on the C# examples for the Unity platform distributed as a separate package on the SmartFoxServer 2X download page.

Most tutorials analyze a single example, describing its objectives, giving an insight into the SmartFoxServer features it wants to highlight and providing the direct link to download the source code, which includes all the assets required to compile and test it (both client and — if existing — server side). If necessary, code excerpts are provided in the tutorial itself, in order to better explain the approach that was followed to implement a specific feature. At the bottom of the tutorial, additional resources are linked if available.

The tutorials follow an increasingly complexity curve from basic server connections over chat messaging to full realtime games with authoritative server extension.

Specifically the examples will show:

  1. basic connection
  2. chat messaging and room management
  3. game rooms and extension messaging
  4. simple client side 3d object movement
  5. server authoritative first person shooter

» Usability on different Unity deployment targets

All examples *should* run seamless and be interoperable on

The user interfaces have primarily been developed for standalone and webplayer usage, so might not fit 100% into mobile screensize without a little extra work.

All GUI code has been done with Unity GUI and a special SmartFoxServer skin.

» Usability on non-Unity platforms

The client API is fully usable on other .NET enabled platforms like ASP.NET or console applications and is thus not limited to Unity usage. The examples are not directly compilable on these platforms, but all relevant C# code is placed in Assets/Scripts and 99% usable via copy/paste in a different context.

NOTE
When using the API on these targets you will have to either run the API in non-thread safe mode or process the callback events in a timer. Check this link for more information on non-thread safe mode.

» Requirements

Unless otherwise noted inside the tutorials:

NOTE
All the examples make use of the latest version of the SmartFoxServer 2X C# API available as part of the server download itself. As the API evolve in time (bug fixes, new features), we strongly recommend that, after downloading an example, you overwrite the included API DLL file (SmartFox2.dll in the source code's Assets/Plugins folder) with the one provided in the latest SmartFoxServer package or patch available on our website.