UIWindowBase.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System;
  5. public class UIWindowBase : UIBase
  6. {
  7. [HideInInspector]
  8. public string cameraKey;
  9. public UIType m_UIType;
  10. public WindowStatus windowStatus;
  11. public GameObject m_bgMask;
  12. public GameObject m_uiRoot;
  13. public float m_PosZ; //Z轴偏移
  14. #region 重载方法
  15. public virtual void OnOpen()
  16. {
  17. }
  18. public virtual void OnClose()
  19. {
  20. }
  21. public virtual void OnHide()
  22. {
  23. }
  24. public virtual void OnShow()
  25. {
  26. }
  27. public virtual void OnRefresh()
  28. {
  29. }
  30. public virtual IEnumerator EnterAnim(UIAnimCallBack animComplete, UICallBack callBack,params object[] objs)
  31. {
  32. //默认无动画
  33. animComplete(this, callBack, objs);
  34. yield break;
  35. }
  36. public virtual void OnCompleteEnterAnim()
  37. {
  38. }
  39. public virtual IEnumerator ExitAnim(UIAnimCallBack animComplete, UICallBack callBack, params object[] objs)
  40. {
  41. //默认无动画
  42. animComplete(this, callBack, objs);
  43. yield break;
  44. }
  45. public virtual void OnCompleteExitAnim()
  46. {
  47. }
  48. public virtual void Show()
  49. {
  50. gameObject.SetActive(true);
  51. }
  52. public virtual void Hide()
  53. {
  54. gameObject.SetActive(false);
  55. }
  56. #endregion
  57. #region 继承方法
  58. public void InitWindow(int id)
  59. {
  60. List<UILifeCycleInterface> list = new List<UILifeCycleInterface>();
  61. Init(null, id);
  62. RecursionInitUI(null,this,id, list);
  63. }
  64. /// <summary>
  65. /// 递归初始化UI
  66. /// </summary>
  67. /// <param name="uiBase"></param>
  68. public void RecursionInitUI(UIBase parentUI,UIBase uiBase,int id,List<UILifeCycleInterface> UIList)
  69. {
  70. int childIndex = 0;
  71. for (int i = 0; i < uiBase.m_objectList.Count; i++)
  72. {
  73. GameObject go = uiBase.m_objectList[i];
  74. if(go != null)
  75. {
  76. UILifeCycleInterface tmp = go.GetComponent<UILifeCycleInterface>();
  77. if (tmp != null)
  78. {
  79. if (!UIList.Contains(tmp))
  80. {
  81. uiBase.AddLifeCycleComponent(tmp);
  82. UIList.Add(tmp);
  83. UIBase subUI = uiBase.m_objectList[i].GetComponent<UIBase>();
  84. if(subUI != null)
  85. {
  86. RecursionInitUI(uiBase, subUI, childIndex++, UIList);
  87. }
  88. }
  89. else
  90. {
  91. Debug.LogError("InitWindow 重复的引用 " + uiBase.UIEventKey + " " + uiBase.m_objectList[i].name);
  92. }
  93. }
  94. }
  95. else
  96. {
  97. Debug.LogWarning("InitWindow objectList[" + i + "] is null !: " + uiBase.UIEventKey );
  98. }
  99. }
  100. }
  101. //刷新是主动调用
  102. public void Refresh(params object[] args)
  103. {
  104. UISystemEvent.Dispatch(this, UIEvent.OnRefresh);
  105. OnRefresh();
  106. }
  107. public void AddEventListener(Enum l_Event)
  108. {
  109. if (!m_EventNames.Contains(l_Event))
  110. {
  111. m_EventNames.Add(l_Event);
  112. GlobalEvent.AddEvent(l_Event, Refresh);
  113. }
  114. }
  115. public override void RemoveAllListener()
  116. {
  117. base.RemoveAllListener();
  118. for (int i = 0; i < m_EventNames.Count; i++)
  119. {
  120. GlobalEvent.RemoveEvent(m_EventNames[i], Refresh);
  121. }
  122. m_EventNames.Clear();
  123. }
  124. #endregion
  125. public enum WindowStatus
  126. {
  127. Create,
  128. Open,
  129. Close,
  130. OpenAnim,
  131. CloseAnim,
  132. Hide,
  133. }
  134. }