--[[ --通用UI管理器 界面相关接口以UIView的路径名作为键,不再使用预置体的路径名 界面相关接口: 1、UIManager.OpenView 2、UIManager.OpenAndPush 3、UIManager.OpenAndPushAll 4、UIManager.IsViewOpened 5、UIManager.RecoverView 6、UIManager.RecoverTopView 子界面相关接口: 1、self.subViewRoot:OpenView 2、self.subViewRoot:IsViewOpened --]] local UIManager = {} local EventSystem = require('Event/EventSystem') local UIView = require('View/UIView') local GetViewClass = UIView.GetViewClass rawset(_G, 'UIViewClass', UIView.CreateViewClass) rawset(_G, 'GetViewClass', GetViewClass) rawset(_G, 'UIEventTriggerType', UIView.UIEventTriggerType) local IPhoneNotchSize = { ["DEFAULT"] = 88, ["iPhone 11"] = 70, ["iPhone XR"] = 70, ["iPhone XS Max"] = 93, ["iPhone X"] = 93, } local _rootUICanvas local _rootUICamera local specialCanvasRoot = nil local _recoveringTopView = false --记录显示关闭场景名字界面的统计 local ClosePlayerNamePanelCount = 0 --为了定位activeUIModule计数错误添加的日志,定位完成后可以删除 local _uiActiveUIModuleTag = {} --初始化 do local rootObj = UnityEngine.GameObject.Find("UIRootCanvas") _rootUICanvas = rootObj:GetComponent(typeof(Tai.Lua.UIScriptableCanvas)) specialCanvasRoot = UnityEngine.GameObject.Find("UIRootCanvas/SpecialCanvasRoot"):GetComponent(typeof(Tai.Lua.UIScriptableCanvas)) _rootUICamera = UnityEngine.GameObject.Find("UIRootCanvas/Camera"):GetComponent(typeof(UnityEngine.Camera)) CSExt.SetViewEntryFunc(UIView.ViewEntryFunc) end function UIManager.OnShutdown() UIManager.CloseAll(true) CSExt.SetViewEntryFunc(nil) end function UIManager.GetIPhoneNotchSize(deviceName) return IPhoneNotchSize[deviceName] or IPhoneNotchSize["DEFAULT"] end function UIManager.GetUIMainCamera() return _rootUICamera end function UIManager.CallViewFunction(classPath, funcName, ...) local view = _rootUICanvas:GetOpenedView(classPath) if view then return view[funcName](view, ...) end return nil end --@param classPath 逻辑类接口 --@param context 界面参数 --@param prefabPath 可选参数,传空则表示prefabPath与classPath相同 function UIManager.OpenView(classPath, context, prefabPath) local viewClass = GetViewClass(classPath) local view = _rootUICanvas:OpenView(viewClass, context, prefabPath, classPath) return view end --@param classPath 逻辑类接口 --@param context 界面参数 --@param pushclassPath 要push的界面名字 --@param prefabPath 可选参数,传空则表示prefabPath与classPath相同 function UIManager.OpenAndPush(classPath, context, prefabPath, pushClassPath) local viewClass = GetViewClass(classPath) local view = _rootUICanvas:OpenAndPush(viewClass, context, prefabPath, classPath, pushClassPath) return view end --@param classPath 逻辑类接口 --@param context 界面参数 --@param prefabPath 可选参数,传空则表示prefabPath与classPath相同 function UIManager.OpenAndPushAll(classPath, context, prefabPath) _rootUICanvas:PushAll() local viewClass = GetViewClass(classPath) local view = _rootUICanvas:OpenView(viewClass, context, prefabPath, classPath) return view end --是否打开一个界面 function UIManager.IsViewOpened(classPath, isCheckSpecialView) if isCheckSpecialView then return specialCanvasRoot:IsViewOpened(classPath) else return _rootUICanvas:IsViewOpened(classPath) end end function UIManager.FindViewTransform(classPath, path, inchildren) local view if inchildren then view = _rootUICanvas:GetOpenedViewInChildren(classPath) else view = _rootUICanvas:GetOpenedView(classPath) end if view then local transf = view.gameObject.transform if path then return transf:Find(path) else return transf end end end function UIManager.RecoverView() _rootUICanvas:RecoverView() end function UIManager.RecoverTopView() if not _recoveringTopView then _recoveringTopView = true _rootUICanvas:RecoverTopView() _recoveringTopView = false else logging.error(LTAG.ERROR,"error RecoverTopView") end end function UIManager.PushView(go) _rootUICanvas:PushView(go) end function UIManager.PushAllAndRecoverView() _rootUICanvas:PushAll() UIManager.RecoverView() end --关闭ui --@param classpath class路径 function UIManager.CloseView(classPath) _rootUICanvas:CloseView(classPath) end function UIManager.CloseViewByLayer(layer) _rootUICanvas:CloseViewByLayer(layer) end --关闭所有界面 --一般退出登录的时候调用 function UIManager.CloseAll(immediate) _rootUICanvas:CloseAll(immediate or false) if specialCanvasRoot then specialCanvasRoot:CloseAll(immediate or false) end end function UIManager.IsFocus(classPath) return _rootUICanvas:IsFocus(classPath) end --关闭所有界面 除了modelui 界面 loading的时候调用 function UIManager.CloseAllBase() _rootUICanvas:CloseAll() end function UIManager.SetLayerActive(uiLayer, active) _rootUICanvas:SetLayerActive(uiLayer, active) end function UIManager.SetAllLayerActive(active) UIManager.ActiveUIModle(active, "TimeLineActive") UIManager.SetLayerActive(Const_UI_Lua.UILayers.UIBackground, active) UIManager.SetLayerActive(Const_UI_Lua.UILayers.UIDefault, active) UIManager.SetLayerActive(Const_UI_Lua.UILayers.UIPopup, active) UIManager.SetLayerActive(Const_UI_Lua.UILayers.UIForeground, active) UIManager.SetLayerActive(Const_UI_Lua.UILayers.UIBottom, active) end function UIManager.OnOrientationChange(screenOrientation) EventSystem.Dispatch(EventID.UI_OnOrientationChange, screenOrientation) end function UIManager.OnBackButtonPressed() _rootUICanvas:HandleBackButtonPressed() end -----------处理特殊界面 比如uimodel uidebugview 这些界面不能隐藏或者关闭 --@param classPath 逻辑类接口 --@param context 界面参数 --@param prefabPath 可选参数,传空则表示prefabPath与classPath相同 function UIManager.OpenSpecialView(classPath, context, prefabPath) if not specialCanvasRoot:IsViewOpened(classPath) then local viewClass = GetViewClass(classPath) specialCanvasRoot:OpenView(viewClass, context, prefabPath, classPath) end end function UIManager.CloseSpecialView(classPath) specialCanvasRoot:CloseView(classPath) end function UIManager.ActiveUIModle(active, srcTag) if srcTag then --srcTag,调用此方法的源,每个源正常应该只存在一次,不应该多次 if active then if not _uiActiveUIModuleTag[srcTag] then logging.error(LTAG.ERROR, "应该有该tag的的标志", srcTag) end _uiActiveUIModuleTag[srcTag] = nil else if _uiActiveUIModuleTag[srcTag] then logging.error(LTAG.ERROR, "不应该有该tag的的标志", srcTag) end _uiActiveUIModuleTag[srcTag] = true end else logging.error(LTAG.ERROR, "srcTag不能为空") end if active then ClosePlayerNamePanelCount = ClosePlayerNamePanelCount-1 if ClosePlayerNamePanelCount<0 then logging.error(LTAG.ERROR, "UIManager.ActiveUIModle计数错误") ClosePlayerNamePanelCount = 0 end if ClosePlayerNamePanelCount == 0 then EventSystem.Dispatch(EventID.UI_ActiveAllModelElement, active) end else ClosePlayerNamePanelCount = ClosePlayerNamePanelCount+1 if ClosePlayerNamePanelCount == 1 then EventSystem.Dispatch(EventID.UI_ActiveAllModelElement, active) AuxUtil.SetShowUIBloodBar(false) end end end function UIManager.CheckActiveUIModleTags() for tag, __ in pairs(_uiActiveUIModuleTag) do logging.error(LTAG.ERROR, "切换场景的时候,不应该有未清理的tag", tag) _uiActiveUIModuleTag[tag] = nil end if ClosePlayerNamePanelCount>0 then logging.error(LTAG.ERROR, "切换场景的时候,ClosePlayerNamePanelCount应该为0", ClosePlayerNamePanelCount) end ClosePlayerNamePanelCount = 0 --切完场景应该限制显示名字 EventSystem.Dispatch(EventID.UI_ActiveAllModelElement, true) end --PC-Cheat,进入模式 function UIManager.EnterCheatModel(isEnter) UI3DModelComponent.IsCheatModel = isEnter UIModelComponent.IsCheatModel = isEnter AuxUtil.SetActiveLayerCameraLockUI(not isEnter) UIManager.SetLayerActive(Const_UI_Lua.UILayers.UIBackground, not isEnter) UIManager.SetLayerActive(Const_UI_Lua.UILayers.UIDefault, not isEnter) UIManager.SetLayerActive(Const_UI_Lua.UILayers.UIForeground, not isEnter) UIManager.SetLayerActive(Const_UI_Lua.UILayers.UIBottom, not isEnter) EventSystem.Dispatch(EventID.UI_EnterCheatModel, isEnter) end local LoopCellTableMT = { __newindex = function() logging.error(LTAG.ERROR, k, v, "请不要对好不容易被保护起来的cellTable进行额外的赋值操作") end } function UIManager.CreateProtectedCellTable() return setmetatable({}, LoopCellTableMT) end return UIManager