Fusion Social Hub
- Before You Start
- Connection Manager System
- Coding For Both Topologies
Fusion Social Hub is a technical sample that demonstrates how to make use of multiple topologies in one project, as well as how to implement logic so that it will execute differently for each specific topology while accounting for their inherent differences. The sample also demonstrates how to manage multiple
NetworkRunners to transition between sessions.
This sample uses the following combination:
- Shared Mode for the social hub in which many players can initially gather and interact with NPCs; and,
- Host Mode session for dungeons which can be entered (i.e. created & started) from the social hub by a smaller number of players. In the dungeon, players can destroy boxes.
- Host only: LMB to attack.
- Both topologies: E to interact.
Before You Start
To run the sample, first create a Fusion AppId in the PhotonEngine Dashboard and paste it into the
App Id Fusion field in Real Time Settings (reachable from the Fusion menu).
|1.1.3||Nov 01, 2022||Fusion Social Hub 1.1.3 Build 68|
Connection Manager System
The Connection Manager is responsible for handling connection requests, as there will be more than one
NetworkRunner to handle both topologies, it takes care of referencing the correct Runner and taking all necessary precautions not to get in conflict with the other.
The main purpose of this class is to perform networked operations that the
ConnectionManager cannot because it is a
Monobehaviour. On this sample it is only used to pass a RPC.
Is a simple c# class that holds references to a
ConnectionData currently used on that Runner, an
App, the callbacks class of the Runner and some helpers checks.
A scriptable object that will be used to hold all the data needed to make a connection request to
ConnectionManager. These are the main properties:
ConnectionID: ID referent to the connection, each unique session should have a different ID. It will be used as a session property to join or create a new session if none is available to join.
ConnectionTarget: It is used by
ConnectionManagerto know if the desired connection will be on a
It contains a reference to a
ConnectionData and will be used as an area trigger for toggling the interface to connect to the session defined at the
ConnectionManager.cs will mainly perform the connection to the desired session, storing the reference to the correct
ConnectionContainer based on the connection target received, besides some other utility logics.
Coding For Both Topologies
It is important to notice that some logics are going to work differently on different topologies, the best practice for provide support for both is to always check for
Object.HasStateAuthority instead of
Runner.IsServer, because it cover the state authority in Shared Mode and also the host or the server in Host/Server mode.
Also, using the Fusion Input, even if it is not really useful in Shared Mode, will make it work on Host/Server, like the
For logics that are only supposed to run on a specific topology,
Runner.Topology will return the topology that the
NetworkRunner related to the
NetworkObject is using.