Quantcast
Jump to content


Recommended Posts

Posted

2021-06-07-01-banner_v2.jpg

Unity Distribution Portal (UDP) lets you distribute your games to multiple app stores through a single hub. UDP repacks your Android build with each store’s dedicated In-App Purchase SDK to make your game compatible with the separate app stores (Android alternative app stores). In this tutorial, you will learn the procedure for publishing a game on Galaxy Store using the UDP console. All you need to do is implement in-app purchases (IAP) using UDP. UDP then automatically repacks your game into store-specific builds. Follow the tutorial to integrate UDP into your game and publish it on Galaxy Store.

Before you start

We recommend that you implement UDP in your game towards the end of the development cycle. It is easier to implement UDP at this stage as you have already decided what your game’s IAP items are. Make sure you have completed your game before diving into the UDP implementation. We have developed a sample coin collecting game (see Figure 1) in Unity and we’ll show you how we implemented UDP into this game.


2021-06-07-01-01.jpgFigure 1: Preview of the sample game developed in Unity.


Note that there are three types of Samsung IAP items: consumable (single use, re-purchasable), non-consumable (unlimited use, not re-purchasable), and subscription (unlimited use while active). Since UDP does not support subscriptions, there is no guidance for implementing subscription items in this post.

Now that you know when to implement UDP and which Samsung IAP items are supported, we’re ready to begin with the development procedure.

Create a game in the UDP console

After signing in to UDP, please follow the steps below:

  1. Go to My Games -> ADD GAME, enter the game title, and click on CREATE. After that, you are automatically moved to the Game Info tab.
  2. In the Game Description tab, provide some basic information (metadata, description, visual assets, and ratings).
  3. Click on SAVE. You are not required to complete all sections at this time.

Integrate UDP in Unity and link it to the UDP console

There are two ways to integrate UDP in Unity: using the UDP package or Unity IAP. We used the UDP package for this blog. To do this, follow the steps below:

  1. In the Unity editor, go to Window -> Package Manager, select All packages -> Unity Distribution Portal -> Install.
  2. To enable UDP in your project, access Window -> Unity Distribution Portal -> Settings.
  3. Create a new Unity project ID (if required, or else use an existing one) in the Services Window. To do this, click on Go to the Services Window, select your organization, and then click Create.
  4. Obtain the client ID from the UDP console: go to the Game Info tab of the UDP console, scroll down to Integration Information, and copy your Client ID using the COPY button.
  5. Now, go back to Window -> Unity Distribution Portal -> Settings, paste the client ID into the relevant field, and finally click on Link Project to this UDP game.

Now you have successfully linked your Unity project to the game created on the UDP console. If you’re having problems, go here to try some troubleshooting methods before jumping into the next section.

Register IAP items in UDP

There are two IAP products in our sample game: “Super Jump” (consumable) and “Upgraded Player” (non-consumable). We need to add these products in the UDP console so they can be purchased inside the game. We can register the items directly either on the UDP console or in the Unity editor.

Follow the steps below for the UDP console:

  1. Go to the Game Info tab of the UDP console, scroll down to In-App Purchases, and select Add Item. Do not forget to click on EDIT INFO, if required.
  2. Provide a valid product ID, product name, price (USD), and description. Select if the item is consumable or non-consumable, then click SAVE. You can add as many products as you have in your game. For our sample game, we have added a consumable and a non-consumable item with the product IDs “superjump1” and “upgradeplayer1” respectively. Please remember the IDs you choose as these are required while initiating purchases.
  3. You can manage the prices in different currencies for each product individually by clicking on Manage amounts and currencies. You can also automatically convert your base price (USD) to different currencies for all your products at once by clicking Convert.
  4. Select SAVE in the top right corner to save your changes.
  5. In Unity, go to Window -> Unity Distribution Portal -> Settings, and click on Pull to retrieve your saved IAP items from the UDP server. Now, you can see all the items are added to the IAP Catalog.

You can also add IAP items in Unity directly in the IAP Catalog by clicking on Add New IAP Product, and then selecting Push to save your products to the UDP server (see Figure 2). In addition, there are many manipulation processes for adding IAP items (for example, bulk import and CSV template). Click here to learn more.


2021-06-07-01-02.jpgFigure 2: IAP Catalog under UDP Settings in Unity.


