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("
"))
SuCaiData.textContent = SuCaiData.textContent.Replace("
","\n");
m_Text.text = SuCaiData.textContent;
m_BG.sprite = ResMgr.Instance.Load("Template/Texture/文本框" + SuCaiData.TextBJ.ToString());
}
}
protected override void OnAwake()
{
base.OnAwake();
m_Canvas = transform.Find("Canvas").GetComponent();
m_BG = transform.Find("Canvas/Image").GetComponent();
m_Text = transform.Find("Canvas/Text").GetComponent();
HideCollider();
}
private void Update()
{
CanvasHeight = m_Text.GetComponent().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("
"))
value.textContent = value.textContent.Replace("
","\n");
m_Text.text = value.textContent;
m_BG.sprite = ResMgr.Instance.Load("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("Template/Texture/文本框" + bg);
}
public override void HideCollider()
{
base.HideCollider();
}
}