Get Started
Download
You must imperatively have the playfab SDK in your project. This is a service that will be used to store all player data. Normally this one is attached in the asset, but if you encounter errors delete it and download it here.
Configuration
-
Step 1: Create a PlayFab Application
Congratulations, you are now connected to the Play Fab services, all you have to do is create your application, to do so, simply follow the steps indicated. You should have this:
-
Step 2: Configure your PlayFab Application
Now click on your game to access this information, then follow this video.
This step is very important, it will allow users to store their data.WARNING by checking this box, your game can be submitted to cheat!
If you want to switch to a secure transfer, this option is available in the Complete Account with Database Asset, which also contains a virtual currency system, friends list, leaderboards, and more....
-
Step 3: Get your Application ID
Now, all you have to do is retrieve your game ID, in the settings, from where you were:
Copy your Title ID to your clipboard and proceed to the next step. -
Step 4: Unity Pre-Configuration
So, now you can go back to Unity to set up your project. In the action bar, go to Database Controller > Settings
This window should then open:
-
Step 5: Unity Configuration
Go to the scene you will use for your connection system.
ATTENTION only one scene can be used per project to avoid any problems.
Then, in the settings window that was opened earlier, click the “Create this object for me” button. After which, you can enter your application ID (step 3) in the Project ID selection.
If you are developing a mobile game, and would like to use the anonymous connection option, please switch your project to iOS or Android if you haven’t already done so. This option is only available for mobile.
Now all you have to do is fill in all the necessary objects in the management window and press “Apply”.
A confirmation message should appear in the Unity console.
Congratulations, you have successfully configured your project.
Now you can build your level in order to implement the login system for the user.
You can help yourself from the demo scene to better understand.
Implementations (Unity C#)
During this part, you will be able to see some implementations that you may not use in your project, if so, just skip the part in question.
1 - Get Started
In order to properly prepare your system, you will need only one thing, a script that will manage the elements of your scene.
If you have a problem or hesitation, do not hesitate to consult our demo script, or join us on discord.
Step 1:
Open your script, and at the top, insert the following line : ‘using DatabaseAPI.Account;’
(this is our demo script, you can find it in the asset folder > Demo > scripts).
Now, you're able to use our asset in your script.
ATTENTION more namespace can be used, refer to the Extras part of this documentation.
2 - Connection
Step 1:
Once the API is imported into your script, you can create your first calling functions.
Here are the available instructions:
-
1 - Get the username of the person to be registered (Complete void bellow)
public void GetUserName(string value) { AccountController.controller.GET_USER_USERNAME(value); }
-
2 - Get the email address of the user to connect/register (Complete void bellow)
public void GetUserEmail(string value) { AccountController.controller.GET_USER_EMAIL(value); }
-
3 - Get the password of the user to log in/register (Complete void bellow)
public void GetUserPassword(string value) { AccountController.controller.GET_USER_PASSWORD(value); }
-
4 - Send a connection request (line 176 in demo script)
AccountController.controller.LOGIN_ACTION();
-
5 - Send an account creation request (line 178 in demo script)
AccountController.controller.ON_CLIC_CREATE_ACCOUNT();
-
6 - Send a Logout Request (line 182 in demo script)
AccountController.controller.LOG_OUT();
Step 2:
All right, now, save and go back to unity to link these new functions to your buttons.
The first 3 functions listed above must be added to InputFields, in the “On Value Changed” section.
CAUTION choose the Dynamic string, otherwise your function will not work.
ATTENTION be careful, it's not necessary, but you can select the true option in Content type, Email Address for email, Password for the password, and standard for username.
Now, you just have to put the login or connect function to your button in the on Click function.
3 - Mobile Anonymous Connection
If you dont made a mobile game, please skip this part
This anonymous login allows the user to start playing without creating an account. The anonymous login still create an account to the user, which will allow him an automatic login every time the application opens. Its ID and password will be defined by its phone ID. Using the anonymous connection does not prevent linking your profile to an existing account or a new one afterwards.
If you want to use this option, you don’t need a connection scene, you are strongly advised to do this section in your main menu scene.
Prerequisites:
in your scene, main menu for example, you will need a button to open the backup account section, and a panel that will allow the user to enter this data (email, and password as well as a username, which will only be processed if the connection does not work).
Step 1: Write the new functions in your script
-
1 - This first command is simply used to open your connect recovery panel.
public void OpenCloseRecoverySection() { AccountController.controller.OPEN_RECOVERY_PANEL(); }
-
2 - Now, this function is used to request a recovery connection, like on a login button
public void CreateRecoveryAccount() { AccountController.controller.ON_CLIC_ADD_RECOVERY(); }
4 - User Statistics
You can only save integer (int) values!
This section is relatively simplistic, everything is already done for you.
The first thing to know, is that when connecting, all user data is stored in a local dictionary.
You can view it and retrieve this data by simply typing:
AccountController.playerData.TryGetValue(NAME OF THE VALUE SAVED, out VALUE TO UPDATE)
You can see this template in the demo script, line 44.
How to save new data or update one:
AccountController.controller.SetStat(NAME OF THE VALUE TO SAVED, VALUE TO SAVE);
You can see this template in the demo script, line 104.
Extras
In this last part of the Asset manual, you can find several small functions that may be useful to you.
-
1 - Knowing when you are logged into an account
You can say that this option has no interest, but on the contrary, it’s necessary! When you log in, how do you know if that connection failed, and therefore how do you make sure that you can start the next scene, such as a main menu.
To access this information, you have this boolean available:
AccountController.controller.connectedToAnAccount
If you are logged in, this boolean will return True.
If you are looking for how to integrate it, you can consult the demo script of line 34 to 41. -
2 - Know when data has finished loading
Looking at these lines 34 to 41 of the demo script, you must have seen this:
AccountController.controller.getStatsFinished
This statement is also a boolean. It allows to know the state of loading of the user’s data. This boolean will equal True when all data is finished loading.
This option allows for example the use of a loading screen, to avoid that once logged in, the user sees erroneous data because not yet updated. -
3 - Retrieve errors
It’s also one of the most important elements, how to warn the user of a failure.
To do this, you have access to a variable that will allow you to directly retrieve the entire error message:
AccountController.DebugMessage
this simple command allows you to retrieve the error message, then you can either process it or return it as it was to the user.
Example of use:
public Text errorMsg; // using UnityEngine.UI;
void Update() { errorMsg.text = AccountController.DebugMessage; } -
4 - Get the User ID
Do you need your player’s server ID? you can retrieve it by typing AccountController.userID
User Id is a string that will contain the id of the currently connected player.
You can find it in the demo script, from lines 59 to 56.
How to use PlayFab dashboard
-
1 - Accessing Users
-
2 - View his data
Once on the players reference page, click on one of the list to access their profile.
Once on a profile, the Overview page references this personal data, then the Statistics section will show you its data that you have chosen to save online, and finally, the Logins section will show you these latest connections.
The other sections will probably not be useful to you with this asset, as they are not compatible.
To go to your dashboard, in the unity action bar go to: Database Controller > Your Dashboard