ドキュメント

Unity Engine

Unity Engine

ソーシャル API

Social API を使用して GameCenter とインターフェースします。
読み終わるまでの所要時間 3 分最終更新 7日前

注
ソーシャル API は非推奨で、将来のリリースで削除されます。
Social APIは、次のようなソーシャル機能にアクセスするUnityのポイントです。
  • ユーザープロファイル
  • Friends リスト
  • 事跡
  • 統計/Leaderboardsボード
GameCenter などのさまざまなソーシャルバックエンドに統一されたインターフェースを提供し、主にゲームプロジェクトのプログラマーが使用することを目的としています。
Social API は主に非非同期 API で、一般的な使用方法は機能コールを行い、その機能が完了したときのコールバックを登録することです。非非同期機能には、API で特定のステート変数を入力するなどの副作用があり、コールバックには処理するサーバーからのデータが含まれる場合があります。
Social クラスは UnityEngine 名前空間に存在し、常に使用可能ですが、その他の Social API クラスは独自の名前空間 UnityEngine.SocialPlatforms に保持されます。さらに、Social API の実装は SocialPlatforms.GameCenter などのサブ名前空間にあります。
Social API の使用例を次に示します。
using UnityEngine;using UnityEngine.SocialPlatforms;public class SocialExample :MonoBehaviour { void Start () { // Authenticate and register a ProcessAuthentication callback // This call needs to be made before we can proceed to other calls in the Social API Social.localUser.Authenticate (ProcessAuthentication); } // This function gets called when Authenticate completes // Note that if the operation is successful, Social.localUser will contain data from the server. void ProcessAuthentication (bool success) { if (success) { Debug.Log ("Authenticated, checking achievements"); // Request loaded achievements, and register a callback for processing them Social.LoadAchievements (ProcessLoadedAchievements); } else Debug.Log ("Failed to authenticate"); } // This function gets called when the LoadAchievement call completes void ProcessLoadedAchievements (IAchievement[] achievements) { if (achievements.Length == 0) Debug.Log ("Error: no achievements found"); else Debug.Log ("Got " + achievements.Length + " achievements"); // You can also call into the functions like this Social.ReportProgress ("Achievement01", 100.0, result => { if (result) Debug.Log ("Successfully reported achievement progress"); else Debug.Log ("Failed to report achievement"); }); }}
Social API の詳細については、Social API スクリプティングリファレンス を参照してください。