TemplateText.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class TemplateText : BaseTemPlate
  6. {
  7. private RectTransform m_Canvas;
  8. private Image m_BG;
  9. private Text m_Text;
  10. private float m_CanvasHeight;
  11. public float CanvasHeight
  12. {
  13. get { return m_CanvasHeight; }
  14. set
  15. {
  16. m_CanvasHeight = value;
  17. m_Canvas.sizeDelta = new Vector2(m_Canvas.sizeDelta.x, value);
  18. }
  19. }
  20. private float m_CanvasWidth;
  21. public float CanvasWidth
  22. {
  23. get { return m_CanvasWidth; }
  24. set
  25. {
  26. m_CanvasWidth = value;
  27. m_Canvas.sizeDelta = new Vector2(m_CanvasWidth, CanvasHeight);
  28. }
  29. }
  30. protected override void OnEnable()
  31. {
  32. base.OnEnable();
  33. if (GameManager.Instance.IsRuning && m_Text.text == null)
  34. {
  35. if(SuCaiData.textContent.Contains("<br>"))
  36. SuCaiData.textContent = SuCaiData.textContent.Replace("<br>","\n");
  37. m_Text.text = SuCaiData.textContent;
  38. m_BG.sprite = ResMgr.Instance.Load<Sprite>("Template/Texture/文本框" + SuCaiData.TextBJ.ToString());
  39. }
  40. }
  41. protected override void OnAwake()
  42. {
  43. base.OnAwake();
  44. m_Canvas = transform.Find("Canvas").GetComponent<RectTransform>();
  45. m_BG = transform.Find("Canvas/Image").GetComponent<Image>();
  46. m_Text = transform.Find("Canvas/Text").GetComponent<Text>();
  47. HideCollider();
  48. }
  49. private void Update()
  50. {
  51. CanvasHeight = m_Text.GetComponent<RectTransform>().sizeDelta.y + 60;
  52. }
  53. public override void SetData(MaterialObjValue value, int updateTime)
  54. {
  55. base.SetData(value, updateTime);
  56. SuCaiData = value;
  57. Data = new DownloadData(value);
  58. Data.updateTime = updateTime;
  59. if (string.IsNullOrWhiteSpace(value.textContent))
  60. {
  61. return;
  62. }
  63. if(value.textContent.Contains("<br>"))
  64. value.textContent = value.textContent.Replace("<br>","\n");
  65. m_Text.text = value.textContent;
  66. m_BG.sprite = ResMgr.Instance.Load<Sprite>("Template/Texture/文本框" + value.TextBJ.ToString());
  67. }
  68. public void SetData(string text ,string bg )
  69. {
  70. if (string.IsNullOrWhiteSpace(text))
  71. {
  72. return;
  73. }
  74. m_Text.text = text;
  75. m_BG.sprite = ResMgr.Instance.Load<Sprite>("Template/Texture/文本框" + bg);
  76. }
  77. public override void HideCollider()
  78. {
  79. base.HideCollider();
  80. }
  81. }