You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

60 lines
1.3 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UPersian.Utils;
  6. namespace UPersian.Components
  7. {
  8. [AddComponentMenu("UI/RtlText")]
  9. public class RtlText : Text
  10. {
  11. public string BaseText
  12. {
  13. get
  14. {
  15. return base.text;
  16. }
  17. }
  18. public override string text
  19. {
  20. get
  21. {
  22. string text = base.text;
  23. base.cachedTextGenerator.Populate(text, base.GetGenerationSettings(base.rectTransform.rect.size));
  24. List<UILineInfo> list = base.cachedTextGenerator.lines as List<UILineInfo>;
  25. if (list == null)
  26. {
  27. return null;
  28. }
  29. string text2 = string.Empty;
  30. for (int i = 0; i < list.Count; i++)
  31. {
  32. if (i < list.Count - 1)
  33. {
  34. int startCharIdx = list[i].startCharIdx;
  35. int length = list[i + 1].startCharIdx - list[i].startCharIdx;
  36. text2 += text.Substring(startCharIdx, length);
  37. if (text2.Length > 0 && text2[text2.Length - 1] != '\n' && text2[text2.Length - 1] != '\r')
  38. {
  39. text2 += this.LineEnding;
  40. }
  41. }
  42. else
  43. {
  44. text2 += text.Substring(list[i].startCharIdx);
  45. }
  46. }
  47. return text2.RtlFix();
  48. }
  49. set
  50. {
  51. base.text = value;
  52. }
  53. }
  54. protected char LineEnding = '\n';
  55. }
  56. }