This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
Basics
Rendering
Professional (SIM)
UnigineEditor
Interface Overview
Assets Workflow
Version Control
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
Sandworm
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Built-in Node Types
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
Materials and Shaders
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
API
Animations-Related Classes
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
VR-Related Classes
Content Creation
Content Optimization
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials

C++/C# Photon Integration Sample

Photon is a networking engine and multiplayer platform that can handle all requests on their own servers. Thus, to create a multiplayer networking solution, you implement the application (gameplay) logic and features in the UNIGINE project, and the networking part is done using Photon. This small sample demonstrates how to integrate the Photon engine into your UNIGINE project to make it a multiplayer app.

Two Photon products are integrated into the Photon Integration third-party sample:

  • Photon Realtime arranges interaction of multiple players via network. It can be used for creation of multiplayer shooters, racing games, and other real-time applications.
  • Photon Chat allows users to exchange written messages both publicly and privately.

The sample contains the following elements:

  • Simplified authorization window to enter the user nickname, which can be used as a basis for a more elaborate authorization window with a password and so on
  • Lobby window to create a room and check the list of created rooms available for connection
  • World containing the actual objects that can be manipulated and the chat window to exchange messages

Data Transfer via Network#

Photon Sample contains Utils that demonstrate how to transfer UNIGINE data types via Photon.

It is impossible to directly transfer UNIGINE data via network using Photon — they should be serialized before being sent and then deserialized when received by another party. Photon is able to serialize and deserialize the data sets listed here (click on Common-cpp - data types and utilities). The same information on data types is available as a PDF file for your convenience.

Other specific data types such as transformation matrices should be registered in a specific way illustrated in our sample for proper serialization/deserialization process.

Check this sample and create your own applications integrating more network solutions developed by Photon.

How to Run the Sample#

To use Photon products, register on the Photon website (www.photonengine.com) and do the following:

  1. Download the required SDKs.

    Go to SDKs (the tab in the top right corner).

    You'll need SDKs for two Photon products to run this sample:

    • REALTIME — Windows/Linux for C++ or .NET for C#
    • CHAT — Windows/Linux for C++ or .NET for C#
  2. Add binaries.

    In the Photon sample folder, find the folder named PhotonSDK. Copy all binaries to this folder according to the structure provided in the Readme.txt file also available in this folder.

    Example for Windows C++ project, Chat SDK binaries

    Example for Windows C++ project, Chat SDK binaries

    Example for Windows C# project, Chat SDK binaries

    Example for Windows C# project, Chat SDK binaries
  3. Create App IDs.

    Go to Dashboards (the tab in the top right corner).

    In the Dashboards section, click CREATE A NEW APP.

    You need to create two applications for Photon sample: one using Realtime Photon SDK, and the other one — Chat Photon SDK.

    Creating a Realtime Photon App

    Creating a Chat Photon App

    Now you have two apps and may use their IDs in the sample. The same ID is used for every instance (i.e. other participants don't need to create their own apps).

  4. Add App IDs to the sample project.

    In the project folder find data/application_params.json and paste the IDs to the corresponding lines.

    Shell commands
    {
        "realtime_application_id": "______________",
        "realtime_application_version": "1.0",
        "chat_application_id": "_________________",
        "chat_application_version": "1.0"
    }

This is it. Now run the app and ask your friend to do the same.

If you do solo testing, run one or two more instances on your PC and switch between the windows to get a glimpse.

How to Use the Sample#

As you run the sample, you'll see a basic authorization form. Type in your nickname and click Join Lobby.

The Lobby window will be displayed next. If you are the first and there are no rooms in the list, click Create Room and the room will be created.

All users using the same Photon IDs in the data/application_params.json will see the room named after the nickname, if they join after this room has been created.

Double-click the room name to join this room.

As soon as the world opens, you can move your material ball around using WASD buttons, rotate it using QE, and shoot other players clicking the left mouse button.

You can type in messages to send them to all users, or send messages starting with @username to exchange private messages with that user. (Of course, you should know the username for that, the application doesn't have any specific interface to let you know it.)

As the life progress bar is empty, the Leave button is displayed on the screen. Click it to return to Lobby.

Last update: 2024-08-16
Build: ()