Gaming Services Unity3D SDK

Sau khi bạn tích hợp phương thức Đăng nhập bằng Facebook, tính năng Chia sẻ lên Facebook hoặc Facebook Gaming, hệ thống sẽ tự động ghi và thu thập một số Sự kiện trong ứng dụng cho Trình quản lý sự kiện, trừ khi bạn tắt tính năng Tự động ghi sự kiện trong ứng dụng. Tất cả những nhà phát triển ứng dụng dùng phương thức Đăng nhập bằng Facebook, tính năng Chia sẻ lên Facebook hoặc Facebook Gaming nên nắm rõ cách hoạt động của chức năng này. Để biết chi tiết về loại thông tin được thu thập và cách tắt tính năng Tự động ghi sự kiện trong ứng dụng, hãy xem bài viết Tự động ghi sự kiện trong ứng dụng.

Gaming Services is available as a new component in the official Facebook SDK for Unity3D. Using Facebook official SDKs is the recommended approach and makes it easy to access services enabled by Facebook Login for Gaming including the Player Finder and Sharing (for Gaming) experiences.

Prerequisites

  1. Your application needs to enroll in Gaming Services to access features in this document. Follow the instructions to enroll your application.
  2. Make sure you have the minimal version of Facebook Unity3D SDK and above. Download the latest version.

Implementation

Facebook Login for Gaming

Facebook Login for Gaming enables a new login method for games. It supports the same implementation and SDK methods as Facebook Login. If this is the first time you're integrating the Facebook SDK into your App, refer to the configuration guide before proceeding.

Instead of receiving public_profile, your application will receive gaming_profile as the default permission. Other requestable permissions include user_friends, email, and gaming_user_picture.


Gaming Graph Domain

After integrating with Facebook Login for Gaming, your application will receive an access token for use on Gaming graph domain (graph.fb.gg), instead of the Facebook graph domain (graph.facebook.com). Read more about gaming graph domain.

You can check if the current User has connected with Facebook Login For Gaming by verifying the Graph Domain to be gaming in the Access Token:

// (c) Facebook, Inc. and its affiliates. Confidential and proprietary.
...
using Facebook.Unity;
...
AccessToken currentAccessToken = AccessToken.CurrentAccessToken;
if (currentAccessToken != null && currentAccessToken.GraphDomain == "gaming") {
  // current user has been migrated to Facebook Login for Gaming
}

Player Finder and Sharing for Gaming

Below is a Unity3D sample code showing how to implement Player Finder and Sharing (for Gaming).

// (c) Facebook, Inc. and its affiliates. Confidential and proprietary.
using Facebook.Unity;
...

// this is a general purpose IResult handler
// that can be used with the examples below.
protected void HandleResult(IResult result)
{
    if (result == null)
    {
      LogView.AddLog("Null Response\n");
      return;
    }

    // Some platforms return the empty string instead of null.
    if (!string.IsNullOrEmpty(result.Error))
    {
      // handle error case here.
    }
    else if (result.Cancelled)
    {
      // a dialog was cancelled.
    }
    else if (!string.IsNullOrEmpty(result.RawResult))
    {
       // success case! Do something useful with this.
    }
    else
    {
      // we got an empty response
    }
}
...

// binding Player Finder to a button
if (GUILayout.Button("Player Finder Button"))
{
  FBGamingServices.OpenFriendFinderDialog(HandleResult);
}
...

// Uploading an Image to use with Sharing (for Gaming)
FBGamingServices.UploadImageToMediaLibrary(
                        "test Image",
                        new Uri("/path/to/image/in/phone.jpg"),
                        true,
                        HandleResult);
...

// Uploading a Video to use with Sharing (for Gaming)
FBGamingServices.UploadVideoToMediaLibrary(
                        "test Video",
                        new Uri("/path/to/video/in/phone.mp4"),
                        HandleResult);