Search Unity

IAP button: get title frmo IAP into Textmeshpro?

Discussion in 'Unity IAP' started by John1515, Jun 30, 2018.

  1. John1515

    John1515

    Joined:
    Nov 29, 2012
    Posts:
    248
    Hi

    I'm using the out of the box IAP button, which allows to set text of a text component in the inspector.
    But what would be the best way to get an IAP title into a textmeshpro UI text, without "hacking" the IAP button (too much)?
     
  2. unityjingyao

    unityjingyao

    Unity Technologies

    Joined:
    Feb 20, 2017
    Posts:
    220
    Hi,

    You can drag the UI text GameObject to the "Title Text" of IAPButton.
    IAPButton will update it after initialization.

    Or using CodelessIAPStoreListener.Instance.GetProduct(productId) to get a specific Product, then using Product.metadata.localizedTitle to get the IAP title.
     
  3. blanktarget

    blanktarget

    Joined:
    Aug 28, 2017
    Posts:
    20
    I know this is a little old now but if anyone is looking still:
    You can just edit the IAPButton.cs file and change
    public Text titleText;
    to
    public TextMeshProUGUI titleText;

    make sure to add using TMPro; to the top as well and you can have it point text mesh files.
     
  4. mylastggColto

    mylastggColto

    Joined:
    Feb 28, 2017
    Posts:
    28
    This works, but wouldn't this break when the codelessIAP package gets updated and overwrites the changes?
     
  5. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    That is correct, you would need to apply the change again manually, so ensure to make a back up!
     
  6. iboshido

    iboshido

    Joined:
    Mar 4, 2017
    Posts:
    33

    thank you so much dude
     
  7. thekid579

    thekid579

    Joined:
    Feb 7, 2019
    Posts:
    4
    Old thread, but here's a quick script to simply take the info from the IAPButton and slap it on a text mesh pro. I was running into some issues where the IAPButton script kept reverting my changes.

    Code (CSharp):
    1. using TMPro;
    2. using UnityEngine;
    3. using UnityEngine.Purchasing;
    4.  
    5. [RequireComponent(typeof(IAPButton))]
    6. public class IAPButtonDescriptionController : MonoBehaviour
    7. {
    8.     [SerializeField] private TextMeshProUGUI priceText;
    9.     [SerializeField] private TextMeshProUGUI titleText;
    10.     [SerializeField] private TextMeshProUGUI descriptionText;
    11.  
    12.     private IAPButton attachedButton;
    13.  
    14.     private void Awake()
    15.     {
    16.         attachedButton = GetComponent<IAPButton>();
    17.         Initialize();
    18.     }
    19.  
    20.     private void Initialize()
    21.     {
    22.         var product = CodelessIAPStoreListener.Instance.GetProduct(attachedButton.productId);
    23.  
    24.         if (priceText != null)
    25.             priceText.SetText(product.metadata.localizedPriceString);
    26.  
    27.         if (titleText != null)
    28.             titleText.SetText(product.metadata.localizedTitle);
    29.  
    30.         if (descriptionText != null)
    31.             descriptionText.SetText(product.metadata.localizedDescription);
    32.     }
    33. }
     
    jam3shug likes this.
  8. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    So you know, Codeless has some issues that we are looking to address, hopefully by Q2 of this year (due to resource constraints). You would want to avoid Codeless for now. It is missing receipt validation, for example. Also, many users have claimed that all purchases are refunded after 3 days. Instead, you would be advised to use Scripted IAP as demonstrated in the Sample IAP Project below, and in the great Samples shipped in Package Manager for In App Purchasing https://forum.unity.com/threads/sample-iap-project.529555/#post-6950270
     
  9. SkylorBeck

    SkylorBeck

    Joined:
    Aug 29, 2020
    Posts:
    13
    Hi, sorry to Necro this but is this still the case? Why is codeless even in the package if it's so terrible?
     
  10. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    For users that may have used it in the past and need to upgrade, and then switch to Scripted IAP.
     
  11. SkylorBeck

    SkylorBeck

    Joined:
    Aug 29, 2020
    Posts:
    13
    There should be some sort of warning that it's depreciated then. I spent several hours setting it up yesterday only to find this post at the end of it all and now I have to redo it all anyway. Talk about frustrating.
     
    amazingamazing likes this.
  12. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Understood, I will bring this up to the team. The good news is that you have the scripted code already written for you with the Sample project.