BaseView.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using UnityEngine;
  2. public abstract class BaseView : BaseWindow
  3. {
  4. private BaseList _baseList;
  5. public BaseList baseList {
  6. get {
  7. if (!_baseList) {
  8. _baseList = GetComponentInParent<BaseList>();
  9. }
  10. return _baseList;
  11. }
  12. }
  13. protected BaseConfig config;
  14. public bool IsSelect { get; set; }
  15. public TextMesh titleTextMesh;
  16. public TextMesh introductionTextMesh;
  17. public GameObject backGround;
  18. SCButton _scButton;
  19. public SCButton scButton {
  20. get {
  21. _scButton = GetComponent<SCButton>();
  22. if (!_scButton) {
  23. _scButton = gameObject.AddComponent<SCButton>();
  24. }
  25. return _scButton;
  26. }
  27. }
  28. public override void Init() {
  29. base.Init();
  30. if (config != null) {
  31. config.Init();
  32. }
  33. }
  34. public override void Awake() {
  35. base.Awake();
  36. if (config != null) {
  37. config.Awake();
  38. }
  39. IsSelect = false;
  40. SCButtonAddListener();
  41. }
  42. public override void Start() {
  43. base.Start();
  44. if (config != null) {
  45. config.Start();
  46. }
  47. }
  48. public override void Update() {
  49. base.Update();
  50. if (config != null) {
  51. config.Update();
  52. }
  53. }
  54. public override void OnDestroy() {
  55. base.OnDestroy();
  56. if (config != null) {
  57. config.OnDestroy();
  58. }
  59. }
  60. public virtual void OnEnter() {
  61. if (config !=null) {
  62. config.OnEnter();
  63. }
  64. }
  65. public virtual void OnDown() {
  66. if (config != null) {
  67. config.OnDown();
  68. }
  69. }
  70. public virtual void OnUp() {
  71. if (config != null) {
  72. config.OnUp();
  73. }
  74. }
  75. public virtual void OnExit() {
  76. if (config != null) {
  77. config.OnExit();
  78. }
  79. }
  80. public virtual void OnClick() {
  81. if (config != null) {
  82. config.OnClick();
  83. }
  84. }
  85. public virtual void UpdateConfig(BaseConfig config) {
  86. this.config = config;
  87. if (titleTextMesh) {
  88. // titleTextMesh.text = config == null ? "Null" : config.title;
  89. }
  90. if (introductionTextMesh) {
  91. // introductionTextMesh.text = config == null ? "Null" : config.introduction;
  92. }
  93. }
  94. public void SCButtonAddListener() {
  95. scButton.onEnter.AddListener(OnEnter);
  96. scButton.onClick.AddListener(OnClick);
  97. scButton.onDown.AddListener(OnDown);
  98. scButton.onUp.AddListener(OnUp);
  99. scButton.onExit.AddListener(OnExit);
  100. }
  101. }