इस गाइड में, Google Play Games PC SDK को अपने Unity प्रोजेक्ट में इंटिग्रेट करने के सिलसिलेवार निर्देश दिए गए हैं.
पहला चरण: एसडीके डाउनलोड करना
डाउनलोड लिंक का इस्तेमाल करके, Unity पैकेज का सबसे नया वर्शन डाउनलोड करें.
डाउनलोड करें: Play Games PC Unity SDK
दूसरा चरण: पैकेज इंपोर्ट करना
एसडीके को Unity Package Manager (UPM) के साथ काम करने वाली टार फ़ाइल के तौर पर डिस्ट्रिब्यूट किया जाता है. ज़्यादा जानकारी के लिए, लोकल टार फ़ाइल से UPM पैकेज इंस्टॉल करना लेख पढ़ें
तीसरा चरण: बिल्ड सेटिंग कॉन्फ़िगर करना
यह पुष्टि करने के लिए कि नेटिव लाइब्रेरी सही तरीके से लोड हो रही हैं, आपको अपने प्रोजेक्ट को कॉन्फ़िगर करना होगा. इसके लिए, IL2CPP स्क्रिप्टिंग बैकएंड का इस्तेमाल करें और सही आर्किटेक्चर को टारगेट करें.
प्लैटफ़ॉर्म के तौर पर Windows का इस्तेमाल करके, बिल्ड प्रोफ़ाइल बनाएं.
प्लैटफ़ॉर्म की सेटिंग में जाकर, Windows को चुनें. आर्किटेक्चर के लिए, इन विकल्पों का इस्तेमाल करें:
- Intel 64-bit (सुझाया गया)
- Intel 32-bit
ध्यान दें: Google Play Games on PC प्लैटफ़ॉर्म, 64-बिट एनवायरमेंट पर काम करता है. अपने गेम को 32-बिट (x86) या 64-बिट (x64) के तौर पर बनाया जा सकता है.
Scripting Backend को IL2CPP पर सेट करें. ज़्यादा जानकारी के लिए, IL2CPP की मदद से प्रोजेक्ट बनाना लेख पढ़ें.
- एपीआई के साथ काम करने वाले वर्शन का लेवल को .NET Standard 2.0 (या .NET Framework) पर सेट करें.
चौथा चरण: ऐप्लिकेशन मेनिफ़ेस्ट बनाना
अपने गेम में एसडीके का इस्तेमाल करने से पहले, आपको अपने गेम के एक्ज़ीक्यूटेबल को उस Play पैकेज के नाम से जोड़ना होगा जिस पर आपने Play Console में दावा किया है. इसके लिए, आपको अपने गेम के एक्ज़ीक्यूटेबल फ़ाइल वाली डायरेक्ट्री में manifest.xml फ़ाइल जोड़नी होगी.
ध्यान दें: यह एक मैन्युअल चरण है, जिसे पूरा करना ज़रूरी है.
- गेम की एक्ज़ीक्यूटेबल फ़ाइल बनाने के लिए, File > Build and
Run को चुनें या
Ctrl+Bपर क्लिक करें. - टेक्स्ट एडिटर खोलें और
manifest.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पर होना चाहिए.
पांचवां चरण: एसडीके को शुरू करना
बिलिंग या इंटिग्रिटी जैसी किसी भी सुविधा को ऐक्सेस करने से पहले, आपको एसडीके को शुरू करना होगा. 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 से अटैच करें. गेम चलाने के दौरान, Console में "SDK Initialized Successfully!" मैसेज देखें.