ऐसेट डिलीवरी (Unity) को इंटिग्रेट करना

ऐसेट डिलीवरी को इंटिग्रेट करते समय, Unity गेम इससे पता करने लायक जानकारी या AssetBundles का इस्तेमाल करके, ऐसेट पैक ऐक्सेस किए जा सकते हैं. पते वाले फ़ील्ड Unity के साथ बनाए गए गेम के लिए, नया और सुझाया गया ऐसेट डिलीवरी सलूशन 2019.4 या इसके बाद के वर्शन में, जबकि AssetBundles Unity में ऐसेट पैक इस्तेमाल करने की सुविधा देता है 2017.4 और 2018.4.

यूनिटी अड्रेसेबल

Unity 2019.4 या इसके बाद के वर्शन के साथ बनाए गए गेम में पते को ट्रैक करने की सुविधा मिलती है. Unity, Play ऐसेट डिलीवरी (PAD) एपीआई उपलब्ध कराता है का इस्तेमाल करें. इसका इस्तेमाल करने के बारे में जानकारी के लिए पते जोड़ने के लिए, यहां दी गई जानकारी देखें:

AssetBundle फ़ाइलों का इस्तेमाल करना

Unity 2017.4 और 2018.4 के साथ बनाए गए गेम में ऐसेट के लिए, AssetBundle फ़ाइलों का इस्तेमाल किया जा सकता है Android पर डिलीवरी पाएं. यूनिटी AssetBundle फ़ाइलों में सीरियल एसेट मौजूद हैं, जिन्हें Unity इंजन से लोड किया जा सकता है. ऐप चल रहा है. ये फ़ाइलें प्लेटफ़ॉर्म-विशिष्ट होती हैं (उदाहरण के लिए, Android) के साथ-साथ ऐसेट पैक के साथ भी इस्तेमाल किया जा सकता है. आम तौर पर, एक AssetBundle फ़ाइल, पैक के साथ, एक ऐसेट पैक में पैकेज की जाती है उसी नाम का इस्तेमाल करें जो AssetBundle है. अगर आपको अपने वीडियो की मदद से, ऐसेट पैक, एपीआई का इस्तेमाल करके ऐसेट पैक को कॉन्फ़िगर करें.

रनटाइम के दौरान, Unity के लिए Play ऐसेट डिलीवरी का इस्तेमाल करें क्लास का इस्तेमाल करें.

ज़रूरी शर्तें

  1. Play Asset Delivery Unity प्लगिन की सबसे नई रिलीज़, Google के इन पैकेज से डाउनलोड करें: Unity.

  2. Unity में AssetBundles बनाएं.

यूज़र इंटरफ़ेस (यूआई) का इस्तेमाल करके ऐसेट बंडल कॉन्फ़िगर करना

  1. किसी ऐसेट पैक में हर AssetBundle को कॉन्फ़िगर करें:

    1. Google > चुनें Android ऐप्लिकेशन बंडल > ऐसेट डिलीवरी की सेटिंग.
    2. उन फ़ोल्डर को चुनने के लिए जिनमें सीधे AssetBundle फ़ाइलें शामिल हैं, जोड़ें फ़ोल्डर.

  2. हर बंडल के लिए, डिलीवरी मोड को बदलकर इंस्टॉल करने में लगने वाला समय, तेज़ फ़ॉलो करें या मांग पर का विकल्प चुनें. सभी गड़बड़ियों या डिपेंडेंसी को ठीक करें और विंडो.

  3. Google > चुनें ऐप्लिकेशन बंडल बनाने के लिए, Android ऐप्लिकेशन बंडल बनाएं.

  4. (ज़रूरी नहीं) अलग-अलग टेक्सचर के साथ काम करने के लिए, अपने ऐप्लिकेशन बंडल को कॉन्फ़िगर करें कंप्रेशन फ़ॉर्मैट में बनाए जा सकते हैं.

एपीआई का इस्तेमाल करके ऐसेट पैक कॉन्फ़िगर करना

एडिटर स्क्रिप्ट की मदद से ऐसेट डिलीवरी को कॉन्फ़िगर किया जा सकता है. इस स्क्रिप्ट को पार्ट के तौर पर चलाया जा सकता है एक ऑटोमेटेड बिल्ड सिस्टम होना चाहिए.

इसका इस्तेमाल करें AssetPackConfig क्लास का इस्तेमाल करें, ताकि यह तय किया जा सके कि किसी Android ऐप्लिकेशन बंडल के बिल्ड में कौनसी एसेट शामिल की जाएं. ऐसेट के डिलीवरी मोड के तौर पर. इन ऐसेट पैक को शामिल करना ज़रूरी नहीं है कोई AssetBundle.

