private void SetSiblingIndex(UIWindowBase window, Transform root) { window.transform.SetAsLastSibling(); for (int i = 0; i < root.childCount; i++) { Transform tf = root.GetChild(i); UIWindowBase tw = tf.GetComponent <UIWindowBase>(); if (tw != null && tw != window && window.windowData.siblingNum < tw.windowData.siblingNum) { window.transform.SetSiblingIndex(tw.transform.GetSiblingIndex()); return; } } }
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)); }); } }