TemplateText.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. m_Text.text = SuCaiData.textContent;
  36. m_BG.sprite = ResMgr.Instance.Load<Sprite>("Template/Texture/文本框" + SuCaiData.TextBJ.ToString());
  37. }
  38. }
  39. protected override void OnAwake()
  40. {
  41. base.OnAwake();
  42. m_Canvas = transform.Find("Canvas").GetComponent<RectTransform>();
  43. m_BG = transform.Find("Canvas/Image").GetComponent<Image>();
  44. m_Text = transform.Find("Canvas/Text").GetComponent<Text>();
  45. HideCollider();
  46. }
  47. private void Update()
  48. {
  49. CanvasHeight = m_Text.GetComponent<RectTransform>().sizeDelta.y + 60;
  50. }
  51. public override void SetData(MaterialObjValue value, int updateTime)
  52. {
  53. base.SetData(value, updateTime);
  54. SuCaiData = value;
  55. Data = new DownloadData(value);
  56. Data.updateTime = updateTime;
  57. if (string.IsNullOrWhiteSpace(value.textContent))
  58. {
  59. return;
  60. }
  61. m_Text.text = value.textContent;
  62. m_BG.sprite = ResMgr.Instance.Load<Sprite>("Template/Texture/文本框" + value.TextBJ.ToString());
  63. }
  64. public override void HideCollider()
  65. {
  66. base.HideCollider();
  67. }
  68. }