public void ConfigureAssetPacks {
   // Creates an AssetPackConfig with a single asset pack, named
   // examplePackName, containing all the files in path/to/exampleFolder.
   var assetPackConfig = new AssetPackConfig();
   assetPackConfig.AddAssetsFolder("examplePackName",
                                   "path/to/exampleFolder",
                                   AssetPackDeliveryMode.OnDemand);

   // Configures the build system to use the newly created assetPackConfig when
   // calling Google > Build and Run or Google > Build Android App Bundle.
   AssetPackConfigSerializer.SaveConfig(assetPackConfig);

   // Alternatively, use BundleTool.BuildBundle to build an App Bundle from script.
   BuildBundle(new buildPlayerOptions(), assetPackConfig);
}

आप स्टैटिक कॉलम का इस्तेमाल BuildBundle ऐसेट के साथ Android ऐप्लिकेशन बंडल जनरेट करने के लिए Bundletool क्लास में तरीका पैक, दिए गए बिल्डप्लेयर विकल्प और AssetPackConfig.

निर्देश देने वाले ट्यूटोरियल के लिए, यह देखें Unity गेम के लिए कोडलैब (कोड बनाना सीखना) में Play ऐसेट डिलीवरी का इस्तेमाल करना.

Play ऐसेट डिलीवरी Unity API के साथ इंटिग्रेट करना

कॉन्टेंट बनाने Play ऐसेट डिलीवरी Unity API इससे ऐसेट पैक का अनुरोध करने, डाउनलोड मैनेज करने, और ऐसेट ऐक्सेस करता है. सबसे पहले अपने प्रोजेक्ट में Unity प्लगिन जोड़ें.

एपीआई में इस्तेमाल किए जाने वाले फ़ंक्शन, इस बात पर निर्भर करते हैं कि आपने कैसे बनाया में सुधार करने के लिए प्रोत्साहित करते हैं.

अगर आपको प्लगिन यूज़र इंटरफ़ेस (यूआई) का इस्तेमाल करके ऐसेट पैक बनाए, प्लग इन से कॉन्फ़िगर किए गए ऐसेट पैक चुनें.

अगर आपको एपीआई (या प्लगिन यूज़र इंटरफ़ेस (यूआई)) का इस्तेमाल करके ऐसेट पैक बनाए, एपीआई से कॉन्फ़िगर किए गए ऐसेट पैक चुनें.

एपीआई को इस हिसाब से लागू किया जाता है कि डिलीवरी किस तरह की है आपको जिस ऐसेट पैक को ऐक्सेस करना है. यह तरीका यहां दिया गया है फ़्लोचार्ट.

प्लगिन के लिए, ऐसेट पैक के फ़्लो का डायग्राम

पहला डायग्राम. ऐसेट पैक ऐक्सेस करने का फ़्लो डायग्राम

AssetBundles फिर से पाएं

इंपोर्ट करें Play ऐसेट डिलीवरी लाइब्रेरी और कॉल RetrieveAssetBundleAsync() का इस्तेमाल कैसे किया जाता है.

using Google.Play.AssetDelivery;

// Loads the AssetBundle from disk, downloading the asset pack containing it if necessary.
PlayAssetBundleRequest bundleRequest = PlayAssetDelivery.RetrieveAssetBundleAsync(asset-bundle-name);

ऐप्लिकेशन इंस्टॉल करते समय डिलीवरी पाएं

install-time के तौर पर कॉन्फ़िगर किए गए ऐसेट पैक, ऐप्लिकेशन में तुरंत उपलब्ध हो जाते हैं लॉन्च. AssetBundle से कोई सीन लोड करने के लिए, इसका इस्तेमाल करें:

AssetBundle assetBundle = bundleRequest.AssetBundle;

// You may choose to load scenes from the AssetBundle. For example:
string[] scenePaths = assetBundle.GetAllScenePaths();
SceneManager.LoadScene(scenePaths[path-index]);

तेज़ी से फ़ॉलो करें और मांग पर डिलीवरी पाएं

ये सेक्शन, fast-follow और on-demand ऐसेट पैक पर लागू होते हैं.

स्थिति देखें

हर ऐसेट पैक को ऐप्लिकेशन के स्टोरेज में एक अलग फ़ोल्डर में सेव किया जाता है. इसका इस्तेमाल करें isDownloaded() का इस्तेमाल करके यह पता लगाया जा सकता है कि कोई ऐसेट पैक पहले ही डाउनलोड किया जा चुका है या नहीं.