Initialize the UDP SDK in Unity

To access the UDP SDK, we need to declare the UDP namespace inside the game manager script. Please note that “player.cs” is the manager script in our sample project and is attached to the main player game object in the editor as a component. Hence, from now on we continue editing the codes into this script to enable all the UDP functionalities. Follow the steps below:

  1. Add the following line at the beginning to access the UDP libraries.

    using UnityEngine.UDP; 
    
  2. Make the manager code (player.cs) inherit from the IInitListener interface.

    public class player : MonoBehaviour, IInitListener
    
  3. In the Start() function of the manager (player.cs) class, call the Initialize() method.

    StoreService.Initialize(this);
    
  4. The IInitListener then returns a success or failure message to inform your game if the initialization was successful. Implement the following methods in the same class to obtain this message: if it is successfully initialized, the OnInitialized() method is invoked with the user information; if it was not initialized, the OnInitializeFailed() is called with an error message.

    public void OnInitialized(UserInfo userInfo){
          Debug.Log("Initialization succeeded");
         // You can call the QueryInventory method here to check whether there are purchases that haven’t been consumed.  
    } 
    public void OnInitializeFailed(string message){
         Debug.Log("Initialization failed: " + message);
    }
    

If you’d like more guidance, check out Initialize the UDP SDK in the Unity documentation for more detailed information. Otherwise, continue to the next section.

Query the purchased IAP items

After the initialization is successful, we need to retrieve the previously purchased non-consumable and unconsumed products when the user launches the game. Call the QueryInventory() method of the UDP SDK to get the product information (product name, ID, description) for non-consumable purchases and consumable purchases that have not yet been consumed. Follow the steps below:

  1. It is necessary for the manager script (player.cs) to inherit the IPurchaseListener interface along with the IInitListener to implement the QueryInventory() method.

    public class player : MonoBehaviour, IInitListener, IPurchaseListener
    
  2. After that, we need to override all the required methods for the IPurchaseListener interface in our class. Although we show only the OnQueryInventory() and OnQueryInventoryFailed() methods here, we gradually complete the others in subsequent sections.

    public void OnQueryInventory(Inventory inventory){
          //Query inventory succeeded
          Debug.Log("Query inventory succeeded");
          IList<ProductInfo> productList = inventory.GetProductList();
          if(productList != null){
              for(int i=0; i<productList.Count;i++){
                   if(productList[i].ProductId=="upgradeplayer1"){
                       playerMaterial = Resources.Load<Material>("UDPMaterial");
                       MeshRenderer meshRenderer = GetComponent<MeshRenderer>();
                       meshRenderer.material = playerMaterial;
                   }
              }
          }
    }
    public void OnQueryInventoryFailed(string message){
          Debug.Log("Query Inventory failed");
    }
    

    As you can see, a few actions have been taken inside the method depending on the product ID. Similarly, you can build some logic here (for example, check for unconsumed products and purchased products that have not been delivered) based on your game design.

  3. Finally, call the QueryInventory() method on a successful initialization inside the OnInitialized() method that was implemented in the previous section.

    public void OnInitialized(UserInfo userInfo){
           Debug.Log("Initialization succeeded");
           // You can call the QueryInventory method here to check if there are purchases that haven’t been consumed.  
           StoreService.QueryInventory(this);
    }  
    

For further information about query inventory in UDP, go here.

Purchase IAP products

