溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

計算字體寬度及Text組件的自適應(yīng)怎么設(shè)置

發(fā)布時間:2022-01-07 15:21:57 來源:億速云 閱讀:130 作者:iii 欄目:云計算

今天小編給大家分享一下計算字體寬度及Text組件的自適應(yīng)怎么設(shè)置的相關(guān)知識點,內(nèi)容詳細(xì),邏輯清晰,相信大部分人都還太了解這方面的知識,所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。

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("椅子在異鄉(xiāng),樹葉有翅膀,椅子在異鄉(xiāng),樹葉有翅膀,椅子在異鄉(xiāng),樹葉有翅膀"); 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("椅子在異鄉(xiāng),樹葉有翅膀。椅子在異鄉(xiāng),樹葉有翅膀。椅子在異鄉(xiāng),樹葉有翅膀。椅子在異鄉(xiāng),樹葉有翅膀。椅子在異鄉(xiāng),樹葉有翅膀。"); //SetChatText("椅子在異鄉(xiāng),樹葉有翅膀。");}private void InitGetComponent(){ #region RectTransform RtChatContentText = transform.Find("ContentEmpty/BgEmpty/ChatContentText").GetComponent<RectTransform>(); RtBgEmpty = transform.Find("ContentEmpty/.........

以上就是“計算字體寬度及Text組件的自適應(yīng)怎么設(shè)置”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會為大家更新不同的知識,如果還想學(xué)習(xí)更多的知識,請關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI