Souliloquy

Unity IAP price label cleanup

Mar 9th, 2020
1,127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. using System.Linq;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4.  
  5. namespace IAP
  6. {
  7.     public class PriceText : MonoBehaviour
  8.     {
  9.         public Text price = null;
  10.  
  11.         void Start()
  12.         {
  13.             if (price == null)
  14.                 price = GetComponent<Text>();
  15.             if (price == null)
  16.             {
  17.                 Debug.LogError("PriceText didn't find the text!");
  18.                 enabled = false;
  19.             }
  20.         }
  21.  
  22.         void Update()
  23.         {
  24.             FixPrice();
  25.         }
  26.  
  27.         void FixPrice()
  28.         {
  29.             // Remove LRM RLM and controls such as new lines etc
  30.             price.text = new string(price.text.Where(c => !(char.IsControl(c) || c == '\u200F' || c == '\u200E')).ToArray());
  31.         }
  32.  
  33.         [ContextMenu("Test LRM RLM removal")]
  34.         void Test()
  35.         {
  36.             price = GetComponent<Text>();
  37.             price.text = '\u200F'.ToString() + "2.00$" + '\u200E'.ToString();
  38.             FixPrice();
  39.             Debug.Log(price.text);
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment