| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using LuaInterface;
- using TMPro;
- using UnityEngine;
- using UnityEngine.UI;
- public enum UI_ANIM {
- NO,
- MOVE_IN,
- MOVE_OUT,
- SCALE_IN,
- SCALE_OUT,
- }
- public abstract class UIBase : MonoBase {
- public delegate UIBase UIPageCreator ();
- public delegate void PointListener (GameObject point);
- public delegate void PointListenerNoParam ();
- public delegate void ButtonListener (Button btn);
- public delegate void ButtonListenerWithParam (Button btn, params object[] param);
- public delegate void ToggleListener (bool b);
- public delegate void ToggleListenerWithParams (Toggle tog, params object[] param);
- public delegate void DialogCallback (int btn);
-
- [HideInInspector]
- public int ParentId {
- set { m_parentId = value; }
- get { return m_parentId; }
- }
- [SerializeField]
- private int m_parentId;
- [HideInInspector]
- public bool NeedParentKeep {
- set { m_needParentKeep = value; }
- get { return m_needParentKeep; }
- }
- [SerializeField]
- private bool m_needParentKeep;
- private bool mIsBattleMainPage = false;
- [HideInInspector]
- public bool IsBattleMainPage
- {
- get { return mIsBattleMainPage; }
- set { mIsBattleMainPage = value; }
- }
- private bool mIsClosed = false;
-
- #region fields
- private static int s_sequence = 0;
- private bool bInited = false;
- public bool Inited
- {
- get { return bInited; }
- }
- Canvas[] mChildCanvasList = null;
- private Canvas mCanvas = null;
- protected CanvasGroup mCanvasGroup = null;
- private GameObject mRootPage = null;
- private Transform mPageBodyTrans = null;
- private GameObject mPageBody = null;
- private int mPageId = 0;
- public UIAnimationListener animListener;
- private UIAnimationEvent[] mAnimtionEvents;
- private Dictionary<string, GameObject> mChildGoes = null;
- public int PageId {
- get { return mPageId; }
- set { mPageId = value; }
- }
- private int mPageUniqueID = 0;
- public int PageUniqueID {
- get { return mPageUniqueID; }
- }
- private string mPageName;
- public string MPageName {
- get { return mPageName; }
- set { mPageName = value; }
- }
- private int mSourceUIID;
- public int MSourceUIID {
- get { return mSourceUIID; }
- set { mSourceUIID = value; }
- }
- private bool bShowTopBtn;
- public bool ShowTopBtn
- {
- get { return bShowTopBtn; }
- set { bShowTopBtn = value; }
- }
- private bool mOutList;
- public bool MOutList
- {
- get { return mOutList; }
- set { mOutList = value; }
- }
- public bool IsActive {
- get {
- if (mPageBody == null)
- return false;
- return mPageBody.activeSelf;
- }
- }
- protected object m_Data;
- public object Data {
- get { return m_Data; }
- }
- protected UI_ANIM mAnimInType = UI_ANIM.NO;
- protected UI_ANIM mAnimOutType = UI_ANIM.NO;
- private bool mIsPageAnimation = false;
- private bool mIsPageEnabled = false; //save enabled state when page is animation.
- protected bool mIsNotify = false;
- protected bool mIsTop = false;
- protected bool mIsEnabled = true;
- protected bool mIsDisposed = false;
- protected bool mIsOpened = false;
- protected bool mIsShowed = false;
- protected bool mIsHide = false;
- protected bool bNeedCache = true;
- public bool IsHide
- {
- get { return mIsHide; }
- }
- public bool NeedCache
- {
- get { return bNeedCache; }
- set { bNeedCache = value; }
- }
- //protected UIData mUIData;
- private bool mCanPlaySound = true;
- public bool CanPlaySound { get { return mCanPlaySound; } set { mCanPlaySound = value; } }
- private int mUIType = 0;
- public int MUIType {
- set { mUIType = value; }
- get { return mUIType; }
- }
- private bool mPersistentStatus = false;
- public bool MPersistentStatus {
- set { mPersistentStatus = value; }
- get { return mPersistentStatus; }
- }
- protected int mShowLoadingActionId = 0;
- protected struct CanvasStatus {
- public Canvas m_canvas;
- public bool m_bOriginalEnabled;
- public CanvasStatus (Canvas c, bool s) {
- m_canvas = c;
- m_bOriginalEnabled = s;
- }
- };
- protected List<CanvasStatus> m_ChildCanvasStatus = null;
- private EUIPageType mPageType = EUIPageType.Null;
- public EUIPageType PageType {
- get { return mPageType; }
- set { mPageType = value; }
- }
- public int initSortingOrder;
- public int SortingOrder {
- get {
- return mCanvas != null ? mCanvas.sortingOrder : 0;
- }
- set {
- if (mCanvas == null)
- return;
- mCanvas.sortingOrder = value;
- }
- }
- public GameObject PageBody {
- get { return mPageBody; }
- }
- public Transform PageTrans {
- get { return mPageBodyTrans; }
- }
- private string mAssetBundle;
- public string StrAssetBundle {
- get {
- return mAssetBundle;
- }
- set {
- if(mAssetBundle!=value)
- {
- mAssetBundle = value;
- }
- }
- }
- private string[] mChildAssetNames = null;
- private string mChildPaths;
- public string ChildPaths
- {
- get { return mChildPaths; }
- set
- {
- if(mChildPaths != value)
- {
- mChildPaths = value;
- if (!string.IsNullOrEmpty(mChildPaths))
- mChildAssetNames = mChildPaths.Split(';');
- else
- mChildAssetNames = null;
- }
- }
- }
- public bool IsEnabled {
- get { return mIsEnabled; }
- set { mIsEnabled = value; }
- }
- public bool IsDisposed {
- get { return mIsDisposed; }
- }
- public bool IsOpened {
- get { return mIsOpened; }
- }
- public UI_ANIM PageAnimInType {
- get { return mAnimInType; }
- set { mAnimInType = value; }
- }
- public UI_ANIM PageAnimOutType {
- get { return mAnimOutType; }
- set { mAnimOutType = value; }
- }
- public bool IsPageAnimation {
- get { return mIsPageAnimation; }
- }
- public bool CanvasEnabled {
- get { return mCanvas != null ? mCanvas.enabled : false; }
- set {
- if (mCanvas == null) return;
- if (mCanvas.enabled != value) {
- mCanvas.overrideSorting = true;
- mCanvas.enabled = value;
- if (mChildCanvasList != null) {
- for (int idx = 0; idx < mChildCanvasList.Length; idx++)
- {
- if (mChildCanvasList[idx])
- mChildCanvasList[idx].enabled = value;
- }
- }
- }
- }
- }
- public bool IsShowed {
- get { return mIsShowed; }
- }
- public Canvas UICanvas {
- get { return mCanvas; }
- }
- List<Selectable> mAddListenerComList = new List<Selectable> ();
- Dictionary<Selectable, UIPlaySound> mBtnClickSoundHolderDict = new Dictionary<Selectable, UIPlaySound>();
- int interTime = 500;
- int timerSeq;
- bool UIEventStatus = false;
- #endregion
- private void Awake () {
- mPageUniqueID = ++s_sequence;
- }
- [NoToLua]
- public virtual void Open (UIData uidata, object param) {
- DisableGroupInteraction ();
- //mUIData = uidata;
- //mPageId = mUIData.PageID;
- m_Data = param;
- bInited = false;
- mIsShowed = true;
- mIsDisposed = false;
- mIsOpened = true;
- mIsHide = false;
- mIsClosed = false;
- OnAwake ();
- if (mPageBody == null)
- {
- LoadUIAssets ();
- }
- else
- {
- //!Move To Top Level
- mPageBodyTrans.SetAsLastSibling ();
- if (!mIsTop && UIMgr.Instance.MainFunPage != null) {
- UIMgr.Instance.MainFunPage.GetComponent<RectTransform> ().SetAsLastSibling ();
- }
- FillContent ();
- PageAnimationIn();
- }
- }
- [NoToLua]
- public void EnableGroupInteraction () {
- StartCoroutine (DelayCanvasGroupInteraction (0.0f));
- }
- [NoToLua]
- public void DisableGroupInteraction () {
- if (mCanvasGroup != null)
- mCanvasGroup.interactable = false;
- }
- IEnumerator DelayCanvasGroupInteraction (float time) {
- yield return new WaitForSeconds (time);
- if (mCanvasGroup != null) mCanvasGroup.interactable = true;
- }
- protected void CreatePageBody ()
- {
- if (string.IsNullOrEmpty (mPageName))
- mPageName = GetType ().Name;
- mPageBody = new GameObject (mPageName);
- mCanvas = mPageBody.AddComponent<Canvas> ();
- mPageBody.AddComponent<GraphicRaycaster> ();
- mCanvasGroup = mPageBody.AddComponent<CanvasGroup> ();
- DisableGroupInteraction ();
- SortingOrder = initSortingOrder;
- CanvasEnabled = true;
- animListener = mPageBody.AddComponent<UIAnimationListener>();
- animListener.ListenerPage = this;
- mPageBody.layer = LayerMask.NameToLayer ("UI");
- mPageBodyTrans = mPageBody.transform;
- mPageBodyTrans.SetParent (UIMgr.Instance.UIRootTrans);
- RectTransform rectTrans = mPageBody.GetComponent<RectTransform> ();
- if (rectTrans != null) {
- RectTransform rootRTrans = UIMgr.Instance.UIRootTrans.GetComponent<RectTransform> ();
- rectTrans.localPosition = Vector3.zero;
- rectTrans.localScale = Vector3.one;
- rectTrans.anchorMin = new Vector2 (0, 0);
- rectTrans.anchorMax = new Vector2 (1.0f, 1.0f);
- rectTrans.pivot = new Vector2 (0.5f, 0.5f);
- rectTrans.anchoredPosition = Vector2.zero;
- rectTrans.sizeDelta = Vector2.zero;
- }
- if (!mIsTop && UIMgr.Instance.MainFunPage != null) {
- UIMgr.Instance.MainFunPage.GetComponent<RectTransform> ().SetAsLastSibling ();
- }
- mCanvas.overrideSorting = true;
- //SortingOrder += UIMgr.Instance.GetNextPageOrderingSort (this);
- }
-
- private void ResetPageBody(GameObject bodyGO)
- {
- if (string.IsNullOrEmpty(mPageName))
- mPageName = GetType().Name;
- mPageBody = bodyGO;
- mCanvas = mPageBody.GetComponent<Canvas>();
- mCanvasGroup = mPageBody.GetComponent<CanvasGroup>();
- DisableGroupInteraction();
- SortingOrder = initSortingOrder;
- CanvasEnabled = true;
- animListener = mPageBody.GetComponent<UIAnimationListener>();
- if (animListener == null)
- {
- animListener = mPageBody.AddComponent<UIAnimationListener>();
- }
- animListener.ListenerPage = this;
- mPageBodyTrans = mPageBody.transform;
- if (!mIsTop && UIMgr.Instance.MainFunPage != null)
- {
- UIMgr.Instance.MainFunPage.GetComponent<RectTransform>().SetAsLastSibling();
- }
- mCanvas.overrideSorting = true;
- //SortingOrder += UIMgr.Instance.GetNextPageOrderingSort(this);
- mPageBody.SetActive(true);
- //CommonUtil.SetGameObjectLayer(mPageBody, "UI");
- }
- protected void LoadUIAssets ()
- {
- if (mAssetBundle != null && !string.IsNullOrEmpty(mAssetBundle))
- {
- GameObject pageGo = ResourceMgr.Instance.GetUIGoFromPool(Constants.UIPath, mAssetBundle + "_body");
- List<string> assetNames = new List<string>();
- assetNames.Add(mAssetBundle);
- if (mChildAssetNames != null)
- {
- for (int idx = 0; idx < mChildAssetNames.Length; idx++)
- assetNames.Add(mChildAssetNames[idx]);
- }
- if (pageGo == null)
- {
- CreatePageBody();
- ResourceMgr.Instance.GetGoesFromPool(Constants.UIPath, assetNames.ToArray(), OnLoadRes);
- }
- else
- {
- ResetPageBody(pageGo);
- mRootPage = pageGo.transform.Find("Root").gameObject;
- mAnimtionEvents = mPageBody.GetComponentsInChildren<UIAnimationEvent>(true);
- if (mAnimtionEvents != null)
- {
- foreach(var animationEvent in mAnimtionEvents)
- {
- animationEvent.BasePage = this;
- }
- }
- for (int idx = 1; idx < assetNames.Count; idx++)
- {
- if (mChildGoes == null)
- mChildGoes = new Dictionary<string, GameObject>();
- var subGo = pageGo.transform.Find("Part" + idx).gameObject;
- mChildGoes.Add(assetNames[idx], subGo);
- }
- StartInitialize();
- PageAnimationIn();
- }
- }
- else
- {
- EventMgr.DispatchEvent<int> (new CoreEvent<int> (ECoreEventType.EID_UI_LoadFail, mPageId));
- }
- }
- private void OnLoadRes (List<GameObject> uiGoes,string path,string[] assetNames)
- {
- if (uiGoes == null || uiGoes.Count == 0) {
- EventMgr.DispatchEvent<int> (new CoreEvent<int> (ECoreEventType.EID_UI_LoadFail, mPageId));
- Hide ();
- return;
- }
- mRootPage = uiGoes[0];
- mRootPage.name = "Root";
- mRootPage.SetActive(true);
- for(int idx = 0;idx < uiGoes.Count;idx++)
- {
- CommonUtil.SetGameObjectLayer(uiGoes[idx], "UI");
- RectTransform rectTrans = uiGoes[idx].GetComponent<RectTransform>();
- rectTrans.SetParent(mPageBodyTrans, false);
- rectTrans.localScale = Vector3.one;
- if(idx == 0)
- {
- rectTrans.anchorMin = new Vector2(0, 0);
- rectTrans.anchorMax = new Vector2(1.0f, 1.0f);
- rectTrans.pivot = new Vector2(0.5f, 0.5f);
- rectTrans.anchoredPosition3D = Vector3.zero;
- rectTrans.sizeDelta = Vector2.zero;
- }
- else
- {
- if (mChildGoes == null)
- mChildGoes = new Dictionary<string, GameObject>();
- mChildGoes.Add(assetNames[idx], uiGoes[idx]);
- uiGoes[idx].name = "Part" + idx;
- }
- }
- //已经关闭
- if (mIsDisposed || mIsClosed)
- {
- //ResourceMgr.Instance.RecycleGO(Constants.UIPath, mMainAssetBundle, mRootPage);
- for(int idx =0; idx < assetNames.Length;idx++)
- {
- ResourceMgr.Instance.RecycleGO(Constants.UIPath, assetNames[idx], uiGoes[idx]);
- }
- mRootPage = null;
- return;
- }
- mAnimtionEvents = mPageBody.GetComponentsInChildren<UIAnimationEvent>(true);
- if (mAnimtionEvents != null)
- {
- foreach (var animationEvent in mAnimtionEvents)
- {
- animationEvent.BasePage = this;
- }
- }
- StartInitialize ();
- PageAnimationIn();
- }
- public GameObject GetRoot ()
- {
- return mRootPage;
- }
- void StartInitialize ()
- {
- EnableGroupInteraction ();
- mChildCanvasList = mPageBody.GetComponentsInChildren<Canvas> ();
- if (mChildCanvasList != null)
- {
- for (int idx = 0; idx < mChildCanvasList.Length; idx++)
- mChildCanvasList[idx].enabled = true;
- }
- EventMgr.DispatchEvent<int>(new CoreEvent<int>(ECoreEventType.EID_UI_LoadSuccess, mPageId));
- InitializePage();
- }
- public GameObject FindElementGo (string name) {
- if (mPageBodyTrans == null) return null;
- GameObject go = null;
- Transform trans = mPageBodyTrans.Find (name);
- if (trans != null) go = trans.gameObject;
- return go;
- }
- public GameObject FindElementGo (GameObject go, string name) {
- if (go == null) return null;
- GameObject cgo = null;
- Transform trans = go.transform.Find (name);
- if (trans != null) cgo = trans.gameObject;
- return cgo;
- }
- public T FindElement<T> (string name) {
- return FindElement<T> (mPageBody, name);
- }
- public T FindElement<T> (GameObject go, string name) {
- if (go == null) return default (T);
- Transform trans = go.transform.Find (name);
- if (trans == null) return default (T);
- return trans.GetComponent<T> ();
- }
- #region 虚函数
- [NoToLua]
- public virtual void InitializePage () {
- bInited = true;
- FillContent ();
- AddEventListener ();
- AddUIEventListener ();
- }
- [NoToLua]
- public virtual void OnOpenAnimEnd () {
- mIsPageAnimation = false;
- IsEnabled = mIsPageEnabled;
- if (!IsOpened) {
- CanvasEnabled = false;
- }
- OnPageInEnd();
- EventMgr.DispatchEvent<int>(new CoreEvent<int>(ECoreEventType.EID_UI_SHOW, mPageId));
- }
- [NoToLua]
- public virtual void OnCloseAnimEnd()
- {
- mIsPageAnimation = false;
- IsEnabled = mIsPageEnabled;
- CanvasEnabled = false;
- OnPageOutEnd();
- EventMgr.DispatchEvent<int>(new CoreEvent<int>(ECoreEventType.EID_UI_CLOSE, mUIType));
- }
- public virtual void Show (object param = null, bool needOutAnim = true) {
- m_Data = param;
- EnableGroupInteraction ();
- if (!bInited)
- {
- return;
- }
- if (!mIsOpened) {
- mIsOpened = true;
- EventMgr.DispatchEvent<int> (new CoreEvent<int> (ECoreEventType.EID_UI_SHOW, mPageId));
- }
- if (!mIsShowed) {
- if (!UIMgr.Instance.PageInHideStack (this)) {
- //SortingOrder += UIMgr.Instance.GetNextPageOrderingSort(this);
- }
- CanvasEnabled = true;
- //mPageBody.SetActive (true);
- mIsShowed = true;
- mIsHide = false;
- PageAnimationIn (needOutAnim);
- }
- OnShow ();
- //EventMgr.DispatchEvent<int, bool> (new CoreEvent<int, bool> (ECoreEventType.EID_UI_VISIBLE, mPageId, true));
- }
- public virtual void Hide (bool needOutAnim = true) {
- if (!mIsShowed) return;
- OnHide();
- PageAnimationOut(needOutAnim);
- if (!IsPageAnimation) {
- //mPageBody.SetActive (false);
- CanvasEnabled = false;
- }
- mIsShowed = false;
- mIsHide = true;
- //EventMgr.DispatchEvent<int, bool> (new CoreEvent<int, bool> (ECoreEventType.EID_UI_VISIBLE, mPageId, false));
- }
- public virtual void Close (bool needOutAnim = true) {
- if (mIsClosed) return;
- RemoveEventListener();
- OnClose();
- PageAnimationOut(needOutAnim);
- mIsShowed = false;
- mIsOpened = false;
- mIsHide = false;
- mIsClosed = true;
- }
- public virtual void Dispose () {
- if (mIsDisposed) return;
- TimerManager.Instance.RemoveTimer(timerSeq);
- for (int idx = 0; idx < mAddListenerComList.Count; idx++)
- {
- Button btn = mAddListenerComList[idx] as Button;
- if (btn != null)
- {
- btn.onClick.RemoveAllListeners();
- continue;
- }
- Toggle tog = mAddListenerComList[idx] as Toggle;
- if (tog != null)
- {
- tog.onValueChanged.RemoveAllListeners();
- continue;
- }
- Slider slider = mAddListenerComList[idx] as Slider;
- if (slider != null)
- {
- slider.onValueChanged.RemoveAllListeners();
- continue;
- }
- InputField input = mAddListenerComList[idx] as InputField;
- if (input != null)
- {
- input.onValueChanged.RemoveAllListeners();
- continue;
- }
- TMP_InputField tInput = mAddListenerComList[idx] as TMP_InputField;
- if (tInput != null)
- {
- tInput.onValueChanged.RemoveAllListeners();
- continue;
- }
- Dropdown dropDown = mAddListenerComList[idx] as Dropdown;
- if (dropDown != null)
- {
- dropDown.onValueChanged.RemoveAllListeners();
- continue;
- }
- }
- mAddListenerComList.Clear();
- mBtnClickSoundHolderDict.Clear();
- Close();
- OnDispose ();
- CanvasEnabled = false;
- if(mRootPage!=null && bNeedCache)
- {
- if (mPageBody != null)
- {
- ResourceMgr.Instance.RecycleUIGO(Constants.UIPath, mAssetBundle + "_body", mPageBody);
- }
- }
- else
- {
- ResourceMgr.Instance.RemoveLoadedResource(Constants.UIPath, mAssetBundle);
- if(mChildAssetNames != null)
- {
- for(int idx =0; idx < mChildAssetNames.Length;idx++)
- {
- ResourceMgr.Instance.RemoveLoadedResource(Constants.UIPath, mChildAssetNames[idx]);
- }
- }
- GameObject.Destroy(mPageBody);
- }
- if (mAnimtionEvents != null)
- {
- foreach (var animationEvent in mAnimtionEvents)
- {
- animationEvent.BasePage = null;
- }
- }
- if(animListener != null)
- {
- animListener.ListenerPage = null;
- }
-
- mPageBody = null;
- mPageBodyTrans = null;
- mRootPage = null;
- mAnimtionEvents = null;
- mChildCanvasList = null;
- animListener = null;
- m_Data = null;
- mCanvas = null;
- mCanvasGroup = null;
- mIsDisposed = true;
- Destroy (this);
- }
- public virtual void BackIn () {
- OnBackIn ();
- }
- #endregion
- #region inner_methods
- void PageAnimationIn (bool needOutAnim = true) {
- if (!UIMgr.Instance) return;
- //已经关闭
- if (mIsDisposed || mIsClosed)
- {
- return;
- }
- if (mIsPageAnimation) {
- StartCoroutine (checkAnimationState ());
- return;
- }
- if (mRootPage != null)
- {
- mRootPage.SetActive(true);
- }
- mIsPageAnimation = false;
- if (needOutAnim)
- {
- Animator anim = null;
- Transform uiAnimator = mPageBody.transform.Find("Root/UIAnimator");
- if (uiAnimator != null)
- {
- if (mAnimInType != UI_ANIM.NO)
- {
- anim = uiAnimator.GetComponent<Animator>();
- }
- if (anim != null)
- {
- switch (mAnimInType)
- {
- case UI_ANIM.MOVE_IN:
- case UI_ANIM.MOVE_OUT:
- case UI_ANIM.SCALE_IN:
- case UI_ANIM.SCALE_OUT:
- {
- string name = GetAniName(mAnimInType);
- if (anim != null)
- {
- anim.Play(name, 0, 0);
- anim.updateMode = AnimatorUpdateMode.Normal;
- mIsPageAnimation = true;
- }
- }
- break;
- }
- }
- }
- }
- if (mIsPageAnimation)
- {
- mIsPageEnabled = IsEnabled;
- IsEnabled = false;
- }
- else
- {
- OnOpenAnimEnd();
- }
- }
- [NoToLua]
- public string GetAniName(UI_ANIM animType)
- {
- string animName = null;
- switch (animType)
- {
- case UI_ANIM.MOVE_IN:
- animName = "UIMoveInRight";
- break;
- case UI_ANIM.MOVE_OUT:
- animName = "UIMoveOutLeft";
- break;
- case UI_ANIM.SCALE_IN:
- animName = "UIWindowIn";
- break;
- case UI_ANIM.SCALE_OUT:
- animName = "UIWindowOut";
- break;
- }
- return animName;
- }
- void PageAnimationOut (bool needOutAnim = true) {
- if (!UIMgr.Instance) return;
- mIsPageAnimation = false;
- if (needOutAnim)
- {
- Animator anim = null;
- Transform uiAnimator = mPageBody.transform.Find("Root/UIAnimator");
- if (uiAnimator != null)
- {
- if (mAnimOutType != UI_ANIM.NO)
- {
- anim = uiAnimator.GetComponent<Animator>();
- }
- if (anim != null)
- {
- switch (mAnimOutType)
- {
- case UI_ANIM.MOVE_IN:
- case UI_ANIM.MOVE_OUT:
- case UI_ANIM.SCALE_IN:
- case UI_ANIM.SCALE_OUT:
- {
- string name = GetAniName(mAnimOutType);
- if (anim != null)
- {
- anim.Play(name, 0, 0);
- anim.updateMode = AnimatorUpdateMode.Normal;
- mIsPageAnimation = true;
- }
- }
- break;
- }
- }
- }
- }
-
- if (mIsPageAnimation) {
- mIsPageEnabled = IsEnabled;
- IsEnabled = false;
- } else {
- OnCloseAnimEnd();
- }
- StartCoroutine (DelayDisablePage ());
- }
- IEnumerator checkAnimationState () {
- while (mIsPageAnimation) yield return 0;
- PageAnimationIn ();
- }
- IEnumerator DelayDisablePage () {
- if (this.PageBody != null) {
- if (mCanvasGroup != null) {
- float time = 0;
- while (mCanvasGroup.alpha != 0) {
- yield return new WaitForEndOfFrame ();
- if (!PageBody)
- yield break;
- time += Time.deltaTime;
- if (time > 2) {
- yield break;
- }
- }
- if (mRootPage != null) {
- mRootPage.SetActive(false);
- }
- }
- }
- }
- #endregion
- #region 外部需要重构的 abstract 方法.
- protected abstract void OnAwake ();
- protected abstract void AddEventListener ();
- protected abstract void FillContent ();
- protected abstract void RemoveEventListener ();
- protected abstract void AddUIEventListener ();
- protected abstract void OnBaseHide();
- protected abstract void OnHide ();
- protected abstract void OnBaseShow();
- protected abstract void OnShow ();
- protected abstract void OnBaseClose();
- protected abstract void OnClose ();
- protected abstract void OnBaseDispose();
- protected abstract void OnDispose ();
- protected abstract void OnBackIn ();
- protected abstract void OnPageOutEnd();
- protected abstract void OnPageInEnd();
- public abstract void OnSubCloseAnimEnd(string path);
- #endregion
- #region events
- void ResetUIEventStatus (int seq) {
- UIEventStatus = false;
- timerSeq = -1;
- }
- public void AddButtonExitListener (Button btn, LuaTable table, LuaFunction listener, params object[] param) {
- if (btn != null) {
- mAddListenerComList.Add (btn);
- UIEventTriggerListener eventTrigger = UIEventTriggerListener.Get (btn.gameObject);
- eventTrigger.onPointerExit = new UnityEngine.Events.UnityAction (() => {
- listener.Call (table, btn, param);
- });
- }
- }
- public void AddButtonEventListener (Button btn, ButtonListener listener) {
- if (btn != null) {
- mAddListenerComList.Add (btn);
- btn.onClick.AddListener (new UnityEngine.Events.UnityAction (() => {
- if (BattleMgr.Instance.IsRotatingCam) return;
- if (UIEventStatus) return;
- UIEventStatus = true;
- timerSeq = TimerManager.Instance.AddTimer (interTime, 1, ResetUIEventStatus);
- ClickButton (btn);
- listener (btn);
- }));
- }
- }
- public void AddButtonEventListener (Button btn, LuaFunction listener) {
- if (btn != null) {
- mAddListenerComList.Add (btn);
- btn.onClick.AddListener (new UnityEngine.Events.UnityAction (() => {
- if (BattleMgr.Instance.IsRotatingCam) return;
- if (UIEventStatus) return;
- UIEventStatus = true;
- timerSeq = TimerManager.Instance.AddTimer (interTime, 1, ResetUIEventStatus);
- ClickButton (btn);
- listener.Call (btn);
- }));
- }
- }
- public void AddButtonEventListener (Button btn, LuaTable table, LuaFunction listener) {
- //Debug.Log($"------------------{btn.name}---");
- //if (btn.name == "BtnInfo")
- //{
- // Debug.Log($"------------------{btn.name}---");
- // btn.onClick.AddListener(() => { Debug.Log("点击BtnInfo"); });
- //}
- if (btn != null) {
- mAddListenerComList.Add (btn);
- btn.onClick.AddListener (new UnityEngine.Events.UnityAction (() => {
-
- if (BattleMgr.Instance.IsRotatingCam) return;
-
- if (UIEventStatus) return;
-
- UIEventStatus = true;
- timerSeq = TimerManager.Instance.AddTimer (interTime, 1, ResetUIEventStatus);
- ClickButton (btn);
- listener.Call (table, btn);
- }));
- }
- }
- public void AddButtonEventListener (Button btn, ButtonListenerWithParam listener, params object[] param) {
- if (btn != null) {
- mAddListenerComList.Add (btn);
- btn.onClick.AddListener (new UnityEngine.Events.UnityAction (() => {
- if (BattleMgr.Instance.IsRotatingCam) return;
- if (UIEventStatus) return;
- UIEventStatus = true;
- timerSeq = TimerManager.Instance.AddTimer (interTime, 1, ResetUIEventStatus);
- ClickButton (btn);
- listener (btn, param);
- }));
- }
- }
- public void AddButtonEventListener (Button btn, LuaTable table, LuaFunction listener, params object[] param) {
- if (btn != null) {
- mAddListenerComList.Add (btn);
- btn.onClick.AddListener (new UnityEngine.Events.UnityAction (() => {
- if (BattleMgr.Instance.IsRotatingCam) return;
- if (UIEventStatus) return;
- UIEventStatus = true;
- timerSeq = TimerManager.Instance.AddTimer (interTime, 1, ResetUIEventStatus);
- ClickButton (btn);
- listener.Call (table, btn, param);
- }));
- }
- }
- public void AddButtonUniqueEventListener (Button btn, LuaTable table, LuaFunction listener, params object[] param) {
- if (btn != null) {
- mAddListenerComList.Add (btn);
- btn.onClick.RemoveAllListeners ();
- btn.onClick.AddListener (new UnityEngine.Events.UnityAction (() => {
- if (BattleMgr.Instance.IsRotatingCam) return;
- ClickButton (btn);
- listener.Call (table, btn, param);
- }));
- }
- }
- public void AddToggleEventListener (Toggle tog, ToggleListener listener) {
- if (tog != null) {
- mAddListenerComList.Add (tog);
- tog.onValueChanged.AddListener (new UnityEngine.Events.UnityAction<bool> ((b) => {
- if (BattleMgr.Instance.IsRotatingCam) return;
- if (b)
- ClickToggle (tog);
- listener (b);
- }));
- }
- }
- public void AddToggleEventListener (Toggle tog, LuaFunction listener) {
- if (tog != null) {
- mAddListenerComList.Add (tog);
- tog.onValueChanged.AddListener (new UnityEngine.Events.UnityAction<bool> ((b) => {
- if (BattleMgr.Instance.IsRotatingCam) return;
- if (b && !tog.isOn)
- {
- ClickToggle(tog);
- }
- listener.Call (b);
- }));
- }
- }
- public void AddToggleEventListener (Toggle tog, ToggleListenerWithParams listener, params object[] param) {
- if (tog != null) {
- mAddListenerComList.Add (tog);
- tog.onValueChanged.AddListener (new UnityEngine.Events.UnityAction<bool> ((b) => {
- if (BattleMgr.Instance.IsRotatingCam) return;
- if (b)
- ClickToggle (tog);
- listener (tog, param);
- }));
- }
- }
- public void AddToggleEventListener (Toggle tog, LuaTable luaTbl, LuaFunction listener, object param) {
- if (tog != null) {
- mAddListenerComList.Add (tog);
- tog.onValueChanged.AddListener (new UnityEngine.Events.UnityAction<bool> ((b) => {
- if (BattleMgr.Instance.IsRotatingCam) return;
- if (b && !tog.isOn) {
- ClickToggle (tog);
- }
- listener.Call (luaTbl, tog, param, b);
- }));
- }
- }
- public void AddToggleUniqueEventListener(Toggle tog, LuaTable luaTbl, LuaFunction listener, params object[] param)
- {
- if (tog != null)
- {
- mAddListenerComList.Add(tog);
- tog.onValueChanged.RemoveAllListeners();
- tog.onValueChanged.AddListener(new UnityEngine.Events.UnityAction<bool>((b) => {
- if (BattleMgr.Instance.IsRotatingCam) return;
- if (b && !tog.isOn)
- {
- ClickToggle(tog);
- }
- listener.Call(luaTbl, tog, param, b);
- }));
- }
- }
- public void AddToggleEventListener (Toggle tog, LuaFunction listener, params object[] param) {
- if (tog != null) {
- mAddListenerComList.Add (tog);
- tog.onValueChanged.AddListener (new UnityEngine.Events.UnityAction<bool> ((b) => {
- if (BattleMgr.Instance.IsRotatingCam) return;
- if (b && !tog.isOn)
- {
- ClickToggle(tog);
- }
- listener.Call (tog, param, b);
- }));
- }
- }
- public void AddSliderEventListener (Slider slider, LuaTable luaTbl, LuaFunction listener, params object[] param) {
- if (slider != null) {
- mAddListenerComList.Add (slider);
- slider.onValueChanged.AddListener (new UnityEngine.Events.UnityAction<float> ((b) => {
- if (BattleMgr.Instance.IsRotatingCam) return;
- listener.Call (luaTbl, slider, b, param);
- }));
- }
- }
- public void AddSliderUniqueEventListener(Slider slider, LuaTable luaTbl, LuaFunction listener, params object[] param) {
- if (slider != null) {
- mAddListenerComList.Add (slider);
- slider.onValueChanged.RemoveAllListeners();
- slider.onValueChanged.AddListener (new UnityEngine.Events.UnityAction<float> ((b) => {
- if (BattleMgr.Instance.IsRotatingCam) return;
- listener.Call (luaTbl, slider, b, param);
- }));
- }
- }
- public void AddInputFileEventListener (InputField inputField, LuaFunction listener) {
- if (inputField != null) {
- mAddListenerComList.Add (inputField);
- inputField.onValueChanged.AddListener (new UnityEngine.Events.UnityAction<string> ((str) => {
- if (BattleMgr.Instance.IsRotatingCam) return;
- listener.Call (inputField, str);
- }));
- }
- }
- public void AddTMPInputFileEventListener(TMP_InputField inputField, LuaFunction listener)
- {
- if (inputField != null)
- {
- mAddListenerComList.Add(inputField);
- inputField.onValueChanged.AddListener(new UnityEngine.Events.UnityAction<string>((str) => {
- listener.Call(inputField, str);
- }));
- }
- }
- public void AddDropdownEventListener (Dropdown dropdown, LuaFunction listener) {
- if (dropdown != null) {
- mAddListenerComList.Add (dropdown);
- dropdown.onValueChanged.AddListener (new UnityEngine.Events.UnityAction<int> ((value) => {
- if (BattleMgr.Instance.IsRotatingCam) return;
- listener.Call (dropdown, value);
- }));
- }
- }
- public void AddUIEventHandlerClickListener (UIEventHandler handler, LuaFunction listener) {
- if (handler == null) return;
- handler.onClick.AddListener (new UnityEngine.Events.UnityAction<GameObject> ((value) => {
- if (BattleMgr.Instance.IsRotatingCam) return;
- listener.Call (value);
- }));
- }
- public void AddScrollRectValueChangeListener (ScrollRect scrollRect, LuaTable luaTbl, LuaFunction listener) {
- if (scrollRect == null) return;
- scrollRect.onValueChanged.AddListener (new UnityEngine.Events.UnityAction<Vector2> ((value) => {
- if (BattleMgr.Instance.IsRotatingCam) return;
- listener.Call (luaTbl, scrollRect, value);
- }));
- }
- public void InvokeToggle (Toggle tog, bool isOn) {
- if (tog != null) tog.onValueChanged.Invoke (isOn);
- }
- public GameObject FindChildGo(string childName)
- {
- if (mChildGoes == null) return null;
- GameObject go;
- mChildGoes.TryGetValue(childName, out go);
- return go;
- }
- void ClickButton (Button btn) {
- //处理点击button的通用行为
- if (btn != null)
- {
- UIPlaySound holder = null;
- if (!mBtnClickSoundHolderDict.TryGetValue(btn, out holder))
- {
- holder = btn.gameObject.GetComponent<UIPlaySound>();
- mBtnClickSoundHolderDict.Add(btn, holder);
- }
- if (holder != null)
- {
- holder.OnClick();
- }
- else
- {
- MusicMgr.Instance.PlayUISound(UIPlaySound.CommonClickSound, false);
- }
- }
- else
- {
- MusicMgr.Instance.PlayUISound(UIPlaySound.CommonClickSound, false);
- }
- }
- void ClickToggle (Toggle tog)
- {
- //处理点击button的通用行为
- if (tog != null)
- {
- UIPlaySound holder = null;
- if (!mBtnClickSoundHolderDict.TryGetValue(tog, out holder))
- {
- holder = tog.gameObject.GetComponent<UIPlaySound>();
- mBtnClickSoundHolderDict.Add(tog, holder);
- }
- if (holder != null)
- {
- holder.OnClick();
- }
- else
- {
- MusicMgr.Instance.PlayUISound(UIPlaySound.CommonClickSound, false);
- }
- }
- else
- {
- MusicMgr.Instance.PlayUISound(UIPlaySound.CommonClickSound, false);
- }
- }
- #endregion
- }
|