소셜 API는 Unity에서 다음과 같은 소셜 기능에 액세스하는 방법입니다.
API는 GameCenter 같은 다양한 소셜 백엔드용 통합 인터페이스를 제공하고, 주로 게임 프로젝트의 프로그래머가 사용하도록 고안되었습니다.
소셜 API는 기본적으로 비동기 API이며, 일반적으로 함수를 호출하고 해당 함수가 완료되면 콜백을 등록하는 방식으로 사용됩니다. 비동기 함수는 특정 상태 변수를 API에 채우고 콜백에 서버에서 전송된 처리할 데이터가 포함될 수 있는 등 몇 가지 부작용이 있습니다.
Social 클래스는 UnityEngine 네임스페이스에 있으므로 항상 사용 가능하지만, 다른 소셜 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에 대한 자세한 내용은 Social API 스크립팅 레퍼런스를 참조하십시오.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.