TemplateText.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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>("文本框" + 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. public override void Update()
  50. {
  51. CanvasHeight = m_Text.GetComponent<RectTransform>().sizeDelta.y + 60;
  52. base.Update();
  53. }
  54. public override void SetData(MaterialObjValue value, long updateTime)
  55. {
  56. Debug.Log("Text +++++" + value.TextBJ);
  57. Debug.Log("Text +++++" + value.textContent);
  58. base.SetData(value, updateTime);
  59. SuCaiData = value;
  60. Data = new DownLoadMaterial(value);
  61. Data.updataTime = updateTime;
  62. if (string.IsNullOrWhiteSpace(value.textContent))
  63. {
  64. return;
  65. }
  66. if(value.textContent.Contains("<br>"))
  67. value.textContent = value.textContent.Replace("<br>","\n");
  68. if (m_Text)
  69. {
  70. m_Text.text = value.textContent;
  71. m_BG.sprite = ResMgr.Instance.Load<Sprite>("文本框" + value.TextBJ);
  72. }
  73. else
  74. {
  75. m_Canvas = transform.Find("Canvas").GetComponent<RectTransform>();
  76. m_BG = transform.Find("Canvas/Image").GetComponent<Image>();
  77. m_Text = transform.Find("Canvas/Text").GetComponent<Text>();
  78. m_Text.text = value.textContent;
  79. m_BG.sprite = ResMgr.Instance.Load<Sprite>("文本框" + value.TextBJ);
  80. }
  81. }
  82. string str;
  83. public void SetData(string text ,string bg )
  84. {
  85. if (string.IsNullOrWhiteSpace(text))
  86. {
  87. return;
  88. }
  89. str = text;
  90. Debug.Log("HJJTEST 賦值Text===》"+text);
  91. if (m_Text)
  92. {
  93. m_Text.text = text;
  94. m_BG.sprite = ResMgr.Instance.Load<Sprite>("文本框" + bg);
  95. }
  96. else
  97. {
  98. m_Canvas = transform.Find("Canvas").GetComponent<RectTransform>();
  99. m_BG = transform.Find("Canvas/Image").GetComponent<Image>();
  100. m_Text = transform.Find("Canvas/Text").GetComponent<Text>();
  101. m_Text.text = text;
  102. m_BG.sprite = ResMgr.Instance.Load<Sprite>("文本框" + bg);
  103. }
  104. }
  105. public override void HideCollider()
  106. {
  107. base.HideCollider();
  108. }
  109. }