Tips to Choose Azure PlayFab Unity SDK or C# SDK for Unity Games
Azure PlayFab is a backend platform for games with managed game services like account management, economy, analytics, and LiveOps.
With PlayFab, you can save a huge amount of time without rebuilding the wheel and focus on making interesting features to engage players.
To integrate Azure PlayFab, you might come out with a few questions.
- How to integrate PlayFab SDK with Unity games?
- How to choose a suitable SDK for your Unity games?
This post will show the compression of both Unity SDK and C# SDK and provide guidelines for you to integrate.
Table of contents
- Unity SDK VS C# SDK
- How to integrate Unity SDK?
- How to integrate C# SDK?
Unity SDK VS C# SDK
Unity SDK
- Uses Callback pattern to return a value
- Can support Unity v5.3+
- Requires to handle the logic in a resultCallback and an errorCallback.
- Can support .NET 2.0 or higher
Pros :
- Highly flexible to be used for legacy games built with .NET 3.5 or new games with .NET 4.5 or above
Cons :
- It’s kind of hard to make your codes clean and control all the logic in one place due to the limitation of the callback pattern.
C# SDK
- Uses Task-based Asynchronou s Pattern (TAP): async/await
- Required to support C# v5 or above
- Only can support .NET 4.5 or higher
Pros :
- Make your codes clean
- Easy to maintain that you can control all the logic in the same place by async/await
Cons :
- You must use .NET 4.5 to implement
Analysis
If you have a new game project, it’s better to choose C# SDK for PlayFab because Task-based Asynchronous patterns will make your codes clean and easy to maintain.
While if you want to reuse existing codes from old game projects, Unity SDK with a callback pattern can be a good option to save your time.
Example:
Let’s demonstrate both SDKs to invoke the same function - LoginWithAndroidDeviceID.
Then you will get a sense of how it works and its difference.
Unity SDK
- In LoginPlayFab, you cannot get the returned value but need to rely on callback function OnSuccLoginDeviceID and OnErrorLoginDeviceID.
- This makes your codes hard to debug and trace errors when your code project becomes bigger.
C# SDK
- You can get the returned result in the same function as shown above and your code is much easier to read and maintain.
Then you can also use await Login() to get the result as below.
How to integrate Unity SDK?
- Download the PlayFab Unity SDK package here.
- Import it into your project
- Setup Title ID and Developer Secret Key in PlayFabSDK/Shared/Public/Resource/PlayFabSharedSettings.asset
- Then you can start coding
You can find Title ID and Developer Secret Key (serve seret key) in Payfab web portal — https://developer.playfab.com/en-us/login
How to integrate C# SDK?
- This is a little bit tricky because you need to download PlayFab’s source and place it in your code project.
- Download and import the following folder into your Assets\Scripts\
- https://github.com/PlayFab/CSharpSDK/tree/master/XamarinTestRunner/XamarinTestRunner/PlayFabSDK
Why we need to use PlayFab SDK in a sampe project?
Becaue I found codes in master branch are not stable with lots of errors While PlaySDK in sample project seems to be much stable.
Why not use PlayFabSDK.dll?
This is possible but you neeed to tweak it and make it work in Unity while source code is much easier.
- Setup Title ID and Developer Secret Key in apiSettings.
- Pass apiSettings to clientApi.
Summary
You have learned the difference between PlayFab Unity SDK and C# SDK in this post.
Basically, they can all support your Unity games but the .NET version and the way to return values are different.
- Callback pattern
- Task-based Asynchronous pattern
I hope this post is helpful for you in choosing a suitable pattern for your game projects to boost work productivity.
If you found this article helpful, please follow us on Facebook to get the latest tutorials in the future.
Thank you for reading!