Devlog8. Backend System and Camera Setup


Introduction

When building our multiplayer board game, I realized that keeping track of which player owns which property needed a better solution than just storing that information on each player's device. In this blog,I’ll explain how I built a backend saving system using PlayFab that keeps tile ownership persistent and synced across all clients.

Why Use PlayFab

PlayFab is easy to set up and integrates well with Unity. It provides a built-in API to save and load data without the need for a custom backend. It also supports per-user data, cloud persistence, and handles reconnects reliably, making it a practical solution for keeping data synced across all clients.

Implementation

Save ownership using PlayFab:

Whenever a tile is bought, TilePurchaseManager calls AssignTileToPlayer(). Inside it, a Photon RPC sets the owner ID on all clients, and then PlayFabTile.SaveTileOwnership() saves the full tile list to PlayFab in a compact string format:

1:2|4:3|7:-1

Each entry means: tileNumber : ownerActorId (-1 means unowned).

Load ownership when entering a room:

When a player joins or reconnects, PlayFabTile checks if tile data exists on the server. If found, it parses the string into a dictionary and reapplies ownership to each TileVisualizer using AssignTileToPlayer().


Handle player leaving:

If a player leaves the room, their tiles are released with ReleaseTilesOwnedBy(), and the updated ownership is saved again with a short delay.

Camera Setup

To make the board easier to read and interact with, I added a basic camera control system. The script enables zooming, edge-scrolling, and reset. Each player in the game has their own individual camera instance. Camera controls are restricted to the local player, and other clients cannot affect it.


Zoom is controlled with the mouse scroll wheel, and transitions are smoothed using Mathf.SmoothDamp. Players can also hold the right mouse button to enable edge scrolling, which means they can move the mouse toward the screen edge pans the view.  Pressing the middle mouse button resets the camera to its default angle and position. This helps players quickly reorient themselves if they’ve panned or zoomed too far.


Final Outcome and Analysis

This system makes tile ownership persistent across sessions. If players disconnect or join late, they can see the correct ownership state and it supports real-time updates after each ownership change.

Design Patterns

  • Observer: tile changes trigger saves to PlayFab automatically. 
  •  Bridge: PlayFab acts as a bridge between TileVisualizer state and persistent storage. 

Future Plan

This backend setup is currently focused on tile ownership, but it could be extended to support more features later. If I had more time, I could expand the data format to include player money, power-ups, or turn position. That would make it possible to implement a Save & Resume feature. Another possibility is to change how disconnections are handled. Currently, tiles are cleared when a player leaves—but it would be easy to modify this to preserve ownership and allow rejoining without losing progress.

Reference

[1] Photon Engine. (n.d.). Multiplayer Game Development Made Easy. Available at: https://www.photonengine.com/[Accessed 30 Apr 2025].

[2] PlayFab. (n.d.). The Game Industry's Most Powerful Backend Platform. Available at: https://developer.playfab.com/ [Accessed 30 Apr 2025].

Leave a comment

Log in with itch.io to leave a comment.