KaiClavier

STMArabicSupport.cs

Mar 25th, 2020
470
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Copyright (c) 2016-2020 Kai Clavier [kaiclavier.com] Do Not Distribute
  2. //Made to work with Arabic Letters Support for Unity by Abdullah Konash [https://github.com/Konash/arabic-support-unity]
  3. using UnityEngine;
  4. using System.Collections;
  5. using ArabicSupport;
  6. using System.Text; //for stringbuilder
  7.  
  8. /*
  9. Tag order code still isn't ideal... but it's a working solution for now!
  10. In the future I'd like to get the tags respecting RTL rules, too.
  11. */
  12.  
  13. [ExecuteInEditMode]
  14. [RequireComponent(typeof(SuperTextMesh))]
  15. public class STMArabicSupport : MonoBehaviour
  16. {
  17.  
  18.     public SuperTextMesh superTextMesh;
  19.     [Tooltip("Make sure this value matches the way your text was typed up!! Otherwise it will cause an error.")]
  20.     public bool rtl = true;
  21.     [Tooltip("Sending other-language strings through the fixer can cause issues, so this is here so things can be quickly disabled in localized games.")]
  22.     public bool isEnabled = true;
  23.     public static bool disableAll = false;
  24.  
  25.     void Reset()
  26.     {
  27.         superTextMesh = GetComponent<SuperTextMesh>();
  28.     }
  29.  
  30.     void OnEnable()
  31.     {
  32.         superTextMesh.OnPreParse += FixText;
  33.         //Debug.Log("subscribing");
  34.     }
  35.     void OnDisable()
  36.     {
  37.         superTextMesh.OnPreParse -= FixText;
  38.         //Debug.Log("Unsubscribing");
  39.     }
  40.     void FixText(STMTextContainer container)
  41.     {
  42.         if(isEnabled && !disableAll)
  43.         {
  44.             //fix the string within the container
  45.             //container.text = ArabicFixer.Fix(container.text, rtl);
  46.             string fixedString = ArabicFixer.Fix(container.text, rtl);
  47.             if(rtl)
  48.             {
  49.                 fixedString = fixedString.Replace('<', ''); //null for now
  50.                 fixedString = fixedString.Replace('>', '<');
  51.                 fixedString = fixedString.Replace('', '>');
  52.             }
  53.             container.text = fixedString;
  54.         }
  55.     }
  56. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×