public void CloseForm(UIFormBase form) { if (form == null) { return; } UIFormTableSetting config = form.Table; //设置显示逻辑 UIFormsShowMode mode = (UIFormsShowMode)config.ShowMode; if (!dicForms.ContainsKey(mode)) { dicForms[mode] = new List <UIFormBase>(); GameObject modeRoot = new GameObject(mode.ToString()); modeRoot.transform.SetParent(uiCamera); modeRoot.transform.localPosition = Vector3.zero; modeRoot.transform.localScale = Vector3.one; modeRoot.transform.localEulerAngles = Vector3.zero; dicFormRoots.Add(mode, modeRoot); } List <UIFormBase> formList = null; UIFormBase nextForm = null; int index = 1; switch (mode) { case UIFormsShowMode.Pop: formList = dicForms[mode]; //关闭的窗口并不是当前显示的窗口 if (form.State == UIFormState.Hide || form.gameObject.activeSelf == false) { break; } //寻找下个可以显示的窗口 while (nextForm == null && formList.Count > index) { if (formList[formList.Count - 1 - index] != null && formList[formList.Count - 1 - index].State == UIFormState.Show) { nextForm = formList[formList.Count - 1 - index]; } else { index++; } } if (nextForm != null) { nextForm.Resume(); } break; case UIFormsShowMode.HideOther: formList = dicForms[mode]; //关闭的窗口并不是当前显示的窗口 if (form.State == UIFormState.Hide || form.gameObject.activeSelf == false) { break; } //寻找下个可以显示的窗口 while (nextForm == null && formList.Count > index) { if (formList[formList.Count - 1 - index] != null && formList[formList.Count - 1 - index].State == UIFormState.Show) { nextForm = formList[formList.Count - 1 - index]; } else { index++; } } if (nextForm == null) { for (int i = 0; i < dicForms[UIFormsShowMode.Normal].Count; i++) { dicForms[UIFormsShowMode.Normal][i].Resume(); } } if (nextForm != null) { nextForm.Resume(); } break; case UIFormsShowMode.Single: formList = dicForms[mode]; //关闭的窗口并不是当前显示的窗口 if (form.State == UIFormState.Hide || form.gameObject.activeSelf == false) { break; } while (nextForm == null && formList.Count > index) { if (formList[formList.Count - 1 - index] != null && formList[formList.Count - 1 - index].State == UIFormState.Show) { nextForm = formList[formList.Count - 1 - index]; } else { index++; } } //非独占,都显示弹窗 if (nextForm == null) { if (dicForms[UIFormsShowMode.Pop].Count > 0) { dicForms[UIFormsShowMode.Pop][dicForms[UIFormsShowMode.Pop].Count - 1].Resume(); } } //寻找模式窗口 while (nextForm == null && dicForms[UIFormsShowMode.HideOther].Count > index) { UIFormBase formBase = dicForms[UIFormsShowMode.HideOther][formList.Count - 1 - index]; if (formBase != null && formBase.State == UIFormState.Show) { nextForm = formBase; } else { index++; } } //没有模式窗口,显示普通窗口 if (nextForm == null) { for (int i = 0; i < dicForms[UIFormsShowMode.Normal].Count; i++) { dicForms[UIFormsShowMode.Normal][i].Resume(); } } if (nextForm != null) { nextForm.Resume(); } break; case UIFormsShowMode.Normal: default: formList = dicForms[UIFormsShowMode.Normal]; //关闭的窗口并不是当前显示的窗口 if (form.State == UIFormState.Hide || form.gameObject.activeSelf == false) { break; } while (nextForm == null && formList.Count > index) { if (formList[formList.Count - 1 - index] != null && formList[formList.Count - 1 - index].State == UIFormState.Show) { nextForm = formList[formList.Count - 1 - index]; } else { index++; } } if (nextForm != null) { nextForm.Resume(); } break; } //寻找剩下的有没有相同的,有就不销毁 int count = 0; index = 0; for (int i = 0; i < formList.Count; i++) { if (formList[i] == form) { count++; index = i; } } formList.RemoveAt(index); if (count > 1) { //Debug.LogError(form.Table.Id + ":" + form.Table.Name + "被重复打开了!"); form.Cover(); } else { form.Close(); GameObject.Destroy(form.gameObject); Resources.UnloadUnusedAssets(); GC.Collect(); } }
void ProcessForm(UIFormBase form, UIFormTableSetting config, object userdata, bool isOld) { //设置层级 UIPanel[] panels = form.transform.GetComponentsInChildren <UIPanel>(true); List <UIPanel> sortedPanels = new List <UIPanel>(panels); sortedPanels.Sort((p1, p2) => p1.depth.CompareTo(p2.depth)); UIFormsGroup group = (UIFormsGroup)config.Group; for (int i = 0; i < sortedPanels.Count; i++) { if (!baseDepths.ContainsKey(group)) { baseDepths[group] = config.Group * 1000 * 1000; } sortedPanels[i].depth = baseDepths[group] + i; } form.StartDepth = baseDepths[group]; baseDepths[group] += panels.Length; //设置显示逻辑 UIFormsShowMode mode = (UIFormsShowMode)config.ShowMode; form.transform.SetParent(dicFormRoots[mode].transform); form.transform.localPosition = Vector3.zero; form.transform.localScale = Vector3.one; form.transform.localEulerAngles = Vector3.zero; List <UIFormBase> formList = null; switch (mode) { case UIFormsShowMode.Pop: formList = dicForms[mode]; if (formList.Count > 0 && formList[formList.Count - 1] != null) { formList[formList.Count - 1].Cover(); } form.Init(config, userdata); formList.Add(form); if (dicForms[UIFormsShowMode.Single].Count > 0) { form.Cover(); } break; case UIFormsShowMode.HideOther: formList = dicForms[mode]; for (int i = 0; i < dicForms[UIFormsShowMode.HideOther].Count; i++) { dicForms[UIFormsShowMode.HideOther][i].Cover(); } for (int i = 0; i < dicForms[UIFormsShowMode.Normal].Count; i++) { dicForms[UIFormsShowMode.Normal][i].Cover(); } form.Init(config, userdata); formList.Add(form); if (dicForms[UIFormsShowMode.Single].Count > 0) { form.Cover(); } break; case UIFormsShowMode.Single: formList = dicForms[mode]; for (int i = 0; i < dicForms[UIFormsShowMode.HideOther].Count; i++) { dicForms[UIFormsShowMode.HideOther][i].Cover(); } for (int i = 0; i < dicForms[UIFormsShowMode.Normal].Count; i++) { dicForms[UIFormsShowMode.Normal][i].Cover(); } for (int i = 0; i < dicForms[UIFormsShowMode.Pop].Count; i++) { dicForms[UIFormsShowMode.Pop][i].Cover(); } form.Init(config, userdata); formList.Add(form); break; case UIFormsShowMode.Normal: default: formList = dicForms[UIFormsShowMode.Normal]; form.Init(config, userdata); formList.Add(form); if (dicForms[UIFormsShowMode.HideOther].Count > 0) { form.Cover(); } if (dicForms[UIFormsShowMode.Single].Count > 0) { form.Cover(); } break; } }