PlayFabManager.cs 소스입니다
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PlayFab;
using PlayFab.ClientModels;
using PlayFab.Json;
using UnityEngine.UI;
public class PlayFabManager : MonoBehaviour
{
#region 로그인
public InputField EmailInput, PasswordInput, UsernameInput;
public void Register()
{
var request = new RegisterPlayFabUserRequest { Email = EmailInput.text, Password = PasswordInput.text, Username = UsernameInput.text, DisplayName = UsernameInput.text };
PlayFabClientAPI.RegisterPlayFabUser(request, (result) => print("회원가입 성공"), (error) => print("회원가입 실패"));
}
public void Login()
{
var request = new LoginWithEmailAddressRequest { Email = EmailInput.text, Password = PasswordInput.text };
PlayFabClientAPI.LoginWithEmailAddress(request, (result) => print("로그인 성공"), (error) => print("로그인 실패"));
}
#endregion
// C# 스크립트 using PlayFab.Json;
[ContextMenu("클라우드 스크립트 실행")]
void StartCloudScript()
{
PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest()
{
FunctionName = "helloWorld",
FunctionParameter = new { ro = "ㅎㅇㅎㅇ" },
//GeneratePlayStreamEvent = true
}, OnCloudHelloWorld, (error) => print("실패"));
}
void OnCloudHelloWorld(ExecuteCloudScriptResult result)
{
JsonObject jsonResult = (JsonObject)result.FunctionResult;
jsonResult.TryGetValue("messageValue", out object messageValue);
Debug.Log((string)messageValue);
}
[ContextMenu("클라우드 스크립트 데이터 저장")]
void StartSetData()
{
PlayFabClientAPI.ExecuteCloudScript(
new ExecuteCloudScriptRequest
{
FunctionName = "SetData",
FunctionParameter = new { onlineState = true },
GeneratePlayStreamEvent = true
},
null, null);
}
}
클라우드 스크립트 입니다
handlers.helloWorld = function (args, context) {
if(args.hasOwnProperty("text"))
{
var message = "Hello " + currentPlayerId + "! " + args.text;
log.info(message);
}
else log.info("핵 의심");
return { messageValue: message };
};
handlers.SetData = function(args, context) {
var isOnline = args.onlineState;
server.UpdateUserData({ PlayFabId: currentPlayerId, Data: {"IsOnline" : isOnline}, Permission: UserDataPermission.Public });
};