Created
January 2, 2023 23:36
-
-
Save BlackFoxgamingstudio/8d277ae24fe30ec06a9a18e278305718 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using UnityEngine; | |
using PlayFab; | |
using PlayFab.ClientModels; | |
using Newtonsoft.Json; | |
using UnityEngine.UI; | |
public class PlayfabManager : MonoBehaviour { | |
public InputField input; | |
public Text output; | |
public void ExecuteButton() { | |
var request = new ExecuteCloudScriptRequest { | |
FunctionName = "QuestChain1", | |
FunctionParameter = new { | |
name = input.text | |
} | |
}; | |
PlayFabClientAPI.ExecuteCloudScript(request, OnExecuteSuccess, OnError); | |
} | |
void OnExecuteSuccess(ExecuteCloudScriptResult result) { | |
output.text = result.ToString(); | |
} | |
// 🎥 Playfab episode #1 - Login with custom ID | |
void Start() { | |
Login(); | |
} | |
void Login() { | |
var request = new LoginWithCustomIDRequest { | |
CustomId = SystemInfo.deviceUniqueIdentifier, | |
//CustomId = Random.Range(0, 100000).ToString(), <- ⭐️ Use this if you'd like to test something as a new user | |
CreateAccount = true, | |
InfoRequestParameters = new GetPlayerCombinedInfoRequestParams { | |
GetPlayerProfile = true | |
} | |
}; | |
PlayFabClientAPI.LoginWithCustomID(request, OnLoginSuccess, OnError); | |
} | |
void OnLoginSuccess(LoginResult result) { | |
Debug.Log("Successful login/account create!"); | |
string name = null; | |
if (result.InfoResultPayload.PlayerProfile != null) | |
name = result.InfoResultPayload.PlayerProfile.DisplayName; | |
} | |
// 🎥 Playfab episode #2 - Leaderboard (+ UI video) | |
// Error for all Playfab calls | |
void OnError(PlayFabError error) { | |
Debug.Log("Error while executing Playfab call!"); | |
Debug.Log(error.GenerateErrorReport()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment