private IEnumerator ConfigureWindow(GameObject go, UISettings.UIWindowID id, bool needTransform = true, System.Action onComplate = null, params object[] data) { UIWindowBase window; allWindows.TryGetValue(id, out window); if (window == null) { GameObject windowGO = GameObject.Instantiate(go); windowGO.name = id.ToString(); windowGO.layer = LayerMask.NameToLayer("UI"); windowGO.SetActive(false); window = windowGO.GetComponent <UIWindowBase>(); UIWindowData windowData = window.windowData; if (windowData.id != id) { Debug.LogError("加载的window id和目标id不符"); } allWindows.Add(windowData.id, window); } RectTransform rt = window.transform as RectTransform; switch (window.windowData.type) { case UISettings.UIWindowType.Fixed: window.gameObject.transform.SetParent(FixedRoot); rt.anchorMin = Vector2.zero; rt.anchorMax = Vector2.one; rt.offsetMin = Vector2.zero; rt.offsetMax = Vector2.one; break; case UISettings.UIWindowType.PopUp: window.transform.SetParent(PopUpRoot); break; case UISettings.UIWindowType.Cover: window.transform.SetParent(CoverRoot); rt.anchorMin = Vector2.zero; rt.anchorMax = Vector2.one; rt.offsetMin = Vector2.zero; rt.offsetMax = Vector2.one; break; } window.transform.localPosition = Vector3.zero; window.transform.localScale = Vector3.one; //(window.transform as RectTransform).anchoredPosition = Vector2.zero; window.Init(); yield return(null); if (windowsState[id]) { StartOpenWindow(id, needTransform, onComplate, data); } else { isOpening = false; } }
public void CloseWindow(UISettings.UIWindowID id, bool needTransform = true, System.Action onComplate = null) { SetWindowState(id, false); UIWindowBase window; allWindows.TryGetValue(id, out window); if (window != null) { if (showingWindows.ContainsKey(id)) { showingWindows.Remove(id); } popupCollider.GetComponent <FadeIn>().to = 0; window.HideWindow(() => { UIWindowData windowdata = window.windowData; if (windowdata.type == UISettings.UIWindowType.Fixed) { } else if (windowdata.type == UISettings.UIWindowType.PopUp) { curPopUpWindow = null; popupCollider.SetActive(false); for (int i = PopUpRoot.childCount - 1; i >= 0; i--) { Transform tf = PopUpRoot.GetChild(i); if (tf.gameObject.activeSelf) { UIWindowBase wd = tf.GetComponent <UIWindowBase>(); if (wd != null) { popupCollider.SetActive(true); curPopUpWindow = wd; popupCollider.transform.SetSiblingIndex(Mathf.Max(0, i - 1)); break; } } } } if (onComplate != null) { onComplate(); } Messenger.Broadcast <UISettings.UIWindowID>(ELocalMsgID.CloseUI, id); }, needTransform); } }
private void StartOpenWindow(UISettings.UIWindowID id, bool needTransform = true, System.Action onComplate = null, params object[] data) { isOpening = true; UIWindowBase window; allWindows.TryGetValue(id, out window); if (window != null) { if (!window.canOpen) { isOpening = false; return; } UIWindowData windowdata = window.windowData; if (windowdata.type == UISettings.UIWindowType.Fixed) { //window.transform.SetSiblingIndex(FixedRoot.childCount); SetSiblingIndex(window, FixedRoot); } else if (windowdata.type == UISettings.UIWindowType.PopUp) { curPopUpWindow = window; popupCollider.SetActive(true); popupCollider.transform.SetAsLastSibling(); SetSiblingIndex(window, PopUpRoot); //popupCollider.transform.SetSiblingIndex(PopUpRoot.childCount); // window.transform.SetSiblingIndex(PopUpRoot.childCount); if (window.windowData.colliderType == UISettings.UIWindowColliderType.Transparent) { popupCollider.GetComponent <Image>().color = new Color(0.8f, 0.8f, 0.8f, 0f); } else { popupCollider.GetComponent <Image>().color = new Color(0, 0, 0, 0f); popupCollider.GetComponent <FadeIn>().to = 0.4f; } //popupCollider.GetComponent<Image>().color = new Color(0.8f,0.8f,0.8f,0.5f); } else if (windowdata.type == UISettings.UIWindowType.Cover) { SetSiblingIndex(window, CoverRoot); } if (!showingWindows.ContainsKey(id)) { showingWindows.Add(id, window); } isOpening = false; Messenger.Broadcast <UISettings.UIWindowID>(ELocalMsgID.OpenUI, id); StartCoroutine(window.ShowWindow(() => { if (onComplate != null) { onComplate(); } }, needTransform, data)); } else { string path = FilePathTools.getUIPath(UISettings.GetWindowName(id)); AssetsManager.Instance.LoadAssetAsync <GameObject>(path, (go) => { StartCoroutine(ConfigureWindow(go, id, needTransform, onComplate, data)); }); } }