12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- 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 override void HideCollider()
- {
- base.HideCollider();
- }
- }
|