123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- 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>("文本框" + 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();
- }
- public override void Update()
- {
- CanvasHeight = m_Text.GetComponent<RectTransform>().sizeDelta.y + 60;
- base.Update();
- }
- public override void SetData(MaterialObjValue value, long updateTime)
- {
- Debug.Log("Text +++++" + value.TextBJ);
- Debug.Log("Text +++++" + value.textContent);
- base.SetData(value, updateTime);
- SuCaiData = value;
- Data = new DownLoadMaterial(value);
- Data.updataTime = updateTime;
- if (string.IsNullOrWhiteSpace(value.textContent))
- {
- return;
- }
- if(value.textContent.Contains("<br>"))
- value.textContent = value.textContent.Replace("<br>","\n");
- if (m_Text)
- {
- m_Text.text = value.textContent;
- m_BG.sprite = ResMgr.Instance.Load<Sprite>("文本框" + value.TextBJ);
- }
- else
- {
- m_Canvas = transform.Find("Canvas").GetComponent<RectTransform>();
- m_BG = transform.Find("Canvas/Image").GetComponent<Image>();
- m_Text = transform.Find("Canvas/Text").GetComponent<Text>();
- m_Text.text = value.textContent;
- m_BG.sprite = ResMgr.Instance.Load<Sprite>("文本框" + value.TextBJ);
- }
- }
- string str;
- public void SetData(string text ,string bg )
- {
- if (string.IsNullOrWhiteSpace(text))
- {
- return;
- }
- str = text;
- Debug.Log("HJJTEST 賦值Text===》"+text);
- if (m_Text)
- {
- m_Text.text = text;
- m_BG.sprite = ResMgr.Instance.Load<Sprite>("文本框" + bg);
- }
- else
- {
- m_Canvas = transform.Find("Canvas").GetComponent<RectTransform>();
- m_BG = transform.Find("Canvas/Image").GetComponent<Image>();
- m_Text = transform.Find("Canvas/Text").GetComponent<Text>();
- m_Text.text = text;
- m_BG.sprite = ResMgr.Instance.Load<Sprite>("文本框" + bg);
- }
- }
-
- public override void HideCollider()
- {
- base.HideCollider();
- }
- }
|