डाउनलोड को मॉनिटर करें

क्वेरी PlayAssetBundleRequest अनुरोध की स्थिति पर नज़र रखें:

// Download progress of request, between 0.0f and 1.0f. The value will always be
// 1.0 for assets delivered as install-time.
// NOTE: A value of 1.0 will only signify the download is complete. It will still need to be loaded.
float progress = bundleRequest.DownloadProgress;

// Returns true if:
//   * it had either completed the download, installing, and loading of the AssetBundle,
//   * OR if it has encountered an error.
bool done = bundleRequest.IsDone;

// Returns status of retrieval request.
AssetDeliveryStatus status = bundleRequest.Status;
switch(status) {
    case AssetDeliveryStatus.Pending:
        // Asset pack download is pending - N/A for install-time assets.
    case AssetDeliveryStatus.Retrieving:
        // Asset pack is being downloaded and transferred to app storage.
        // N/A for install-time assets.
    case AssetDeliveryStatus.Available:
        // Asset pack is downloaded on disk but NOT loaded into memory.
        // For PlayAssetPackRequest(), this indicates that the request is complete.
    case AssetDeliveryStatus.Loading:
        // Asset pack is being loaded.
    case AssetDeliveryStatus.Loaded:
        // Asset pack has finished loading, assets can now be loaded.
        // For PlayAssetBundleRequest(), this indicates that the request is complete.
    case AssetDeliveryStatus.Failed:
        // Asset pack retrieval has failed.
    case AssetDeliveryStatus.WaitingForWifi:
        // Asset pack retrieval paused until either the device connects via Wi-Fi,
        // or the user accepts the PlayAssetDelivery.ShowConfirmationDialog dialog.
    case AssetDeliveryStatus.RequiresUserConfirmation:
        // Asset pack retrieval paused until the user accepts the
        // PlayAssetDelivery.ShowConfirmationDialog dialog.
    default:
        break;
}

बड़े डाउनलोड

जिन ऐसेट पैक का साइज़ 200 एमबी से ज़्यादा है वे अपने-आप डाउनलोड हो सकते हैं. हालांकि, ऐसा सिर्फ़ वाई-फ़ाई की मदद से किया जा सकता है. अगर आपने उपयोगकर्ता वाई-फ़ाई पर नहीं है, PlayAssetBundleRequest की स्थिति इस पर सेट है AssetDeliveryStatus.WaitingForWifi और डाउनलोड को रोक दिया जाता है. ऐसे में, डिवाइस के कनेक्ट होने तक इंतज़ार करें वाई-फ़ाई से कनेक्ट करें, डाउनलोड को फिर से शुरू करें या डाउनलोड करने के लिए उपयोगकर्ता से मंज़ूरी मांगें किसी मोबाइल इंटरनेट कनेक्शन का इस्तेमाल करके पैक करें.

उपयोगकर्ता की पुष्टि करना ज़रूरी है

अगर किसी पैक की स्थिति AssetDeliveryStatus.RequiresUserConfirmation है, तो डाउनलोड तब तक नहीं होगा, जब तक उपयोगकर्ता PlayAssetDelivery.ShowConfirmationDialog(). यह स्थिति तब पैदा हो सकती है, जब ऐप्लिकेशन Play ने इसकी पहचान नहीं की. ध्यान दें कि कॉलिंग इस मामले में PlayAssetDelivery.ShowConfirmationDialog() की वजह से ऐप्लिकेशन उन्हें अपडेट किया जाएगा. अपडेट के बाद, ऐसेट के लिए फिर से अनुरोध करें.

if(request.Status == AssetDeliveryStatus.RequiresUserConfirmation
   || request.Status == AssetDeliveryStatus.WaitingForWifi) {
    var userConfirmationOperation = PlayAssetDelivery.ShowConfirmationDialog();
    yield return userConfirmationOperation;

    switch(userConfirmationOperation.GetResult()) {
        case ConfirmationDialogResult.Unknown:
            // userConfirmationOperation finished with an error. Something went
            // wrong when displaying the prompt to the user, and they weren't
            // able to interact with the dialog.
        case ConfirmationDialogResult.Accepted:
            // User accepted the confirmation dialog--an update will start.
        case ConfirmationDialogResult.Declined:
            // User canceled or declined the dialog. It can be shown again.
        default:
            break;
    }
}

