This game requires the companion Azure Functions app to be deployed before the Unity project can run. See the Tic-Tac-Toe Functions sample for setup instructions.
Requirements
Unity 2019.1.8f1+
The project requires Unity 2019.1.8f1 or later.
PlayFab Unity Beta SDK
Included with the source code. The Azure Functions integration features are in beta and require the Beta SDK.
MK Glow Free plugin
A free third-party shader plugin for visual effects, available on the Unity Asset Store.
Azure Functions app
The companion Tic-Tac-Toe Functions app must be deployed and registered in PlayFab before running the game.
PlayFab configuration
1. Create a PlayFab title
Create a new PlayFab title named TicTacToe in Game Manager. Note the Title ID — you will need to enter it inAssets/Scripts/Constants.cs.
2. Enable Azure Functions integration
In Game Manager, navigate to Automation → Cloud Script → Functions and enable the Azure Functions integration.3. Register your Azure Functions
For each function in the Azure Functions app:- Get the invokable URL from the Azure Portal (Function → Get function URL, key type:
default (Function key)). URLs follow the format[function-app-name].azurewebsites.net/api/[function-name]. - In Game Manager under Automation → Cloud Script → Functions, click Register Function.
- Enter the function name and paste the URL, then click Register.
/Functions folder of the Tic-Tac-Toe Functions repository.
Only the URL of a registered function can be edited after registration. The function name cannot be changed, so double-check names before registering.
Setup
Deploy the Azure Functions app
Follow the setup guide in the Tic-Tac-Toe Functions sample to build and deploy the Azure Functions app, then complete the PlayFab configuration steps above.
Add the PlayFab Unity Beta SDK
Drag the
PlayFabSDK folder from the Beta SDK repository’s Source/ directory into the game’s Assets/ folder via the Unity Project View (not the OS file browser). Unity will recompile and generate .meta files automatically.Set the Title ID
Open
Assets/Scripts/Constants.cs and set TITLE_ID to the Title ID from your PlayFab title.Constants.cs
Game flow
Once the player is logged in, the game loop runs as follows:Player move
The player taps a cell. The client calls the
MakePlayerMove Azure Function, submitting the chosen row and column. If the move is valid the token is placed; otherwise the player must choose again.Win check after player move
The
WinCheck Azure Function evaluates the current board state. If the player has won, the game ends.AI move
The
MakeRandomAIMove or MakeMinimaxAIMove Azure Function generates the AI’s next move. If the AI cannot move (board full), its turn is skipped.Win check after AI move
WinCheck runs again. If the AI has won or the board is full with no winner, the game ends as a draw.Code structure
The game’s code lives inAssets/Scripts/ and is organized into the following files and folders.
Top-level files
| File | Responsibility |
|---|---|
Game.cs | Entry point. Manages the overall game lifecycle: player login, starting the game loop, detecting game-over conditions, and allowing the game to be restarted. |
Board.cs | MonoBehaviour attached to the physical board object in the scene. Holds three TokenRows, each containing three TokenPlaceholders representing the nine Tic-Tac-Toe cells. |
Settings.cs | Stores runtime configuration (Title ID, Azure Function URLs) and exposes it to the rest of the game. |
Constants.cs | Compile-time constants, including TitleID. |
/Handlers
Request handlers that wrap PlayFab SDK calls using Unity Coroutines, producing flat, readable async code without nested callbacks.| Handler | Azure Function called | Purpose |
|---|---|---|
LoginHandler.cs | — | Logs the player in via the PlayFab client SDK. |
PlayerMoveHandler.cs | MakePlayerMove | Submits a player move and receives a validity result. |
WinCheckHandler.cs | WinCheck | Submits the board state and receives a winner determination. |
AIMoveHandler.cs | MakeAIMove (registered name on PlayFab; backed by MakeRandomAIMove or MakeMinimaxAIMove) | Requests an AI move and receives the chosen cell. |
ResetGameStateHandler.cs | ResetGameState | Clears the server-side game state so a new game can start. |
RequestHandler.cs | — | Base class / utility shared by the other handlers. |
/Models
Data structures used for serialization between the Unity client and the Azure Functions.| Model | Description |
|---|---|
TicTacToeMove | Represents a move with row and col fields (lower-cased to match Azure Functions default serialization). |
MakeMoveRequest | Request payload for player and AI move functions. |
MakePlayerMoveResult | Response from MakePlayerMove, indicating whether the move was valid. |
MakeAIMoveResult | Response from the AI move functions, containing the AI’s chosen cell. |
WinCheckResult | Response from WinCheck, containing the GameWinnerType. |
GameWinnerType | Enum: NONE, PLAYER, AI, or DRAW. |
OccupantType | Enum representing a cell state: NONE, HUMAN, or AI. |
TokenPlaceholder | Model for a single board cell, tracking its OccupantType. |
TokenRow | Holds three TokenPlaceholders forming one row of the board. |
PlayerInfo | Stores the player’s PlayFab ID and display name. |
ResetGameStateRequest | Payload sent to ResetGameState. |
Key PlayFab features
Azure Functions integration
Replaces traditional CloudScript with Azure Functions, enabling strongly-typed C# server logic with full IDE support and local debugging.
ExecuteFunction
The PlayFab client API call used to invoke a registered Azure Function from the Unity game. Passes a request payload and returns a typed response.
LoginWithCustomID
Authenticates the player anonymously for quick local testing without requiring account creation.
Server-authoritative game state
Move validation, win detection, and AI logic all run on the server via Azure Functions, preventing client-side cheating.
Related samples
Tic-Tac-Toe Functions
The companion Azure Functions app that provides the server-side game logic required by this Unity client.
Sign-in
A focused sample demonstrating the PlayFab authentication flows used as the login step in this game.
