UIBase.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class UIBase : MonoBehaviour
  5. {
  6. public SimpleUIdata UIData;
  7. public System.Object UICanshu;
  8. public virtual bool NeedBroad { get; }
  9. protected virtual void Awake()
  10. {
  11. }
  12. protected virtual void Start()
  13. {
  14. MessageCenterController.Instance.Register(GameEnum.MESSAGE_TONGBU_UI_CHANGE, TongbuData);
  15. }
  16. protected virtual void OnDestroy()
  17. {
  18. MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_TONGBU_UI_CHANGE, TongbuData);
  19. }
  20. protected virtual void LateUpdate()
  21. {
  22. //UIData.Pos = this.gameObject.transform.position;
  23. //UIData.Eurl = this.gameObject.transform.eulerAngles;
  24. }
  25. public virtual void InitSimpleUIdata()
  26. {
  27. }
  28. protected virtual void Refresh()
  29. {
  30. }
  31. private void TongbuData(System.Object datas)
  32. {
  33. if(UIData == null)
  34. {
  35. return;
  36. }
  37. SimpleUIdata checkData = datas as SimpleUIdata;
  38. if (checkData.GetUIKey().Equals(UIData.GetUIKey()))
  39. {
  40. UICanshu = UIDataManager.Instance.GetDataByKeyId(UIData.GetUIKey());
  41. Refresh();
  42. }
  43. }
  44. protected void ShowDataRefresh()
  45. {
  46. //防止 UIData 是空的
  47. if (UIData == null)
  48. {
  49. InitSimpleUIdata();
  50. }
  51. UICanshu =UIDataManager.Instance.GetDataByKeyId(UIData.GetUIKey());
  52. }
  53. protected virtual void HideDataSend()
  54. {
  55. if (NeedBroad)
  56. UIDataManager.Instance.RefreshUI(UIData, UICanshu,UIDataMode.Del);
  57. }
  58. protected virtual void ShowDataSend()
  59. {
  60. if(NeedBroad)
  61. UIDataManager.Instance.RefreshUI(UIData, UICanshu, UIDataMode.Add);
  62. }
  63. protected virtual void RefreshDataSend()
  64. {
  65. if(NeedBroad)
  66. UIDataManager.Instance.RefreshUI(UIData, UICanshu, UIDataMode.Refresh);
  67. }
  68. }