# PlayFab

### :large\_blue\_diamond: Setup PlayFab

{% hint style="info" %}
You can try to check Unity Playfab at this [guide](https://learn.microsoft.com/en-us/gaming/playfab/sdks/unity3d/quickstart).
{% endhint %}

1. Create your PlayFab account follow this [link](https://developer.playfab.com/en-us/sign-up).

2. When you created an PlayFab account, copy your title ID.\
   \
   &#x20;

   <figure><img src="/files/nxXWVVVyM8iJWBy4ev8C" alt=""><figcaption></figcaption></figure>

3. In Unity editor, select Window menu -> PlayFab -> Editor Extensions.

4. Paste your title ID on PlayFab Editor Extensions Window.\ <br>

   <figure><img src="/files/m4sGkqGL4ehBtB14Q0kZ" alt="" width="338"><figcaption></figcaption></figure>

5. Done for setup PlayFab.

### :large\_blue\_diamond: Control Showing Ads With PlayFab

{% hint style="info" %}
To use this feature, you need to complete steps setup PlayFab above.
{% endhint %}

By using title data on PlayFab dashboard, you can control amount of ads are shown in the game. You can follow steps below to use this feature:

1. In Unity editor, open main menu scene -> select Ads Manager game object -> check the box "Control Ads With PlayFab".\ <br>

   <figure><img src="/files/EKoMUqSZxUvkLPRrTef5" alt="" width="563"><figcaption></figcaption></figure>

2. On PlayFab dashboard, select content -> title data -> edit.\ <br>

   <figure><img src="/files/mwv3p9lnFEPY8dBPzAD9" alt=""><figcaption></figcaption></figure>

3. Add two new keys *<mark style="background-color:blue;">numEndGameClassicToShowAd</mark>* and *<mark style="background-color:blue;">numExitLobbyToShowAd</mark>* . Then, set the value you want for both keys.\ <br>

   <figure><img src="/files/3r0lr26EhMWK4kAAebZD" alt=""><figcaption></figcaption></figure>

   \
   \&#xNAN;*Note: The name keys need to be same on PlayFab dashboard and at Ads Manager script. You can set other key name you like on PlayFab dashboard, but remember to change key name at The Ads Manager script same as key name on PlayFab dashboard well.* \ <br>

   <figure><img src="/files/woyjwFyjcIavYwBOEPkm" alt=""><figcaption><p><em>Ads Manager Script.</em></p></figcaption></figure>

4. Done, you can use this feature now.

<mark style="color:yellow;">Example how this feature work:</mark>

* If you set *<mark style="background-color:blue;">numEndGameClassicToShowAd = 2</mark>* . In classic mode, whenever players complete or fail a level, it counts as an attempt. After two attempts, ads will be displayed on either the win screen or the fail screen.
* If you set *<mark style="background-color:blue;">numExitLobbyToShowAd = 3</mark>  .* In lobby multiplayer mode, whenever players click on exit lobby button or click on leave room button, it counts as an attempt. After three attempts, ads will be displayed.

### :large\_blue\_diamond: Save Cloud With PlayFab

{% hint style="info" %}
To use this feature, you need to complete steps setup PlayFab above.
{% endhint %}

Follow below steps to use this feature:

1. In Unity editor, open main menu scene -> select Save Load Manager game object -> check the box "Is Use Save Cloud".\ <br>

   <figure><img src="/files/gY68Aq1qiPM1VSeTSBtb" alt="" width="563"><figcaption></figcaption></figure>

2. Done, we can use this feature now.

<mark style="color:yellow;">How this feature work:</mark>

The GameData class will be saved like json and this json will be sent to PlayFab server. We can view the GameData class on PlayFab dashboard by steps:

1. On PlayFab dashboard, select Players -> Click on search button.\ <br>

   <figure><img src="/files/A8FaXmlBqyt96YjTJClF" alt=""><figcaption></figcaption></figure>

2. When click on search button, PlayFab will show list players, you can try to select any players you like. In the player, select Player Data (Title) -> click on json button.\ <br>

   <figure><img src="/files/FGO4XCzpTcToGuD5Pwlc" alt=""><figcaption></figcaption></figure>

3. When you clicked on json button, PlayFab will show an json window. You can view player data on this window.\ <br>

   <figure><img src="/files/MlNAG7lZ30YGK8PAG4gV" alt="" width="563"><figcaption></figcaption></figure>

{% hint style="info" %}
The Save Cloud feature operates using PlayFab's anonymous login method. This simple login method is used for backing up player data on their device and tracking which mobile platforms players use to play the game. You can refer to [this document](https://learn.microsoft.com/en-us/gaming/playfab/features/authentication/login/login-basics-best-practices#anonymous-login-mechanisms) for more details about this login method.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://black-knight.gitbook.io/2d-racing-multiplayer-game-template/customization/playfab.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