अनुरोध रद्द करना (सिर्फ़ मांग पर)

अगर आपको AssetBundles के लोड होने से पहले अनुरोध को रद्द करना हो मेमोरी, AttemptCancel() का तरीका PlayAssetBundleRequest ऑब्जेक्ट:

// Will only attempt if the status is Pending, Retrieving, or Available - otherwise
// it will be a no-op.
bundleRequest.AttemptCancel();

// Check to see if the request was successful by checking if the error code is Canceled.
if(bundleRequest.Error == AssetDeliveryErrorCode.Canceled) {
    // Request was successfully canceled.
}

एसिंक्रोनस रूप से एसेट पैक का अनुरोध करें

ज़्यादातर मामलों में, आपको कोरूटीन से एसिंक्रोनस तरीके से ऐसेट पैक का अनुरोध करें और प्रोग्रेस को मॉनिटर करें. फ़ॉलो किया जा रहा है:

private IEnumerator LoadAssetBundleCoroutine(string assetBundleName) {

    PlayAssetBundleRequest bundleRequest =
        PlayAssetDelivery.RetrieveAssetBundleAsync(assetBundleName);

    while (!bundleRequest.IsDone) {
        if(bundleRequest.Status == AssetDeliveryStatus.WaitingForWifi) {
            var userConfirmationOperation = PlayAssetDelivery.ShowCellularDataConfirmation();

            // Wait for confirmation dialog action.
            yield return userConfirmationOperation;

            if((userConfirmationOperation.Error != AssetDeliveryErrorCode.NoError) ||
               (userConfirmationOperation.GetResult() != ConfirmationDialogResult.Accepted)) {
                // The user did not accept the confirmation. Handle as needed.
            }

            // Wait for Wi-Fi connection OR confirmation dialog acceptance before moving on.
            yield return new WaitUntil(() => bundleRequest.Status != AssetDeliveryStatus.WaitingForWifi);
        }

        // Use bundleRequest.DownloadProgress to track download progress.
        // Use bundleRequest.Status to track the status of request.

        yield return null;
    }

    if (bundleRequest.Error != AssetDeliveryErrorCode.NoError) {
        // There was an error retrieving the bundle. For error codes NetworkError
        // and InsufficientStorage, you may prompt the user to check their
        // connection settings or check their storage space, respectively, then
        // try again.
        yield return null;
    }

    // Request was successful. Retrieve AssetBundle from request.AssetBundle.
    AssetBundle assetBundle = bundleRequest.AssetBundle;

गड़बड़ियों को हैंडल करने के बारे में ज़्यादा जानकारी के लिए, AssetDeliveryErrorCodes.

Play Core API के अन्य तरीके

नीचे एपीआई के कुछ अन्य तरीकों के बारे में बताया गया है, जिनका इस्तेमाल आपको अपने ऐप्लिकेशन में करना चाहिए.

डाउनलोड किए जाने वाले डेटा का साइज़ देखना

Google Play को एसिंक्रोनस कॉल करके, AssetBundle का साइज़ देखना और कार्रवाई पूरी होने के बाद कॉलबैक का तरीका सेट करें:

public IEnumerator GetDownloadSize() {
   PlayAsyncOperation<long> getSizeOperation =
   PlayAssetDelivery.GetDownloadSize(assetPackName);

   yield return getSizeOperation;
   if(operation.Error != AssetDeliveryErrorCode.NoError) {
       // Error while retrieving download size.
    } else {
        // Download size is given in bytes.
        long downloadSize = operation.GetResult();
    }
}

ऐसेट बंडल हटाएं

फ़ास्ट-फ़ॉलो और मांग पर उपलब्ध ऐसे AssetBundles को हटाया जा सकता है जो फ़िलहाल उपलब्ध नहीं हैं मेमोरी में लोड किया जा सकता है. नीचे दिया गया एसिंक्रोनस कॉल करें और कॉलबैक सेट करें इसके पूरा होने पर नीचे दिया गया तरीका अपनाएं:

PlayAsyncOperation<string> removeOperation = PlayAssetDelivery.RemoveAssetPack(assetBundleName);

removeOperation.Completed += (operation) =>
            {
                if(operation.Error != AssetDeliveryErrorCode.NoError) {
                    // Error while attempting to remove AssetBundles.
                } else {
                    // Files were deleted OR files did not exist to begin with.
                }
            };

अगले चरण

स्थानीय तौर पर और स्थानीय स्टोर से ऐसेट डिलीवरी की जांच करना Google Play से डाउनलोड करें.