public QUIBehaviour OpenUI<T>(QUILevel canvasLevel,string bundleName,object uiData = null) where T : QUIBehaviour { string behaviourName = typeof(T).ToString(); if (!mAllUI.ContainsKey(behaviourName)) { return CreateUI<T>(canvasLevel,bundleName,uiData); } mAllUI [behaviourName].Show (); return mAllUI[behaviourName]; }
/// <summary> /// 增加UI层 /// </summary> public QUIBehaviour CreateUI<T> (QUILevel level,string bundleName,object uiData = null) where T : QUIBehaviour { string behaviourName = typeof(T).ToString(); if (mAllUI.ContainsKey (behaviourName)) { Debug.LogWarning(behaviourName + ": already exist"); mAllUI [behaviourName].transform.localPosition = Vector3.zero; mAllUI [behaviourName].transform.localEulerAngles = Vector3.zero; mAllUI [behaviourName].transform.localScale = Vector3.one; mAllUI [behaviourName].Enter (uiData); } else { GameObject prefab = Resources.Load<GameObject> (behaviourName); GameObject mUIGo = Instantiate (prefab); switch (level) { case QUILevel.Bg: mUIGo.transform.SetParent (mBgTrans); break; case QUILevel.Common: mUIGo.transform.SetParent (mCommonTrans); break; case QUILevel.PopUI: mUIGo.transform.SetParent (mPopUITrans); break; case QUILevel.Const: mUIGo.transform.SetParent (mConstTrans); break; case QUILevel.Toast: mUIGo.transform.SetParent (mToastTrans); break; case QUILevel.Forward: mUIGo.transform.SetParent (mForwardTrans); break; } mUIGo.transform.localPosition = Vector3.zero; mUIGo.transform.localEulerAngles = Vector3.zero; mUIGo.transform.localScale = Vector3.one; mUIGo.gameObject.name = behaviourName; Debug.Log(behaviourName + " Load Success"); T t = mUIGo.AddComponent<T>(); mAllUI.Add (behaviourName, t); t.Init (uiData); } return mAllUI [behaviourName]; }
/// <summary> /// Create&ShowUI /// </summary> public T OpenUI <T>(QUILevel canvasLevel, string bundleName, object uiData = null) where T : QUIBehaviour { string behaviourName = typeof(T).ToString(); QUIBehaviour ui; if (!mAllUI.TryGetValue(behaviourName, out ui)) { ui = CreateUI <T>(canvasLevel, bundleName, uiData); } ui.Show(); return(ui as T); }
/// <summary> /// Create&ShowUI /// </summary> public T OpenUI <T>(QUILevel canvasLevel, QUIData uiData = null) where T : QUIBehaviour { string behaviourName = GetUIBehaviourName <T> (); QUIBehaviour ui; if (!mAllUI.TryGetValue(behaviourName, out ui)) { ui = CreateUI <T>(canvasLevel, uiData); } ui.Show(); return(ui as T); }
/// <summary> /// 增加UI层 /// </summary> public T CreateUI <T>(QUILevel level, string bundleName, object initData = null) where T : QUIBehaviour { string behaviourName = typeof(T).ToString(); QUIBehaviour ui; if (mAllUI.TryGetValue(behaviourName, out ui)) { Debug.LogWarning(behaviourName + ": already exist"); //直接返回,不要再调一次Init(),Init()应该只能调用一次 return(ui as T); } GameObject prefab = QResourceManager.Instance.LoadAsset <GameObject> (bundleName, behaviourName); GameObject mUIGo = Instantiate(prefab); switch (level) { case QUILevel.Bg: mUIGo.transform.SetParent(mBgTrans); break; case QUILevel.Common: mUIGo.transform.SetParent(mCommonTrans); break; case QUILevel.PopUI: mUIGo.transform.SetParent(mPopUITrans); break; case QUILevel.Const: mUIGo.transform.SetParent(mConstTrans); break; case QUILevel.Toast: mUIGo.transform.SetParent(mToastTrans); break; case QUILevel.Forward: mUIGo.transform.SetParent(mForwardTrans); break; } var uiGoRectTrans = mUIGo.GetComponent <RectTransform> (); uiGoRectTrans.offsetMin = Vector2.zero; uiGoRectTrans.offsetMax = Vector2.zero; uiGoRectTrans.anchoredPosition3D = Vector3.one; uiGoRectTrans.anchorMin = Vector2.zero; uiGoRectTrans.anchorMax = Vector2.one; mUIGo.transform.localScale = Vector3.one; mUIGo.gameObject.name = behaviourName; Debug.Log(behaviourName + " Load Success"); ui = mUIGo.AddComponent <T>(); mAllUI.Add(behaviourName, ui); ui.Init(initData); return(ui as T); }