TemplateText.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 override void HideCollider()
  69. {
  70. base.HideCollider();
  71. }
  72. }