共計(jì) 2269 個(gè)字符,預(yù)計(jì)需要花費(fèi) 6 分鐘才能閱讀完成。
今天丸趣 TV 小編給大家分享一下計(jì)算字體寬度及 Text 組件的自適應(yīng)怎么設(shè)置的相關(guān)知識(shí)點(diǎn),內(nèi)容詳細(xì),邏輯清晰,相信大部分人都還太了解這方面的知識(shí),所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。
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/.........
以上就是“計(jì)算字體寬度及 Text 組件的自適應(yīng)怎么設(shè)置”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,丸趣 TV 小編每天都會(huì)為大家更新不同的知識(shí),如果還想學(xué)習(xí)更多的知識(shí),請(qǐng)關(guān)注丸趣 TV 行業(yè)資訊頻道。