Skip to content

Commit

Permalink
PlayFab API scripts
Browse files Browse the repository at this point in the history
PlayFab REST API Docs
- https://learn.microsoft.com/en-us/rest/api/?view=Playfab

Use api
- LoginWithEmailAddress
- ExecuteCloudScript
  • Loading branch information
wooson00308 committed Oct 6, 2022
1 parent 9feff7d commit 41f55a2
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Assets/Scripts/PlayFab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions Assets/Scripts/PlayFab/AuthBackend.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using PlayFab;
using PlayFab.ClientModels;
using System;

public enum CallbackType
{
Success,
Fail
}

public class LoginInfo
{
public string email;
public string password;
}

public class LoginCallback
{
public CallbackType callbackType;
public LoginResult result;
public PlayFabError error;
}

public static class AuthBackend
{
public static void OnLogin(LoginInfo info, Action<LoginCallback> callback = null)
{
PlayFabClientAPI.LoginWithEmailAddress(new LoginWithEmailAddressRequest
{
Email = info.email,
Password = info.password,
TitleId = PlayFabSettings.TitleId
},
result =>
{
callback?.Invoke(new LoginCallback { callbackType = CallbackType.Success, result = result });
},
error =>
{
callback?.Invoke(new LoginCallback { callbackType = CallbackType.Fail, error = error });
});
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/PlayFab/AuthBackend.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions Assets/Scripts/PlayFab/DataBackend.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using PlayFab;
using PlayFab.ClientModels;
using System;
using UnityEngine;

public static class DataBackend
{
// Àӽà ÄÚµå
private static int _attackCount = 0;

public static void PlusAttackCount()
{
_attackCount++;
}

public static void UpdateLeaderboard(Action callback = null)
{
PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest
{
FunctionName = "updatePlayerLeaderboard",
FunctionParameter = new {
LeaderboardName = "AttackCount",
Value = _attackCount
},
GeneratePlayStreamEvent = true
},
result =>
{
callback?.Invoke();
Debug.Log("Leaderboard Update Success!");
},
error =>
{
callback?.Invoke();
Debug.LogError("Leaderboard Update Fail!");
});
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/PlayFab/DataBackend.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions UserSettings/EditorUserSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ EditorUserSettings:
RecentlyUsedScenePath-0:
value: 22424703114646680e0b0227036c683926582c2f3f3c2f3e2a0e0f3cf7ee3076f7e93ffdfe
flags: 0
RecentlyUsedScenePath-1:
value: 22424703114646680e0b0227036c761e1f03112b20213c313920123dacf53a31f6fe
flags: 0
RecentlyUsedScenePath-2:
value: 22424703114646680e0b0227036c721518020b6501292f3e002c1326acf53a31f6fe
flags: 0
vcSharedLogLevel:
value: 0d5e400f0650
flags: 0
Expand Down

0 comments on commit 41f55a2

Please sign in to comment.