/// <summary> /// 如果正在显示,不做处理 /// 如果在hide ,显示出来 /// 其他情况就创建一个新的 /// </summary> /// <param name="type"></param> /// <returns></returns> public async Task <UI> CreateAsync(string type) { UI ui = Get(type); if (ui != null && ui.UiComponent.InShow) { return(ui); } //打开遮罩,阻挡点击事件,只有一个控件,很快的 UI uiEventMask = await CreateUIEventMask(); await semaphoreSlim.WaitAsync(); bool isRelease = false; //信号量释放后要重新刷新堵塞前的状态 ui = Get(type); if (ui != null && ui.UiComponent.InShow) { ReleaseRelated(uiEventMask, ref isRelease); return(ui); } try { if (ui == null) { //ui = UiTypes[type].Create(this.GetParent<Scene>(), type, Root); ui = await uiFactory.CreateAsync(type); uis.Add(type, ui); } if (ui.GameObject == null) { ZLog.Error(type + "CreateAsync ui.GameObject==null"); //return null; } else { SetViewParent(ui, ui.GameObject.GetComponent <CanvasConfig>()?.CanvasName); ui.ShowUI(); AddCanvas(ui.GameObject); } //热更层不会走finally,所有这里直接释放掉 ReleaseRelated(uiEventMask, ref isRelease); return(ui); } catch (Exception e) { throw new Exception($"{type} UI 错误: {e}"); } finally { ReleaseRelated(uiEventMask, ref isRelease); } }