이 가이드에서는 Google Play 게임즈 PC SDK를 Unity 프로젝트에 통합하는 단계별 안내를 제공합니다.
1단계: SDK 다운로드
다운로드 링크를 사용하여 최신 버전의 Unity 패키지를 다운로드합니다.
다운로드: Play 게임즈 PC Unity SDK
2단계: 패키지 가져오기
SDK는 Unity Package Manager (UPM)와 호환되는 tar 파일로 배포됩니다. 자세한 내용은 로컬 tar 파일에서 UPM 패키지 설치를 참고하세요.
3단계: 빌드 설정 구성
네이티브 라이브러리가 올바르게 로드되는지 확인하려면 IL2CPP 스크립팅 백엔드를 사용하고 올바른 아키텍처를 타겟팅하도록 프로젝트를 구성해야 합니다.
플랫폼이 Windows인 빌드 프로필을 만듭니다.
플랫폼 설정을 Windows로 선택합니다. 아키텍처의 경우 다음 옵션을 사용합니다.
- Intel 64비트 (권장)
- Intel 32비트
참고: PC용 Google Play 게임즈 플랫폼은 64비트 환경에서 실행됩니다. 게임을 32비트 (x86) 또는 64비트 (x64)로 빌드할 수 있습니다.
Scripting Backend(스크립팅 백엔드)를 IL2CPP로 설정합니다. 자세한 내용은 IL2CPP로 프로젝트 빌드를 참고하세요.
- API 호환성 등급을 .NET Standard 2.0(.NET Framework)으로 설정합니다.
4단계: 애플리케이션 매니페스트 만들기
게임에서 SDK를 사용하려면 먼저 Play Console에서 소유권을 주장한 Play 패키지 이름과 게임 실행 파일을 연결해야 합니다. 게임의 실행 파일과 동일한 디렉터리에 manifest.xml 파일을 추가하여 이를 실행할 수 있습니다.
참고: 이 단계는 수동으로 수행해야 합니다.
- 게임 실행 파일 빌드하려면 File > Build and Run을 선택하거나
Ctrl+B을 클릭합니다. - 텍스트 편집기를 열고
manifest.xml이라는 새 파일을 만듭니다. 다음 XML 코드를 복사하여 파일에 붙여넣습니다.
<?xml version="1.0" encoding="utf-8"?> <?Manifest version="1"> <?Application> <?PackageName>com.example.package<?/PackageName> <?/Application> <?/Manifest>
파일을
manifest.xml로 저장합니다.이 파일을 빌드된 게임 실행 파일과 동일한 폴더로 이동합니다.
예: 게임이
Builds/MyGame.exe에 있으면 매니페스트는Builds/manifest.xml에 있어야 합니다.
5단계: SDK 초기화
결제 또는 무결성과 같은 기능에 액세스하기 전에 SDK를 초기화해야 합니다. PlayPcSdkFactory를 사용하여 초기화 핸들러를 만들고 연결을 시작합니다.
새 C# 스크립트(예: SdkInitialization.cs)를 만들고 다음 코드를 추가합니다.
using UnityEngine; using System; using System.Threading.Tasks; // Import the SDK namespaces using PlayPcSdkManaged.Initialization; using PlayPcSdkManaged.Unity; public class GooglePlayPCSDKInit : MonoBehaviour { // Prevent double-initialization if this script is reloaded private static bool _isInitialized = false; private void Start() { // Use the "Safe Runner" pattern to fire the async method _ = InitializeSdkAsync(); } private async Task InitializeSdkAsync() { if (_isInitialized) { Debug.LogWarning("Google Play PC SDK is already initialized. Skipping."); return; } try { Debug.Log("Initializing Google Play PC SDK..."); // 1. Get the Unity-specific initialization handler from the factory var initHandler = PlayPcSdkFactory.InitializationHandler; // 2. Call InitializeAsync to start the connection var result = await GooglePlayInitialization.InitializeAsync(initHandler); // 3. Check the result if (result.IsOk) { _isInitialized = true; Debug.Log("<color=green>Google Play PC SDK Initialized Successfully!</color>"); // You can now create BillingClient or IntegrityClient instances } else { Debug.LogError($"<color=red>Initialization Failed!</color>"); Debug.LogError($"Error Code: {result.Code}"); Debug.LogError($"Message: {result.ErrorMessage}"); } } catch (Exception ex) { // Catch unexpected crashes or task failures Debug.LogError($"Exception during initialization: {ex.Message}"); Debug.LogException(ex); } } }
이 스크립트를 첫 번째 장면의 GameObject에 연결합니다. 게임을 실행할 때 콘솔에서 'SDK가 성공적으로 초기화되었습니다' 메시지를 확인합니다.