示例#1
0
 public static void SetI18NKey(this UITextmesh self, string key, params object[] paras)
 {
     if (string.IsNullOrEmpty(key))
     {
         self.SetText("");
         return;
     }
     self.__DisableI18Component();
     self.__text_key = key;
     self.SetI18NText(paras);
 }
示例#2
0
 //当手动修改text的时候,需要将mono的i18textcomponent给禁用掉
 static void __DisableI18Component(this UITextmesh self, bool enable = false)
 {
     self.ActivatingComponent();
     if (self.unity_i18ncomp_touched != null)
     {
         self.unity_i18ncomp_touched.enabled = enable;
         if (!enable)
         {
             Log.Warning($"组件{self.GetGameObject().name}, text在逻辑层进行了修改,所以应该去掉去预设里面的I18N组件,否则会被覆盖");
         }
     }
 }
示例#3
0
        public static Vector3 GetLastCharacterLocalPosition(this UITextmesh self)
        {
            self.ActivatingComponent();
            if (self.unity_uitextmesh.m_textInfo.characterInfo != null && self.unity_uitextmesh.m_textInfo.characterInfo.Length > 0)
            {
                var info = self.unity_uitextmesh.m_textInfo.characterInfo[self.unity_uitextmesh.m_textInfo.characterCount - 1];
                return(info.vertex_BR.position);
            }
            var rect = self.unity_uitextmesh.rectTransform.rect;

            return(new Vector3(-rect.width / 2, -rect.height / 2, 0));
        }
示例#4
0
 public static void OnLanguageChange(this UITextmesh self)
 {
     self.ActivatingComponent();
     if (self.__text_key != null)
     {
         if (I18NComponent.Instance.I18NTryGetText(self.__text_key, out var text) && self.keyParams != null)
         {
             text = string.Format(text, self.keyParams);
         }
         self.unity_uitextmesh.text = text;
     }
 }
示例#5
0
 static void ActivatingComponent(this UITextmesh self)
 {
     if (self.unity_uitextmesh == null)
     {
         self.unity_uitextmesh = self.GetGameObject().GetComponent <TMPro.TMP_Text>();
         if (self.unity_uitextmesh == null)
         {
             self.unity_uitextmesh = self.GetGameObject().AddComponent <TMPro.TMP_Text>();
             Log.Info($"添加UI侧组件UITextmesh时,物体{self.GetGameObject().name}上没有找到TMPro.TMP_Text组件");
         }
         self.unity_i18ncomp_touched = self.GetGameObject().GetComponent <I18NText>();
     }
 }
示例#6
0
 public static void SetTextWithColor(this UITextmesh self, string text, string colorstr)
 {
     if (string.IsNullOrEmpty(colorstr))
     {
         self.SetText(text);
     }
     else
     {
         if (!colorstr.StartsWith("#"))
         {
             colorstr = "#" + colorstr;
         }
         self.SetText($"<color={colorstr}>{text}</color>");
     }
 }
示例#7
0
 public static void SetColor(this UITextmesh self, string colorStr)
 {
     if (!colorStr.StartsWith("#"))
     {
         colorStr = "#" + colorStr;
     }
     if (ColorUtility.TryParseHtmlString(colorStr, out var color))
     {
         self.ActivatingComponent();
         self.unity_uitextmesh.color = color;
     }
     else
     {
         Log.Info(colorStr);
     }
 }
示例#8
0
 public static void SetI18NText(this UITextmesh self, params object[] paras)
 {
     if (string.IsNullOrEmpty(self.__text_key))
     {
         Log.Error("there is not key ");
     }
     else
     {
         self.__DisableI18Component();
         self.keyParams = paras;
         if (I18NComponent.Instance.I18NTryGetText(self.__text_key, out var text) && paras != null)
         {
             text = string.Format(text, paras);
         }
         self.unity_uitextmesh.text = text;
     }
 }
示例#9
0
 public static void SetText(this UITextmesh self, string text)
 {
     self.__DisableI18Component();
     self.__text_key            = null;
     self.unity_uitextmesh.text = text;
 }
示例#10
0
 public static string GetText(this UITextmesh self)
 {
     self.ActivatingComponent();
     return(self.unity_uitextmesh.text);
 }
示例#11
0
 public static void SetMaxVisibleCharacters(this UITextmesh self, int count)
 {
     self.ActivatingComponent();
     self.unity_uitextmesh.maxVisibleCharacters = count;
 }
示例#12
0
 public static int GetCharacterCount(this UITextmesh self)
 {
     self.ActivatingComponent();
     return(self.unity_uitextmesh.CharacterCount);
 }
示例#13
0
 public static void SetTextColor(this UITextmesh self, Color color)
 {
     self.ActivatingComponent();
     self.unity_uitextmesh.color = color;
 }