소셜 API
소셜 API 사용하여 GameCenter와 상호 작용합니다.
읽는 시간 1분최근 업데이트: 9일 전
소셜 API 다음과 같은 소셜 기능에 액세스하는 Unity 포인트입니다.
- 사용자 프로필
- Friends 목록
- 업적
- Leaderboards
GameCenter와 같은 다양한 소셜 백엔드에 통합된 인터페이스를 제공하며 게임 프로젝트의 프로그래머가 주로 사용하도록 고안되었습니다.
소셜 API 주로 비동기 API, 일반적으로 함수를 호출하고 해당 함수가 완료되면 콜백을 등록하여 사용합니다. 비동기 함수는 API 특정 상태 변수를 채우는 등 부작용이 있을 수 있으며, 콜백에는 처리할 서버의 데이터가 포함될 수 있습니다.
Social 클래스는 UnityEngine 네임스페이스에 상주하며 항상 사용할 수 있지만 다른 Social API 클래스는 자체 네임스페이스인 UnityEngine.SocialPlatforms에 유지됩니다. 또한 소셜 API SocialPlatforms.GameCenter와 같은 하위 네임스페이스에 구현됩니다.
다음은 소셜 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"); }); }}
소셜 API에 대한 자세한 내용은 소셜 API 스크립팅 레퍼런스를 참조하십시오.