LoginSignup
6
3

More than 5 years have passed since last update.

PlayFabでUnityを動かしてみる -その2 APIコールを作ってみる-

Posted at

その1はこちら

PlayFabを使い始めるための設定を行います。

(1)タイトルセッティング

その1でPlayFabの拡張をインストールしたので設定を行う

Playfab01.png

画面左にある「Project」パネルにある「Create」をクリック
Playfab01.png

C#スクリプトをクリック
Playfab02.png

ファイル名を「PlayFabLogin」に変更
ダブルクリックするとVisualStudioのコードエディターが起動する
Playfab03.png

エディターにマニュアルのコードを丸パクる

using PlayFab;
using PlayFab.ClientModels;
using UnityEngine;

public class PlayFabLogin : MonoBehaviour
{
    public void Start()
    {
        //Note: Setting title Id here can be skipped if you have set the value in Editor Extensions already.
        if (string.IsNullOrEmpty(PlayFabSettings.TitleId)){
            PlayFabSettings.TitleId = "XXX"; // Please change this value to your own titleId from PlayFab Game Manager
        }
        var request = new LoginWithCustomIDRequest { CustomId = "GettingStartedGuide", CreateAccount = true};
        PlayFabClientAPI.LoginWithCustomID(request, OnLoginSuccess, OnLoginFailure);
    }

    private void OnLoginSuccess(LoginResult result)
    {
        Debug.Log("Congratulations, you made your first successful API call!");
    }

    private void OnLoginFailure(PlayFabError error)
    {
        Debug.LogWarning("Something went wrong with your first API call.  :(");
        Debug.LogError("Here's some debug information:");
        Debug.LogError(error.GenerateErrorReport());
    }
}

こんな感じ
Playfab04.png

※こちらのコードはあくまでサンプルコードで、モバイルゲームの場合は別のコードになります

(2)実行してみる

新しいゲームオブジェクトを作成して、(1)で作成したスクリプトをアタッチして実行する
うまく実行できるとこんな感じで実行できる↓
Playfab05.png

次からは実際に動かした時の動きなどを検証してみたいと思います

6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3