• Examples (Unity)
• Examples (iOS)
• Examples (Java/Android)
• Examples (C++)
Server API Documentation


» 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 dedicated package on the SmartFoxServer 2X download page. The examples have been developed with Unity 2021.3 LTS, but the concepts and the code to interact with the SFS2X API are valid for any version of Unity (unless otherwise noted).

Each tutorial examines a single example, describing its objectives, offering an insight into the SmartFoxServer features it wants to highlight and providing the direct link to download the source code. This includes all the assets required to compile and test the example (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 have an increasing complexity, from basic server connection to full realtime games with authoritative server Extension.

Specifically, the examples will showcase:

  1. basic connection with optional protocol encryption
  2. room management
  3. buddy list management
  4. game rooms and match-making
  5. authoritative server in a turn-based game
  6. MMO-related features
  7. clients synchronization in realtime games

» Usability on different Unity deployment targets

All examples run seamlessly and are interoperable on all Unity build targets. For sake of simplicity, the examples have been developed for desktop usage, so they may have issues running on devices (like lack of controls in realtime games).

Please note that due to the different requirements of the Unity build targets, the SmartFoxServer C# API contained in the examples is made of two separate DLLs: a DLL specific for WebGL builds and a DLL for all other Unity target platforms (including the Unity Editor itself).
Most examples use both DLLs, located in separate subfolders under the Plugins folder. Each DLL is assigned to its target by clicking on it and selecting one or more platforms in the Inspector panel as follows:

Check this link for more information on the API setup.

» Non-Unity platforms

The client API is fully usable on other .NET enabled platforms like ASP.NET or console applications and is not limited to Unity usage. The examples are not directly compilable on these platforms, but all relevant C# code is placed in the same Scripts folder and it's mostly usable via copy/paste in a different context. Also, a dedicated, non-Unity DLL must be used.

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:

All the examples make use of the latest version of the SmartFoxServer 2X C# API available at the time of their development. As the API evolves over time (bug fixes, new features), we strongly recommend that, after downloading an example, you overwrite the included API DLL files with those provided in the latest SmartFoxServer C# API package available on our website.