GPF Docs
Matchmaker Walkthrough
Matchmaker Walkthrough
This article documents the code that runs the Matchmaker project demonstrating how to create a matchmaker and Rock-Paper-Scissors match using GPF.
Run the Tests locally
- Change the project to
Simulatedmode inUnity Editor -> GPF -> Settings -> Backend Type - Open Test Runner
Unity Editor -> Window -> General -> Test Runner - Run
MatchmakerTest, see it turn Green. - Right Click on
Testand open the source code.
Notice that:
- The
PlayerActions Taskis used by 2 players, "Bob" and "Gina". - Each
PlayerActionsuses a unique syncer. PlayerActionsare essentially a script of what each player will do, read through the code and comments to gain an understanding.- The client only interacts with
MatchPlayerSO. It does so by sending it these messages:- Match
- Accept
- Move
- The last line of
PlayerActionsassures the test only passes if the Match resolved with the correct state for both players.
await syncer.WaitFor(player, nameof(MatchPlayerSO.state), FieldIs.Equal(outcome));- Open
MatchPlayerSO.cs
MatchPlayerSO
MatchPlayerSO is responsible for the player's state in the cloud.
Notice that:
It's
[Syncable], thereby allowing the client to access it's state.The messages that the client sends up have handlers with the
[FromClient]attribute, while the other's do not.It interacts with other
SOs, specifically:- MatchmakerSO
- MatchGameSO
Diagram
Here are the interactions from the unit test. Go through them and try to match them up with the code.
Run the Game
Now let's actually play the game.
Open the
Matchmakerscene in theAssets/folder.Do a
build and runto run a desktop instance.Click the play button to run the editor instance.
Open the
Data ExplorerGFP -> Data Explorerso you can watch the state of the game change as you play through. You will have to select theData Explorerto make sure it's up to date.Play
UI
At this point we should understand how state is determined and how the game looks, but now lets look at how the SO's are hooked up to UI.
Open the Heirarchy for the Matchmaker scene in the Assets/ folder
and notice the Controller GameObject has a script attached to it called MatchController.cs (/Assets/Scripts). Open it.
MatchController.cs does the following:
- Creates a
Syncer, which provides- The ability to sync UI to SOs
- The ability to send messages to SOs.
- Adds an alias to the
DataStore(match_player) so theMatchPlayerSOstate can be easily referenced by the UI (See Hooking Up UI) - Supports button calllback code for:
- StartMatchMaking
- StopMatchMaking
- AcceptMatch
- RejectMatch
- Move
- Leave
Let's look at ViewBindings on the the Hierarchy
If you turn on the inspector panel, you will notice that the Canvas.GameStates GameObjects has the following ViewBinding.
| UI | ViewBinding | bound to variable |
|---|---|---|
| Canvas.GameStates | SelectChildVB | match_player.state |
This video demonstrates how SelectChildVB is used to display states and state transitions:
You will also notice components have events that reference MatchController functions for example:
| UI | Function (defined in CoinController.cs) |
|---|---|
| Canvas.GameStates.MATCHMAKING.CancelButton | StopMatchMaking |
| Canvas.GameStates.TABLE_OFFERED.AcceptButton | AcceptMatch |
| Canvas.GameStates.TABLE_OFFERED.RejectButton | RejectMatch |
| Canvas.GameStates.GAME_STARTED.Rock | Move |
| Canvas.GameStates.GAME_WON.LeaveButton | Leave |
| Canvas.GameStates.GAME_LOST.LeaveButton | Leave |
© 2023 Launch It Labs INC