Search Unity

trying to use Windows.Services.Store namespace?

Discussion in 'Windows' started by kinguhdahood5, Mar 25, 2020.

  1. kinguhdahood5

    kinguhdahood5

    Joined:
    Dec 18, 2018
    Posts:
    84
    So, I'm trying to get a product key, or a receipt, from the Microsoft store, and in the documentation I've been looking at, I need to use this Windows.Services.Store namespace but It doesn't read the namespace, inside Unity anyway. Do I need to download anything to use their store services? Or do I need to implement this somewhere outside Unity in a VS solution?

    The way I want to set it up, I have a game pass that's ready in the Microsoft store, holding on publishing until I can figure this out, and I want to pull the details of the IAP, receipt or product key, so I can essentially unlock the full game. But documentation is pretty scarce when it comes to Unity + Microsoft so I'm lost. Honestly, I don't quite know if I'm supposed to post this thread on this forum type. But any help would be much appreciated, thank you.

    Edit: My platform target is UWP, right now for xbox and PC, forgot to add that.
     
    Last edited: Mar 25, 2020
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    You should be able to use that API if you wrap your code in #if ENABLE_WINMD_SUPPORT && UNITY_WSA/#endif block.
     
  3. kinguhdahood5

    kinguhdahood5

    Joined:
    Dec 18, 2018
    Posts:
    84
    Awesome, thank you! I haven't used that type of code before, could you show me some documentation on it please? Btw, does this work with IL2CPP as a scripting backend?
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
  5. kinguhdahood5

    kinguhdahood5

    Joined:
    Dec 18, 2018
    Posts:
    84
    Thanks for the info, but I'm having trouble implementing the last section of code. I could be missing something:
    Code (csharp):
    1.  
    2. private void Start()
    3.     {
    4.         #if ENABLE_WINMD_SUPPORT
    5.             Debug.Log("Windows is functional!");
    6.         #endif
    7.     }
    8.  
    Inside the #define directive, I think it's called, it's not letting me use that debug.log, it's commented out. My configuration seems to be setup properly, unless I'm just not using the code the right way. my API compat is at .NET 4.x, tried with .NET 2.0 as well, backend IL2CPP, and runtime .NET 3.5 equivalent. Could it be that I'm missing an extension on visual studios side of things?
     
  6. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    Can you show a screenshot?
     
  7. kinguhdahood5

    kinguhdahood5

    Joined:
    Dec 18, 2018
    Posts:
    84
    2020-03-24 (1).png 2020-03-24 (2).png

    I took a couple, one of the code I'm just trying to test and the other of the setting configs. I'm not sure what exactly to show as well, I'm still kinda new to plugins and what-not
     
  8. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    For some reason this project isn't loaded:

    upload_2020-3-24_20-42-45.png

    Can you try right clicking it and trying to reload it? Once you reload it, you should be able to switch to it here:

    upload_2020-3-24_20-43-31.png
     
    kinguhdahood5 likes this.
  9. kinguhdahood5

    kinguhdahood5

    Joined:
    Dec 18, 2018
    Posts:
    84
    Oh wow, haha thank you. That's weird, I haven't actually used the csharp.player before. Thank you for working with me on this, looks like I can get all the namespaces I've been trying to access. Just for peace of mind, would this be the way to implement the namespaces, without the directive I get an error:

    Code (csharp):
    1.  
    2. #if ENABLE_WINMD_SUPPORT
    3. using Windows.Services.Store;
    4. #endif
    5.  
     
  10. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    Yup, that's exactly what you need to do.
     
  11. kinguhdahood5

    kinguhdahood5

    Joined:
    Dec 18, 2018
    Posts:
    84
    Awesome, thank you, this helped out a lot
     
  12. BottleTopStudios

    BottleTopStudios

    Joined:
    Feb 24, 2015
    Posts:
    2
  13. kinguhdahood5

    kinguhdahood5

    Joined:
    Dec 18, 2018
    Posts:
    84
    So, I'm still working on this myself, a lot of it is just trouble shooting things to see what works and what doesn't. Here's a piece of code I'm using to try and figure it out, I'll break down what works:
    Code (csharp):
    1.  
    2. using System;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.UI;
    6. #if ENABLE_WINMD_SUPPORT
    7. using Windows.Services.Store;
    8. #endif
    9. public class getStoreProducts : MonoBehaviour
    10. {
    11.     public Text passCheck;
    12.     public Text addonLicense;
    13.     private void Start()
    14.     {
    15. #if ENABLE_WINMD_SUPPORT
    16.         GetLicenseInfo();
    17.         //StartCoroutine(getInfo());
    18.         return;
    19. #endif
    20.         passCheck.text = "windows isn't available";
    21.     }
    22.     private void getInfo()
    23.     {
    24.         if (licenseDets == null)
    25.         {
    26.             passCheck.text = "no info was loaded";
    27.         }
    28.         else
    29.         {
    30.             string n = "License Info";
    31.             foreach(string b in licenseDets)
    32.             {
    33.                 n = n + " : " + b;
    34.             }
    35.             addonLicense.text = n;
    36.         }
    37.     }
    38.     private List<string> licenseDets;
    39. #if ENABLE_WINMD_SUPPORT
    40.     private StoreContext context = null;
    41.     public async void GetLicenseInfo()
    42.     {
    43.         licenseDets = new List<string>();
    44.         passCheck.text = "this function is running";
    45.         if (context == null)
    46.         {
    47.             context = StoreContext.GetDefault();
    48.         }
    49.         passCheck.text = "step 1 done";
    50.         StoreAppLicense appLicense = await context.GetAppLicenseAsync();
    51.         licenseDets.Add(appLicense.ToString());
    52.         licenseDets.Add(appLicense.AddOnLicenses.ToString());
    53.         passCheck.text = "step 2 done";
    54.         if (appLicense == null)
    55.         {
    56.             passCheck.text = "An error occurred while retrieving the license.";
    57.             return;
    58.         }
    59.         getInfo();
    60.     }
    61. #endif
    62. }
    63.  
    Now, this isn't necessarily complete or the proper way to do it, but I'm just testing what I pull through the store context for now. But, anyway, If you take a look at this piece of code, you'll see how the windows define tags are used. If you don't know already, windows support doesn't work inside the editor, so to view all your windows defined code, you'll have to build a solution and run it for windows to be accessible. I'm new to IAP as well so I'm not really well-informed, I just know what seems to be working.

    And, to your other question, as long as your publishing to UWP, or xbox I'd assume as well, you shouldn't have to add anything else to use windows coding.
     
  14. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Last edited: Apr 8, 2020
  15. kinguhdahood5

    kinguhdahood5

    Joined:
    Dec 18, 2018
    Posts:
    84
    Thanks, I always have trouble finding that page, but I have trouble using the istorelistener in that example. It requires me to use certain functions but I don't know how to implement the process purchasing function:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.Purchasing;
    4. public class storeProducts_withIStore : MonoBehaviour, IStoreListener
    5. {
    6.  
    7.     void IStoreListener.OnInitialized(IStoreController controller, IExtensionProvider extensions)
    8.     {
    9.     }
    10.     void IStoreListener.OnInitializeFailed(InitializationFailureReason error)
    11.     {
    12.     }
    13.     void IStoreListener.OnPurchaseFailed(Product i, PurchaseFailureReason p)
    14.     {
    15.     }
    16.     void IStoreListener.ProcessPurchase(PurchaseEventArgs e)
    17.     {
    18.         // this is the function call I'm having trouble with.
    19.     }
    20. }
    21.  
    Unless it's not supposed to be declared as a function, in which case I don't know what I should do with it. I've tried using it the way in the scripting api example but it still gives me an error. Could you give me an example on how I should use process purchasing please?
     
  16. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
  17. kinguhdahood5

    kinguhdahood5

    Joined:
    Dec 18, 2018
    Posts:
    84
    Awesome, that helps out a lot, thank you!
     
  18. kinguhdahood5

    kinguhdahood5

    Joined:
    Dec 18, 2018
    Posts:
    84
  19. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Only subscription products are not supported. Consumables and non-consumables would be expected to work. What product(s) are you offering?
     
  20. kinguhdahood5

    kinguhdahood5

    Joined:
    Dec 18, 2018
    Posts:
    84
    Alright cool, I was gonna do a game pass, like if you want the full game you can buy the pass to buy the game, which would be non consumable so that'll work
     
    JeffDUnity3D likes this.