KaiClavier

STMArabicSupport.cs (OUTDATED, use STMRTLSupport Instead!)

Jul 5th, 2021 (edited)
1,278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.96 KB | None | 0 0
  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. This will alo fix ordering for other RTL languages! I need to rename this script...
  10.  
  11. Tag order code still isn't ideal... but it's a working solution for now!
  12. In the future I'd like to get the tags respecting RTL rules, too.
  13. */
  14.  
  15. [ExecuteInEditMode]
  16. [RequireComponent(typeof(SuperTextMesh))]
  17. public class STMArabicSupport : MonoBehaviour
  18. {
  19.  
  20.    
  21.     public SuperTextMesh superTextMesh;
  22.     [Tooltip("Sending other-language strings through the fixer can cause issues, so this is here so things can be quickly disabled in localized games.")]
  23.     public bool isEnabled = true;
  24.     //[Tooltip("Make sure this value matches the way your text was typed up!! Otherwise it will cause an error.")]
  25.     public bool rtlTags = true;
  26.     public bool showTashkeel = false;
  27.     public bool combineTashkeel = false;
  28.     public bool useHinduNumbers = false;
  29.    
  30.     public static bool disableAll = false;
  31.  
  32.    
  33.  
  34.     void Reset()
  35.     {
  36.         superTextMesh = GetComponent<SuperTextMesh>();
  37.     }
  38.  
  39.     void OnEnable()
  40.     {
  41.         superTextMesh.OnPreParse += FixText;
  42.         //Debug.Log("subscribing");
  43.     }
  44.     void OnDisable()
  45.     {
  46.         superTextMesh.OnPreParse -= FixText;
  47.         //Debug.Log("Unsubscribing");
  48.     }
  49.     void FixText(STMTextContainer container)
  50.     {
  51.         if(isEnabled && !disableAll)
  52.         {
  53.             //fix the string within the container
  54.             //container.text = ArabicFixer.Fix(container.text, rtl);
  55.             string fixedString = ArabicFixer.Fix(container.text, showTashkeel, combineTashkeel, useHinduNumbers);
  56.             if(rtlTags)
  57.             {
  58.                 fixedString = fixedString.Replace('<', 'ξ€€'); //null for now
  59.                 fixedString = fixedString.Replace('>', '<');
  60.                 fixedString = fixedString.Replace('ξ€€', '>');
  61.             }
  62.             container.text = fixedString;
  63.         }
  64.     }
  65. }
  66.  
Add Comment
Please, Sign In to add comment