【屏幕适配】CanvasScaler添加到config
parent
db5a0557ea
commit
53912b5384
|
@ -7,6 +7,7 @@ ServerConfigManager.SettingConfig = {
|
|||
ThinkAnalysis_GetDeviceID = "ThinkAnalysis_GetDeviceID", -- 数数获取DeviceID方法
|
||||
LayoutBuilderWrap = "LayoutBuilderWrap", -- 强制刷新layout组件大小的方法修改到lua中调用
|
||||
LanguagePackager = "LanguagePackager", -- 本地化处理
|
||||
UI_Layout_CanvasScaler = "UI_Layout_CanvasScaler", -- 本地化处理
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -62,7 +62,10 @@ function UIManager.Initialize()
|
|||
gameObj.name = "UIRoot"
|
||||
this.eventSystem = GameObject.Find("EventSystem")
|
||||
this.uiRoot = gameObj
|
||||
this.canvasScaler = gameObj.transform:Find("UIRoot"):GetComponent("CanvasScaler")
|
||||
this.isCanvasScaler = ServerConfigManager.IsSettingActive(ServerConfigManager.SettingConfig.UI_Layout_CanvasScaler)
|
||||
if this.isCanvasScaler then
|
||||
this.canvasScaler = gameObj.transform:Find("UIRoot"):GetComponent("CanvasScaler")
|
||||
end
|
||||
this.uiNode = gameObj.transform:Find("UIRoot/UINode")
|
||||
this.fullNode = gameObj.transform:Find("UIRoot/FullNode")
|
||||
this.fixedNode = gameObj.transform:Find("UIRoot/FixedNode")
|
||||
|
@ -122,8 +125,9 @@ function UIManager.Adapter()
|
|||
-- 屏幕大小
|
||||
UIManager.width = Screen.width
|
||||
UIManager.height = Screen.height
|
||||
|
||||
this.canvasScaler.matchWidthOrHeight = 0.5
|
||||
if this.isCanvasScaler then
|
||||
this.canvasScaler.matchWidthOrHeight = 0.5
|
||||
end
|
||||
|
||||
-- 计算屏幕比例的比值,用于部分界面进行屏幕适配的缩放
|
||||
UIManager.adapterScale = (1920/1080)/(Screen.height / Screen.width)
|
||||
|
@ -166,7 +170,10 @@ function UIManager.Adapter()
|
|||
elseif n < standard then
|
||||
-- 计算屏幕比例的比值,用于部分界面进行屏幕适配的缩放
|
||||
UIManager.adapterScale = 1
|
||||
this.canvasScaler.matchWidthOrHeight = 1
|
||||
|
||||
if this.isCanvasScaler then
|
||||
this.canvasScaler.matchWidthOrHeight = 1
|
||||
end
|
||||
|
||||
|
||||
-- 实际分辨率 = 屏幕分辨率 / 比例因子
|
||||
|
|
Loading…
Reference in New Issue