123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class TemplateText : BaseTemPlate
- {
- private RectTransform m_Canvas;
- private Image m_BG;
- private Text m_Text;
- private float m_CanvasHeight;
- public float CanvasHeight
- {
- get { return m_CanvasHeight; }
- set
- {
- m_CanvasHeight = value;
- m_Canvas.sizeDelta = new Vector2(m_Canvas.sizeDelta.x, value);
- }
- }
- private float m_CanvasWidth;
- public float CanvasWidth
- {
- get { return m_CanvasWidth; }
- set
- {
- m_CanvasWidth = value;
- m_Canvas.sizeDelta = new Vector2(m_CanvasWidth, CanvasHeight);
- }
- }
- protected override void OnEnable()
- {
- base.OnEnable();
- if (GameManager.Instance.IsRuning && m_Text.text == null)
- {
- if(SuCaiData.textContent.Contains("<br>"))
- SuCaiData.textContent = SuCaiData.textContent.Replace("<br>","\n");
- m_Text.text = SuCaiData.textContent;
- m_BG.sprite = ResMgr.Instance.Load<Sprite>("Template/Texture/文本框" + SuCaiData.TextBJ.ToString());
- }
- }
- protected override void OnAwake()
- {
- base.OnAwake();
- m_Canvas = transform.Find("Canvas").GetComponent<RectTransform>();
- m_BG = transform.Find("Canvas/Image").GetComponent<Image>();
- m_Text = transform.Find("Canvas/Text").GetComponent<Text>();
- HideCollider();
- }
- private void Update()
- {
- CanvasHeight = m_Text.GetComponent<RectTransform>().sizeDelta.y + 60;
- }
- public override void SetData(MaterialObjValue value, int updateTime)
- {
- base.SetData(value, updateTime);
- SuCaiData = value;
- Data = new DownloadData(value);
- Data.updateTime = updateTime;
- if (string.IsNullOrWhiteSpace(value.textContent))
- {
- return;
- }
- if(value.textContent.Contains("<br>"))
- value.textContent = value.textContent.Replace("<br>","\n");
- m_Text.text = value.textContent;
- m_BG.sprite = ResMgr.Instance.Load<Sprite>("Template/Texture/文本框" + value.TextBJ.ToString());
- }
- public void SetData(string text ,string bg )
- {
- if (string.IsNullOrWhiteSpace(text))
- {
- return;
- }
- m_Text.text = text;
- m_BG.sprite = ResMgr.Instance.Load<Sprite>("Template/Texture/文本框" + bg);
- }
- public override void HideCollider()
- {
- base.HideCollider();
- }
- }
|