In our sample game, there are two UI buttons (see Figure 1), the “Buy Super Jump” and the “Upgrade Player.” These buttons allow users to purchase consumable and non-consumable items respectively inside the game. Please follow the steps below to accomplish these button actions:

  1. Declare two button variables in the beginning of the player class (player.cs).

    public Button buySuperJumpButton;
    public Button upgradePlayerButton;
    
  2. Add two listener methods, OnBuySuperJumpButton and OnUpgradePlayerButton, at the end of the Start() method of the player class (player.cs).

    buySuperJumpButton.onClick.AddListener(OnBuySuperJumpButton);
    upgradePlayerButton.onClick.AddListener(OnUpgradePlayerButton);
    
  3. Implement two listener methods in the same class for the button listeners in the previous section. These enable the “Buy Super Jump” and “Upgrade Player” buttons to initiate purchasing the respective IAP items through invoking the Purchase() method of the UDP SDK. Please note, we have used the item IDs we registered in the “Register IAP items in UDP” section.

    void OnBuySuperJumpButton(){
           //initiate purchasing a super jump item
           StoreService.Purchase("superjump1", "", this);     
    }
    
    void OnUpgradePlayerButton(){
           //initiate purchasing an upgraded player item
           StoreService.Purchase("upgradeplayer1", "", this);
    }
    
  4. The overriding method OnPurchase() is triggered if the purchase is successful. In other cases, the OnPurchaseFailed() method is invoked with an error message. If the item is consumable, consume the product here. Otherwise, deliver the product.

    public void OnPurchase(PurchaseInfo purchaseInfo){
                // The purchase has succeeded.
                // If the purchased product is consumable, you should consume it here.
                // Otherwise, deliver the product.
                if (purchaseInfo.ProductId == "upgradeplayer1"){
                     playerMaterial = Resources.Load<Material>("UDPMaterial");
                     MeshRenderer meshRenderer = GetComponent<MeshRenderer>();
                     meshRenderer.material = playerMaterial;
                }
                else if(purchaseInfo.ProductId == "superjump1"){
                            StoreService.ConsumePurchase(purchaseInfo, this);
                }
    }
    
    public void OnPurchaseFailed(string message, PurchaseInfo purchaseInfo){
                Debug.Log("Purchase Failed: " + message);
    }
    
  5. Save the script and go back to the Unity editor to add references for the UI buttons to the variables of the “player.cs” script that we declared in step 1.

We have completed purchasing IAP items inside our game. However, notice that in step 4, we only delivered the non-consumable item and invoked the ConsumePurchase() method for the consumable item.

Consume IAP products

We need to implement the overriding OnPurchaseConsume() and the OnPurchaseConsumeFailed() methods in the IPurchaseListener interface to consume and deliver the consumable IAP items. See the implementation below:

 public void OnPurchaseConsume(PurchaseInfo purchaseInfo){
            // The consumption succeeded.
            // You should deliver the product here. 
            if (purchaseInfo.ProductId == "superjump1"){
                superJump++;
            }
}

public void OnPurchaseConsumeFailed(string message, PurchaseInfo purchaseInfo){
            // The consumption failed.
}

We have delivered the “Super Jump” item by increasing the counting value. You can implement your game logic here according to your game design. Look here to find out more about consuming IAP products.

Validate in-app purchases

UDP performs client-side validation automatically. When a user purchases an IAP product, Galaxy Store returns the payload and signature. The UDP SDK then validates the signature. If validation fails, the purchase fails accordingly. You can also validate purchases on the server-side. See validating purchases on the server side to implement this functionality.

Build and test your game

Before building your game, add a UDP sandbox tester to verify that your IAP implementation is working. Go to Window -> Unity Distribution Portal -> Settings -> UDP Sandbox Test Accounts -> Add new test account, provide a tester’s email and password, and finally, don’t forget to click Push to save the update to the UDP server.

Now build an APK by going to File -> Build Settings -> Android -> Build and providing all the necessary basic information in Player Settings (File -> Build Settings -> Player Settings). For more information on building for Android, see Building apps for Android. After successfully building the APK, deploy it to the tester’s Galaxy device and assess the IAP functionality. Next, check the test status in the UDP console by going to the Game Info tab and then scrolling down to Sandbox Testing.

Publish your game on the UDP console

Once you have finished building and testing your game, upload the binary to the UDP console (Game Info -> Binary). Finalize all the game information (Game Description, Ads, Premium Price, App Signature) and then release the game by clicking RELEASE before publishing.

Go to the Publish tab on the UDP console, sign in to Galaxy Store with your commercial account, and then publish your game after UDP has successfully repacked it. You can later check the submission status in the Status tab of the UDP console. See details about publishing games on the UDP console here.

Conclusion

This tutorial demonstrates the entire process of publishing a game on Galaxy Store through the UDP console. It also uses the UDP package instead of Samsung IAP for integrating IAP into the game for Galaxy Store. UDP then repacks the game with the Samsung IAP automatically before it is submitted to Galaxy Store. Therefore, we hope this tutorial encourages you to develop games in Unity and publish on Galaxy Store easily through UDP Console.

