计算字体宽度及Text组件的自适应怎么设置

发布时间:2022-01-07 15:21:57 作者:iii
来源:亿速云 阅读:119

今天小编给大家分享一下计算字体宽度及Text组件的自适应怎么设置的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ChatView : MonoBehaviour
{

#region RectTransformprivate RectTransform ChatContent;#endregion#region GameObjectprivate GameObject LeftChatObj;private GameObject RightChatObj;#endregionprivate void Awake(){ InitGetComponent();}private void Start(){ Test();}private void InitGetComponent(){ #region RectTransform ChatContent = transform.Find("ChatPanel/ScrollView/Viewport/ChatContent").GetComponent<RectTransform>(); #endregion #region GameObject LeftChatObj = Resources.Load<GameObject>("Info/LeftChatInfo"); RightChatObj = Resources.Load<GameObject>("Info/RightChatInfo"); #endregion}//测试方法private void Test(){ ChatInfo info1 = Instantiate(LeftChatObj, ChatContent).GetComponent<ChatInfo>(); ChatInfo info2 = Instantiate(RightChatObj, ChatContent).GetComponent<ChatInfo>(); // info1.SetChatText("椅子在异乡,树叶有翅膀,椅子在异乡,树叶有翅膀,椅子在异乡,树叶有翅膀"); info2.SetChatText("斯人如彩虹,遇上方知有,斯人如彩虹,遇上方知有,斯人如彩虹,遇上方知有,斯人如彩虹,遇上方知有,斯人如彩虹,遇上方知有"); UpdateLayout();}private void UpdateLayout(){ UITools.Instance.UpdateLayout(ChatContent);}

}

public class ChatInfo : MonoBehaviour
{

#region RectTransformprivate RectTransform RtChatContentText;private RectTransform RtBgEmpty;private RectTransform RtContentEmpty;private RectTransform RtSelf;#endregion#region Textprivate Text ChatContentText;#endregion#region float//字体总宽高private float m_FontTotalWidth = 0f;private float m_FontTotalHeight = 0f;//Text文本的宽高private float m_TextWidth = 0f;private float m_TextHeight = 0f;//Text背景图宽高private float m_TextBgWidth = 0f;private float m_TextBgHeight = 0f;#endregionprivate void Awake(){ InitGetComponent();}private void Start(){ //SetChatText("椅子在异乡,树叶有翅膀。椅子在异乡,树叶有翅膀。椅子在异乡,树叶有翅膀。椅子在异乡,树叶有翅膀。椅子在异乡,树叶有翅膀。"); //SetChatText("椅子在异乡,树叶有翅膀。");}private void InitGetComponent(){ #region RectTransform RtChatContentText = transform.Find("ContentEmpty/BgEmpty/ChatContentText").GetComponent<RectTransform>(); RtBgEmpty = transform.Find("ContentEmpty/.........

以上就是“计算字体宽度及Text组件的自适应怎么设置”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注亿速云行业资讯频道。

推荐阅读:
  1. Android中怎么实现组件宽度高度自适应
  2. GridView根据字段自适应宽度

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

text

上一篇:微服务划分的方法是什么

下一篇:c++显式栈如何实现递归

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》