TemplateText.cs 3.5 KB

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