Additional resources on the Samsung Developers site

This site has many resources for developers looking to build for and integrate with Samsung devices and services. Stay in touch with the latest news by creating a free account or by subscribing to our monthly newsletter. Visit the Marketing Resources page for information on promoting and distributing your apps. Finally, our developer forum is an excellent way to stay up-to-date on all things related to the Galaxy ecosystem.

View the full blog at its source



  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Similar Topics

    • By Samsung Newsroom
      Play Asset Delivery (PAD) enhances the gaming experience by offering the advantages of application bundles, which are packages that group all necessary resources for efficient delivery, making downloads faster and installations smoother for players. Android App Bundles (AAB) are a type of PAD, the modern way of building and publishing Android applications and games in Google Play Store. The Samsung Galaxy Store recently introduced the option to upload AAB files to Galaxy Store Seller Portal. However, AABs have some Google Play Store proprietary features that might make a game non-functional when it is uploaded to Galaxy Store. This article explores ways in which you can utilize PAD while ensuring your game remains compatible with Galaxy Store.
      Purpose
      PAD is a very useful feature that helps reduce the game's initial download size, as it downloads various game assets at runtime. There are multiple ways of using this feature in Unity games. However, certain PAD configurations may cause the game's assets to fail to load when the game is published to Galaxy Store. In this tutorial, you learn how to properly configure PAD and adjust Unity configurations accordingly, so your game can be successfully published to Galaxy Store.
      In the following sections, PAD functionalities are implemented in an existing coin collector game (referenced in the article Integrating Samsung IAP in Your Unity Game), demonstrating how to download and apply a new set of materials for the floor tile at runtime. Here, you also learn about the adjustments that are necessary for successfully publishing a game using PAD to Galaxy Store.
      Prerequisites
      To follow this tutorial, ensure that your setup has the following:
      Unity Game Engine version 2023.2 or above The "Addressables for Android" package for Unity A Google Play developer account A Galaxy Store Seller Portal commercial seller account A game created using Unity where you want to add the PAD features To implement PAD in your Unity game, you can use the "Addressables for Android" package. This is the easiest and most convenient way to implement PAD in a game. This package is only supported on Unity version 2023.2 or above. If your game is built using a previous version of Unity, please migrate your game to the Unity 2023.2 version first.
      PAD implementation considerations
      There are multitude of ways to implement PAD in games built with the Unity engine. However, the most common method for implementing PAD restricts the game to being publishable exclusively on the Google Play Store and does not provide any easy method of disabling PAD for uploading these games into other storefronts. For the best experience with your game, it is recommended to use PAD to bundle all game assets together. This approach ensures that all necessary resources are downloaded right away, preventing any missing assets which could affect the user experience.
      There are three types of asset packs that can be configured while using PAD: "Install Time," "Fast Follow," and "On Demand." Games that use the "Install Time" asset packs can be uploaded to Galaxy Store without any issues as these assets are installed together with the game and do not require any separate downloads. When Galaxy Store generates a universal APK from AAB files, the "Install Time" assets are directly included in the APK.
      Games that are designed to only use "On Demand" or "Fast Follow" asset packs do not allow downloading their assets when they are uploaded to a storefront that is not the Google Play Store. Thus, for any game that uses either the "On Demand" or "Fast Follow" asset pack delivery method, PAD must be disabled in order to upload the game to Galaxy Store.
      To ensure that your game's PAD functionality can be easily switched off and your game is successfully uploaded to Galaxy Store, the "Addressables for Android" package must be used to implement PAD.
      This article assumes that you have implemented PAD in your game using the "Addressables for Android" package and that you have also configured these two assets with the following configurations:
      A "Grass" asset pack set to be downloaded as a "Fast Follow" asset A "Ground" asset pack set to be downloaded as an "On Demand" asset In the next sections, you learn how to integrate PAD into your existing Unity game using the "Addressables for Android" package so that you can easily publish your game to Galaxy Store with minimal changes.
      Basic steps to implement PAD in your Unity game
      In this section, you learn how to configure your assets using PAD functionality that keeps your game compatible with both Google Play and Galaxy Store.
      In Unity, configure "Build Settings" to run the game on Android and generate the AAB: Click File > Build Settings and then select the Android tab. On the "Android" tab, select the Build App Bundle (Google Play) checkbox.



      Figure 1: Enabling the "Build App Bundle" option

      Install the "Addressables for Android" package from the Unity Package Manager. This additionally installs the "Addressables" package as a dependency. Initialize PAD. Go to Window > Asset Management > Addressables and click Init Play Asset Delivery.



      Figure 2: "Init Play Asset Delivery" option

      Configure the "Addressables Groups" for assets: Select Window > Asset Management > Addressables > Groups. Click New > Play Asset Delivery Assets. This creates a new group. Enter a descriptive name. For the purposes of this walkthrough, name one group "Grass" and then create another group and name it "Ground."



      Figure 3: Creating asset groups

      Assign the assets to the Addressables Group: Select the assets you want to assign to an Addressables Group and in the "Inspector" dialog box, tick the Addressable checkbox. The asset is converted into an "Addressable" and assigned to the default Addressables Group.



      Figure 4: Converting assets into Addressables

      Click the folder name in the "Group" field. In the example, the folder name is "Grass."
      Drag and drop the asset from the default group to the group of your choosing. For the purposes of this exercise, assign the grass material related assets to the "Grass" Addressables Group and ground material related assets to the "Ground" Addressables Group.




      Figure 5: Assigning assets to groups

      Configure the "Play Asset Delivery" schema for these addressable groups to add the PAD functionality to your game: Select any of the top-level Asset Group names in the "Addressables Groups" window to open the inspector window for that group. Scroll down in the "Inspector" window until you find the "Play Asset Delivery" schema. From the "Delivery Type" dropdown list, select Install Time, Fast Follow, or On Demand, based on your requirements. There is a demonstration below on how the game might behave on Galaxy Store when you choose the option "On Demand." For more information, see the Testing your PAD Enabled Game on the Play Store and Galaxy Store section.



      Figure 6: Selecting the delivery type for asset groups

      In the "Addressables Groups" dialog box, select Build > New Build > Play Asset Delivery. Now, the game's addressable-asset configuration is complete. Each asset assigned to an addressable group is packed into an asset pack for that group and the asset pack can be downloaded separately using PAD. Note that asset packs can only be downloaded separately from the Play Store if their delivery type is "On Demand" or "Fast Follow."
      Loading and using the addressable assets with AssetReference
      This section provides a script which details how to load the addressable assets that were implemented with PAD in the earlier sections. Your game is set up to load the addressable assets efficiently. If an asset has not been downloaded yet, the game automatically attempts to download it as an "On Demand" asset using PAD before it loads into the game.
      To complete this setup, use the AssetReference type in your game. This feature enables you to manage and edit addressable assets dynamically at runtime, which gives you more flexibility and control over the assets that your game uses.
      To use two game addressable assets in your script, follow these steps:
      Create two AssetReference instances for the floor types (grass and ground) that you added in the previous section. Add the SerializeField attribute to these AssetReference instances. This enables setting up the assets directly from the Unity editor: [SerializeField] AssetReference Grass_mat; [SerializeField] AssetReference Ground_mat; In the Unity editor, drag and drop the grass and ground assets into the fields in the GameObject script section. Now the AssetReferences specifically reference these two assets during runtime.
      Downloading assets during runtime is necessary for PAD. Use AsyncOperations to load these assets:
      Grass_mat.LoadAssetAsync<Material>().Completed += OnGrassAssetLoaded; Ground_mat.LoadAssetAsync<Material>().Completed += OnGroundAssetLoaded; The OnGrassAssetLoaded and OnGroundAssetLoaded handler functions are defined to use the loaded assets. The LoadAssetAsync method passes the asset using an AsyncOperationHandle, and from there you can access the asset itself using the AsyncOperationHandle.Result parameter.
      In this game, we are using PAD to load the grass and ground assets. Once they are successfully loaded, you can change the floor tile material using the following handler functions.
      In this example, after loading the grass and ground assets, you apply the material change to all the floor tiles in the level:
      void OnGroundAssetLoaded(AsyncOperationHandle<Material> handle) { groundMaterial = handle.Result; foreach (GameObject prefab in floorPrefabs) { prefab.GetComponent<MeshRenderer>().material = groundMaterial; } } Save the script and go back to the Unity editor. The new materials are loaded and applied to the floor tiles in the level.

      Testing your PAD-enabled game on the Play Store and Galaxy Store
      The game configuration for using addressable assets and PAD is complete. Before publishing your game, consider whether to use the "Split Application Binary" option.
      On the Android Player settings, expand "Publishing Settings," and scroll down to the "Split Application Binary" checkbox. This checkbox decides how Unity handles packaging when building the game. If this checkbox is checked, Unity splits the base game files from the asset files when building the AAB and enables you to configure each PAD feature in your game. In the images below, you can see what happens when you choose this option. If this option is unchecked, Unity always generates a singular archive file and disables PAD. This is the safest option for uploading your game to Galaxy Store, if your PAD configuration is using options that are not supported by Galaxy Store.



      Figure 7: "Split Application Binary" option

      To enable PAD, check the "Split Application Binary" option Build the game and upload the generated AAB file to both the Play Store and Galaxy Store to check how the game behaves in both stores. If the game assets load correctly in both stores, the PAD configuration was done correctly. Below is an example of what might happen if "On Demand" configuration is used instead.
      When the game is downloaded from the Play Store, Unity automatically downloads the "On Demand" assets. A notification for an "Additional file download" appears during the download process:




      Figure 8: Additional file download notification

      Once the download is complete, the downloaded asset is loaded in your game, replacing the previous assets. In this example game case, the old ground and grass materials are changed to the new textures configured in the previous section.




      Figure 9: Assets updated in the game

      However, when the same game AAB file is uploaded to Galaxy Store and a user downloads it from this store, the PAD assets are not downloaded. Thus, when the game tries to use these assets, they cannot be loaded into the game's memory and glitches might appear.
      While additional error checking can be done to avoid these glitches, the functionalities which require PAD assets still cannot be used. Internally, the game checks the installation source before trying to download the PAD assets and throws an error if the game is not installed from the Play Store.




      Figure 10: Issues might occur if a PAD-enabled game is uploaded to Galaxy Store

      Making the game compatible with Galaxy Store
      To upload your game to Galaxy Store, you can adjust the asset handling to be compatible with Galaxy Store. The best way to do this is by bundling the assets together with the base game, as explained in the previous sections.
      This method is highly recommended. This ensures that the required assets are always available with the game, as well as allowing you to change the assets during runtime, if necessary. Though this can increase the game download size and require you to upload a separate AAB file to Galaxy Store, the process ensures that the assets are always available with the game for full feature parity across all storefronts.
      To make your game build compatible with all storefronts, choose one of the following approaches.
      Option 1: Uncheck the "Split Application Binary" checkbox
      Go to Build Settings > Player Settings > Publishing Settings and uncheck the Split Application Binary checkbox. When you then compile the game, the new AAB file is compatible with Galaxy Store and all the game's functionalities remain intact.




      Figure 11: "Split Application Binary" unchecked option.

      With this option, the assets are packaged together with the game and no separate download is required.
      Option 2: Change delivery type to "Install Time"
      If you want to keep using PAD, you can achieve compatibility by changing all addressable asset groups' delivery type to "Install Time." Keep in mind that when choosing this option, all assets need to be changed to "Install Time" one by one, while the previous one is a one-click process. Unlike "On Demand" and "Fast Follow" asset packs, "Install Time" asset packs are included in the universal APK. Thus, the assets are downloaded together with the game and work as intended without causing errors.
      From the user's perspective, the main difference between "Install Time" and other PAD options is whether the assets are downloaded when the game is installed or later during gameplay. The initial download size is larger when the assets are packaged together with the game, but on the other hand, the user will not need to wait for the assets to download later during gameplay. This enables offline gameplay as well.
      Conclusion
      In this tutorial, you have learned how to configure a Unity game with PAD so that it can easily be published to Galaxy Store without requiring massive changes or breaking any compatibility. For more information, check out the "Addressables for Android" package documentation page Build content for Play Asset Delivery. If you have any feedback or questions, reach out to us in the Samsung Developers Forum.
      View the full blog at its source
    • By Samsung Newsroom
      The Galaxy Store is one of the top app stores to sell your Android games in many different countries. You can also sell various in-app purchase (IAP) items inside your games using the Samsung IAP SDK. As many of you now use the Unity engine to develop your games, Samsung has introduced a Unity plugin for the Samsung IAP SDK that enables you to implement IAP features. Follow the steps outlined in this blog to easily implement the Unity plugin into your project and utilize the Samsung IAP functionalities.
      Prerequisites
      It is assumed you are already familiar with the Samsung IAP procedure. If not, please read the IAP Helper programming guide carefully before proceeding further. After that, download the Samsung IAP Unity plugin package and go through its documentation. To avoid compatibility issues, make sure you meet the system requirements.
      There are three types of IAP items:
      Consumable: can be used only one time and re-purchasable Non-consumable: can be used any number of times and not re-purchasable Subscription: can be used any number of times while it is active For this example, we have developed a basic coin collecting game in Unity for Android and added UI buttons that allow users to buy IAP items (consumable and non-consumable), and a subscription. The “Buy Super Jump” button initiates purchasing a super jump item from the Galaxy Store using the Samsung IAP SDK. Super jump is a consumable item which enables the player to jump higher than normal. Similarly, the “Upgrade Player” button initiates purchasing a player upgrade, which is a non-consumable item. This blog only covers consumable and non-consumable purchases, we’ll discuss subscriptions in a future blog.

      Figure 1: Preview of the sample game developed in Unity.

      Note: You are required to develop your game/application in Unity beforehand to integrate the IAP Unity plugin into it.
      Integrate the Samsung IAP Unity plugin
      After creating the game in Unity, you need to enable Samsung IAP functionalities in your project. Follow the steps below:
      Import the Samsung IAP Unity plugin package into the project. In Unity, click Assets -> Import Package -> Custom Package and select the downloaded plugin package. You can now see the Plugins folder under your Assets folder and the “SamsungIAP.cs” script at Assets/Plugins/Script. Copy or move the “SamsungIAP.cs” script into the default scripts folder (where all the scripts are kept together) of your project so that other scripts can access it easily. If you don’t already have a scripts folder, create a new one and keep all your project scripts together along with “SamsungIAP.cs”. Create an empty game object in the Hierarchy tab and drag-and-drop the “SamsungIAP.cs” script onto it. In our sample project, we have renamed the game object as “SamsungIAP”. Click on the “SamsungIAP” game object and check whether the IAP functionality is enabled in the Inspector, as shown below:
      Figure 2: Samsung IAP is enabled for the project.

      Set the IAP operation mode
      IAP supports three operational modes. The production mode is for enabling billing for item purchases and the other two are for testing IAP functions without billing the game users for item purchases. The default operation mode is set to OPERATION_MODE_TEST with the return value as Success, but you can set the return value to Failure instead, or switch to OPERATION_MODE_PRODUCTION by checking (√) the Production Build checkbox in the Inspector as shown in figure 2. You can learn more about the IAP operation modes and how they work from here.
      Register the game and IAP items in the Seller Portal
      To process/test the Samsung IAP operations, both your game and any IAP items need to be registered in the Seller Portal. Follow the steps below:
      Ensure you have switched the platform of your game to Android and the package name is different from the apps registered in other app stores. You can rename the package name of your project from Player Settings -> Other Settings. Save your Unity project and build the APK file. In Unity, go to File -> Build Settings and then click the Build button. Follow the steps listed in Register an app and in-app items in Seller Portal and complete the registration of your game and IAP items accordingly. For our sample game, we have registered a consumable and a non-consumable item with the IDs “BuySuperJump” and “BuyUpgradedPlayer” respectively. Keep the item IDs in mind as they will be required when initiating the purchases. You can add testers (non-licensed and licensed) in the Binary tab of the Seller Portal while registering your game in the manner covered in the previous step. Licensed testers are not be charged for purchasing any IAP items. You can register the licensed testers in your Seller Portal profile. See IAP Testing for more information. Get previously purchased items
      Make sure to retrieve any previously purchased non-consumable and unconsumed items every time the user starts the game. Use the GetOwnedList() method of the IAP plugin to get information about the items the user has already purchased. However, please note there is a script “player.cs” in our project which is added to the main player game object as a component. From now on we will be editing the codes into this “player.cs” script to enable all the Samsung IAP functions for this project. Follow the steps below:
      Add the following line at the beginning to access the Samsung IAP libraries in this script.using Samsung; Call the GetOwnedList() method whenever the game launches, by adding the following line at the beginning of the Start() method. Learn more about the GetOwnedList() method here. After the processing of the GetOwnedList() method is completed, the OnGetOwnedList callback is triggered, which receives information about the specified purchased items and API call processing. We need to implement this callback method under the same class as in the following;void OnGetOwnedList(OwnedProductList _ownedProductList){ if(_ownedProductList.errorInfo != null){ if(_ownedProductList.errorInfo.errorCode == 0){// 0 means no error if(_ownedProductList.results != null){ foreach(OwnedProductVo item in _ownedProductList.results){ if(item.mConsumableYN == "Y"){ //consume the consumable items and OnConsume callback is triggered afterwards SamsungIAP.Instance.ConsumePurchasedItems(item.mPurchaseId, OnConsume); } if(item.mItemId == "BuySuperJump"){ superJump++; } else if(item.mItemId == "BuyUpgradedPlayer"){ playerMaterial = Resources.Load<Material>("playerMaterial"); MeshRenderer meshRenderer = GetComponent<MeshRenderer>(); meshRenderer.material = playerMaterial; } } } } } } As you can see, some actions have been taken inside the game depending on the respective item IDs. For example, the super jump counter has been increased and the material of the player gets changed. If there is any consumable item which has not been reported as consumed, then the ConsumePurchasedItems() method is invoked. We describe this method in the next section.
      Consume purchased consumable items
      Use the ConsumePurchasedItems() method to report the purchased consumable item as consumed, which enables the item to be purchased again. See Acknowledge a purchased consumable item to understand this process better. When the process of the ConsumePurchasedItems() method in the previous section is finished, the item data and processing results are returned to the OnConsume callback method. We need to implement this method in the same way under the same class as we implemented the OnGetOwnedList method earlier.
      void OnConsume(ConsumedList _consumedList){ if(_consumedList.errorInfo != null){ if(_consumedList.errorInfo.errorCode == 0){ if(_consumedList.results != null){ foreach(ConsumeVo item in _consumedList.results){ if(item.mStatusCode == 0){ //successfully consumed and ready to be purchased again. } } } } } } Get purchasable IAP items
      The users may want to see details of the available IAP items in the store for the game. The GetProductsDetails() method helps to retrieve detailed information (for example, item name, price, ID, etc.) about the IAP items registered in your game that are available for users to purchase. There is a UI button “Available Items” in our sample game for querying the purchasable items. After clicking this button, brief information for each item is presented in a simple dropdown list next to the button (see figure 3). To get the list of available items:
      Declare a button variable and a dropdown variable in the beginning of the “player.cs” script.public Button getProductsButton; public Dropdown itemList; Add a listener method for the “Available Items” button at the end of the Start() method.getProductsButton.onClick.AddListener(OnGetProductsButton); To initiate the GetProductsDetails() method, we need to implement the listener OnGetProductsButton() method.void OnGetProductsButton(){ //get all the product details SamsungIAP.Instance.GetProductsDetails("", OnGetProductsDetails); } After the processing is completed on the server side, the OnGetProductsDetails callback is triggered, which contains information about the available IAP items. Implement this callback method and add information of each item to the dropdown method so that the users can see them easily. In the example, we show only the item name and price.void OnGetProductsDetails(ProductInfoList _productList){ if (_productList.errorInfo != null){ if (_productList.errorInfo.errorCode == 0){// 0 means no error if (_productList.results != null){ itemList.ClearOptions(); List<string> optionItems = new List<string>(); int i = 1; foreach (ProductVo item in _productList.results){ string temp = i+ ". " + item.mItemName + ": $ " + item.mItemPrice; optionItems.Add(temp); i++; } itemList.AddOptions(optionItems); } } } }
      Figure 3: Showing the available IAP items in the game.

      The information of all IAP items is shown in the dropdown menu as a list. You can show only one specific item or more items by specifying their IDs in the GetProductsDetails() method if you want. Learn more about the method here.
      View the full blog at its source
    • By Samsung Newsroom
      View the full blog at its source
    • By Samsung Newsroom
      View the full blog at its source





×
×
  • Create New...