Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Help using plugin

Discussion in 'Scripting' started by newcoder17, Mar 18, 2018.

  1. newcoder17

    newcoder17

    Joined:
    Dec 9, 2017
    Posts:
    103
    I've purchased the following plugin so I can check licencing status.
    But as a noob I dont really know how I should be using it.
    I realise I should contact the dev, but that will take a couple of days, and I'm hoping its fairly simple.

    https://unionassets.com/android-native-plugin/app-licensing-261

    The code I'm trying to use is as follows. It will just change the color of some text randomly, but on the 6th press of the button I want to throw an error if the app is not licenced.

    I've added the key for my test app from google play.

    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.UI;
    6.  
    7. public class changeColor : MonoBehaviour {
    8.     public Text myText;
    9.     int clickCount = 1;
    10.     // Use this for initialization
    11.  
    12.  
    13.     public enum AN_LicenseStatusCode {
    14.         RESULT_ALLOW,
    15.         RESULT_DONTALLOW,
    16.         RESULT_ERROR,
    17.     }
    18.  
    19.     public enum AN_LicenseErrorCode {
    20.         ERROR_NONE,
    21.         ERROR_RETRY,
    22.         ERROR_CHECK_IN_PROGRESS,
    23.         ERROR_INVALID_PACKAGE_NAME,
    24.         ERROR_INVALID_PUBLIC_KEY,
    25.         ERROR_MISSING_PERMISSION,
    26.         ERROR_NON_MATCHING_UID,
    27.         ERROR_NOT_MARKET_MANAGED,
    28.         ERROR_UNKNOWN
    29.     }
    30.  
    31.     void Start () {
    32.         myText.text = "COLOUR " + clickCount;
    33.         CheckAppLicense ();
    34.  
    35.     }
    36.  
    37.     // Update is called once per frame
    38.     void Update () {
    39.         }
    40.  
    41.     public void dochangeColor(){
    42.         clickCount = clickCount + 1;
    43.         if (clickCount >= 6) {
    44.            
    45.             LicenseRequestResult (result);
    46.         }
    47.  
    48.  
    49.         //Color newColor = new Color(Random.Range(0.0,1.0),Random.Range(0.0,1.0),Random.Range(0.0,1.0),1.0f);
    50.         //this.GetComponent<Renderer>().material.color = Random.ColorHSV(0f,1f,1f,1f,0.5f,1f);
    51.         myText.color=Random.ColorHSV(0f,1f,1f,1f,0.5f,1f);
    52.         myText.text = "COLOUR " + clickCount;
    53.     }
    54.  
    55.     public void quitGame(){
    56.         Application.Quit ();
    57.     }
    58.  
    59.     public void CheckAppLicense() {
    60.  
    61.         AN_LicenseManager.OnLicenseRequestResult += LicenseRequestResult;
    62.         AN_LicenseManager.Instance.StartLicenseRequest (AndroidNativeSettings.Instance.base64EncodedPublicKey);
    63.         //SA_StatusBar.text =  "Get App License Request STARTED";
    64.         Debug.Log ("Licence request started");
    65.     }
    66.  
    67.  
    68.     private void LicenseRequestResult(AN_LicenseRequestResult result) {
    69.         //SA_StatusBar.text =  "App License Status: " + result.ToString();
    70.         Debug.Log("License Check Result: " + "Status: " +  result.Status.ToString() + " \nError: " +  result.Error.ToString());
    71.         //AndroidMessage.Create("License Check Result: ", "Status: " +  result.Status.ToString() + " \nError: " +  result.Error.ToString());
    72.  
    73.     }
    74.  
    75. }
    76.  
    77.  
    The main issue appears to be the calling of LicenceRequestResult. Depending on what syntax I'm using I'm getting varying errors around types being used as variables etc etc.

    Could somebody please help me out? As I say I'm sure its something very simple.

    Thanks in advance.
     
  2. newcoder17

    newcoder17

    Joined:
    Dec 9, 2017
    Posts:
    103
    Anyone? I've tried contacting the developer, but I'm just waiting on a response now.
    I'm guessing this is fairly standard stuff. Although I can start the licence request off, and I can see the class open up in the inspector on doing so, I cant work out how to get the result from it.

    The instructions I linked to above say

    To check App License Status for your App subscribe to

    AN_LicenseManager.OnLicenseRequestResult += LicenseRequestResult;
    AN_LicenseManager.Instance.StartLicenseRequest();
    //or
    AN_LicenseManager.Instance.StartLicenseRequest(AndroidNativeSettings.Instance.base64EncodedPublicKey);

    What does "Subscribe to" mean in this case?
    https://unionassets.com/android-native-plugin/app-licensing-261

    Could anyone help with interpreting what I need to from the instructions?
    Thanks.
     
  3. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
  4. ThrillKill

    ThrillKill

    Joined:
    Apr 7, 2014
    Posts:
    80
    You subscribe to events to listen for when they are called.

    Based on: https://unionassets.com/android-native-plugin/app-licensing-261

    You put it in your Start/Awake/OnEnable functions depending on use case.

    However you have the listening function to be called with parameters? Your trying to overload it without a function for the overload.

    I would setup like this:

    Example:
    Code (csharp):
    1.  
    2.  
    3. void Start() {
    4. AN_LicenseManager.OnLicenseRequestResult += LicenseRequestResult;
    5. AN_LicenseManager.Instance.StartLicenseRequest(AndroidNativeSettings.Instance.base64EncodedPublicKey);
    6. }
    7.  
    8. void LicenseRequestResult() {
    9.  
    10.  //WHEN EVENT IS FIRED => DO STUFF
    11. AndroidMessage.Create("License Check Result: ", "AN_LicenseRequestResult: " +  result.ToString());
    12. }
    13.  
    14.  
    From what I can tell your right, your main issue is:
    Code (csharp):
    1.  
    2. private void LicenseRequestResult(AN_LicenseRequestResult result)
    3.  
    => because when the event fires unless it's providing parameters which I do not see it doing that, will throw errors of course.

    You should have a separate function then the Event Function.
     
  5. newcoder17

    newcoder17

    Joined:
    Dec 9, 2017
    Posts:
    103
    Big Thank You all.
    My biggest mistake was thinking I needed to actually make the call, rather than I was already listening for it.
    I also stupidly hadn't actually copied it to an android device, as I was under the impression it could be tested in the Unity interface (it seems it cant)

    I'm now trying to test for real by deploying as an alpha resource through the store, but because I'm now doing checking against the registered user I now need to host a privacy policy!

    Argghh!

    Anyway, at least I got it doing something, even if it currently gives a positive result each time.

    Thanks Again.
     
    ThrillKill likes this.