private UIControllerBase PrepareUI(WindowID id, WindowContextDataBase showContextData = null) { if (!this.IsWindowRegistered(id)) { return(null); } if (dicShownWindows.ContainsKey((int)id)) { return(null); } UIControllerBase baseController = GetGameWindowFromCache(id); //UI没有在场景里打开过, Instantiate New One bool newAdded = false; if (baseController == null) { newAdded = true; if (UIResourceDefine.windowPrefabPath.ContainsKey((int)id)) { //实例化UI UIViewBase uiView = GameUIUtility.InstantiateUI(id); //保存Controller baseController = uiView.Controller; dicWindowsCache[(int)id] = baseController; //初始化 baseController.OnInit(); //设置UI根 Transform targetRoot = GameUIUtility.GetUIRoot();//UINormalWindowRoot; GameUIUtility.AddChildToTarget(targetRoot, uiView.gameObject.transform); //设置UI Camera Canvas uiCanvas = uiView.gameObject.GetComponent <Canvas>(); uiCanvas.renderMode = RenderMode.ScreenSpaceCamera; { GameObject uiCamera = GameObject.Find("UICamera"); if (uiCamera != null) { uiCanvas.worldCamera = uiCamera.GetComponent <Camera>(); } } //添加通用背景 AddColliderBgForWindow(uiView); } else { Debug.LogError("UI ID对应的Prefab位置在找不到, 使用工具重新生成 " + id); return(null); } } if (baseController == null) { Debug.LogError("[UI instance is null.]" + id.ToString()); } //设置导航信息, 如果是导航类型的UI会把当前显示的UI关闭并且保存到BackSequenceStack里面 //下次返回的时候, 从Stack里面回复. if (showContextData == null || (showContextData != null && showContextData.executeNavLogic)) { ExecuteNavigationLogic(baseController); } //层级管理 //AdjustBaseWindowDepth(baseController); return(baseController); }