local Setting_Controller = {} local EventSystem = require('Event/EventSystem') local JSON = require("cjson") local LuaFuncEntry = require("Main/LuaFuncEntry") local private = { deviceLevel = 0, fpsLevel = 0, customVCullingCapacity = {}, enableCustomTerrainHeight = false, customTerrainHeight = 0, } local adaptiveQuality = { adaptCount = 0, } local LodLevelCustom, LodLevelHigh, LodLevelMid, LodLevelLow = -1, 2, 1, 0 local viewContent local LuaUpdater = require "Main/LuaUpdater" local DeviceLODSetting = require "Modules/Setting/DeviceLODSetting" local SettingHelper = require "Modules/Setting/SettingHelper" local ResolutionSaveKey = "ResolutionSaveKey" local iOSWhiteHeightArray = {1.5, 1, 1} local iOSDefaultHeightArray = {1.5, 1.5, 1} --非负整数,开启后替换生效的实体剔除容量 local ForceVisualCullingCapacity = nil --0 --拥有near, medium, far三个键的整数表,对应近中远三档容量值,开启后替换生效的特效剔除容量 local ForceEffectCullingCapacity = nil --{near = 0, medium = 0, far = 0} --[[ 可视单位的分值分布: 战斗模型 80 组合武将 40 NPC角色 35 PVP模型 25 骑兵 15 宝箱冲车 10 GPU小兵 2 空物体 0 --]] local VisualCullingCapacity = { [0] = 400, [1] = 480, [2] = 560, } local EffectCullingCapacity = { [0] = {near = 50, medium = 20, far = 10,}, [1] = {near = 75, medium = 30, far = 15,}, [2] = {near = 90, medium = 40, far = 20,}, } local MovieToStaticPicDevice = { --日本设备 ["LGE L-01K"] = true, ["LGE L-03K"] = true, ["LGE LGV36"] = true, ["SHARP 603SH"] = true, ["SHARP SH-01K"] = true, ["samsung SC-42A"] = true, ["KYOCERA KYV47"] = true, ["FUJITSU F-01L"] = true, --end } local lastSavePlayerInfo = nil local onlinePlayerJson = nil local isShowJPPanel = true Setting_Controller.UploadLogProblemType = { LoginFailed = "LoginFailed", CommonUpload = "CommonUpload", ClientService = "ClientService", } local function QuitCancle() NotSyncBattleSetter.PauseLevel(false) end function Setting_Controller.OnStartup() private.SetupEntryFunc(true) SettingHelper.Init() Setting_Controller.InitPCConfig() --如果是Win,默认帧率改为60 local defaultFpsLevel = GameAppInfo.IsPCOrMacPackage() and 1 or 0 if MDL.Setting.HasKey(LuaConst.SettingKeyEnum.FrameLimitation) then private.fpsLevel = MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.FrameLimitation) else private.fpsLevel = defaultFpsLevel end SettingHelper.ExecuteFrameSetting(private.fpsLevel) if GameAppInfo.IsPCOrMacPackage() then private.ReSetResolution() if GameAppInfo.IsVersionGreaterThan121000() then UIUtils.SetNarrationFontScale(0.7) end end --启动时将技能震动调整为玩家此前选择 if GameAppInfo.IsVersionGreaterThan110000() then SettingAPI.EnableCameraShake = MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.SkillCameraShake) end --主播PC包要一个1440*1080的分辨率,特殊处理一下 if CTL.WinLogin.IsGameStreamerPackage() then table.insert(LuaConst.SupportResolution, 4, {1440,1080}) end EventSystem.Regist(EventID.Setting_OnAdaptiveQualityTrigger, private.OnAdaptiveQualityTrigger) EventSystem.Regist(EventID.ApplicationPause, private.OnApplicationPause) EventSystem.Regist(EventID.AcquireSystemRedAfterUnlock, private.InitServerDataOver) EventSystem.Regist(EventID.UI_SDKUser_Unlock_Update, private.RefreshUserCustomFunc) end function private.SetupEntryFunc(isRegist) LuaFuncEntry.SetupMainEntryFunc(isRegist, LuaFuncEntry.FuncType.GetGCDuration, private.GetGCDuration, LuaFuncEntry.FuncType.GetNewMessageNum, Setting_Controller.GetNewMessageNum, LuaFuncEntry.FuncType.GetResolutionConfig, private.GetResolutionConfig, LuaFuncEntry.FuncType.GetHeroTransparentRenderQueue, private.GetHeroTransparentRenderQueue, LuaFuncEntry.FuncType.NetworkStateChange, MDL.Setting.SetNetworkState, LuaFuncEntry.FuncType.BatteryStatusChange, MDL.Setting.SetBatteryStatus, LuaFuncEntry.FuncType.BatteryLevelChange, MDL.Setting.SetBatteryLevel, LuaFuncEntry.FuncType.SetKeyMapInput, private.SetKeyMapInput ) end function Setting_Controller.OnShutdown() private.SetupEntryFunc(false) end function private.RefreshUserCustomFunc() if private.getNewMessageNumTimer then TimerUtil.Remove(private.getNewMessageNumTimer) private.getNewMessageNumTimer = nil end if MDL.Unlock.GetDebugSwitchState(MDL.Unlock.DebugSwitchType.UserCustom) then private.GetNewMessageNum() private.getNewMessageNumTimer = TimerUtil.Interval(private.GetNewMessageNum, 20, 0) end end function private.InitServerDataOver() private.RefreshUserCustomFunc() end function private.GetNewMessageNum() if BattleDataGetter.IsTownLevel() then SDKUtil.GetNewMessageNum() end end function Setting_Controller.BackToTown() -- 单机副本打开退出弹窗要暂停战斗,调用UTL.MessageBox.ShowSettingOKCancelBox() if BattleDataGetter.IsSyncLevel() then -- 同步玩法 if BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncSolo) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncSoloPractice) then -- 同步1V1 if LevelManager.IsInLevelWatchBattle() then UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_ExitBarrier, Const_IDS.IDS_PK_WatchQuit, private.SyncQuitRoom, nil) else UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_ExitBarrier, Const_IDS.IDS_1v1Sync_QuitHint, private.SyncQuitRoom, nil) end elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncTeamPVPPractice) then if LevelManager.IsInLevelWatchBattle() then UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_ExitBarrier, Const_IDS.IDS_PK_WatchQuit, private.SyncQuitRoom, nil) end elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncFairSoloTournament) then --天下会武 if LevelManager.IsInLevelWatchBattle() then UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_ExitBarrier, Const_IDS.IDS_FairPlayReplay_ConfirmQuitTips, private.SyncQuitRoom, nil) else UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_ExitBarrier, Const_IDS.IDS_1v1Sync_QuitHint, private.SyncQuitRoom, nil) end elseif BattleDataGetter.IsWorldBossLevel() then -- 世界BOSS UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_ExitBarrier, Const_IDS.IDS_WorldBoss_Quit_Tip, private.SyncQuitRoom, nil) elseif BattleDataGetter.IsWarZoneWorldBossLevel() then -- 战区世界boss UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_ExitBarrier, Const_IDS.IDS_WarZoneBoss_Quit_Tip, private.SyncQuitRoom, nil) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncTeamPVE) then -- 联机组队Pve副本 UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_ExitBarrier, Const_IDS.IDS_ExitDetemine, private.SyncQuitRoom, nil) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncGuildBoss) then -- 军团boss(同步玩法) UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_ExitBarrier, Const_IDS.IDS_WorldBoss_Quit_Tip, private.SyncQuitRoom, nil) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncDigTeamPVE) then -- 挖宝-组队副本 UTL.MessageBox.ShowSettingOKCancelBox(Const_IDS.IDS_ExitBarrier, Const_IDS.IDS_DigTreasure_Quit_Tips, private.SyncQuitRoom, nil) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.FightThroneFirstFloor) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.FightThroneSecondFloor) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.FightThroneThirdFloor) then -- 大乱斗(逐鹿中原) CTL.FightThrone.OnLeaveBattle() elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncUnfairSolo) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncUnfairTeamPVP) then private.SyncQuitRoom() elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.DragonArtery) then CTL.Tips.AddTipsMsg(Const_IDS.IDS_DragonArtey_CantReturn) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncCountryEveningBoss) then UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_ExitBarrier, Const_IDS.IDS_CountryNightBoss_Leave, private.SyncQuitRoom, nil) else UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_ExitBarrier, Const_IDS.IDS_ExitDetemine, private.SyncQuitRoom, nil) end else if BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SoloFight) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.NineVsNineFight) then -- 1v1 UTL.MessageBox.ShowSettingOKCancelBox(Const_IDS.IDS_ExitBarrier, Const_IDS.IDS_OfflineSoloFight_Exit, MDL.Level.SendRoleLeaveFubenFromSetting, nil) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.ClimbTower) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.NationClimbTower) then -- 放置爬塔 UTL.MessageBox.ShowSettingOKCancelBox(Const_IDS.IDS_ExitBarrier, Const_IDS.IDS_NewClimbTower_Quit, CTL.ClimbTower.ShowQuitSummary, nil) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.DigNormal) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.AdvancedDigNormal) then UTL.MessageBox.ShowSettingOKCancelBox(Const_IDS.IDS_ExitBarrier, Const_IDS.IDS_DigTreasure_Quit_Tips_Single, MDL.Level.SendRoleLeaveFubenFromSetting, nil) elseif BattleDataGetter.IsSatelliteTown() then UTL.MessageBox.ShowSettingOKCancelBox(Const_IDS.IDS_SatelliteTown_LogOut, Const_IDS.IDS_ExitDetemine, MDL.Level.ReqExitSatelliteTown, QuitCancle) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.DragonArteryWaitingArea) then CTL.Tips.AddTipsMsg(Const_IDS.IDS_DragonArtey_CantReturn) elseif LevelManager.IsSceneQuizTown() then UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_ExitBarrier, Const_IDS.IDS_SceneQuiz_SenceHint_9, MDL.Level.SendRoleLeaveFubenFromSetting, nil) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SlgGvE) then UTL.MessageBox.ShowSettingOKCancelBox(Const_IDS.IDS_ExitBarrier, Const_IDS.IDS_SlgGve_Enemy_Hint_20, MDL.Level.SendRoleLeaveFubenFromSetting, nil) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.RogueLike) then UTL.MessageBox.ShowSettingOKCancelBox(nil, UIUtils.GetLocalizedTxt(Const_IDS.IDS_VersionsActivity_Roguelike_Hint22), function() LuaInputManager.SetSpecialCommand(LuaConst.SpecialCommandType.QuitRoom) end) else UTL.MessageBox.ShowSettingOKCancelBox(Const_IDS.IDS_ExitBarrier, Const_IDS.IDS_ExitDetemine, MDL.Level.SendRoleLeaveFubenFromSetting, QuitCancle) end end end function private.OnApplicationPause(pause) --线上有一个努比亚玩家报一直弹出这个框,暂时先去掉 if pause and SDKUtil.ChannelID ~= LuaConst.SDKChannelId.NuBiYa and not NetManager.IsLaunch() and BattleDataGetter.IsStandaloneBattleLevel() then -- 攻城略地需要特殊处理 if CTL.GVGFight.CanNotShowApplicationPauseHint() then return end if not AuxUtil.InTimeline() and not UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIMoviePanel) then if MDL.PlayerGuide.IsFinishTutorial() then UTL.MessageBox.ShowSettingOKCancelBox(Const_IDS.IDS_COMMON_PROMPT, Const_IDS.IDS_GoogleAdvise_Confirm, MDL.Level.SendRoleLeaveFubenFromSetting, QuitCancle, Const_IDS.IDS_GoogleAdvise_Quit, Const_IDS.IDS_GoogleAdvise_Continue, UTL.MessageBox.DisplayType.PauseBattle) else UTL.MessageBox.ShowSettingOnlyOKBox(Const_IDS.IDS_COMMON_PROMPT, Const_IDS.IDS_GoogleAdvise_Guide_Confirm, QuitCancle, Const_IDS.IDS_GoogleAdvise_Continue, UTL.MessageBox.DisplayType.PauseBattle) end end end end --获取本地设置的音效音量大小 function Setting_Controller.GetSoundVolume() if MDL.Setting.HasKey(LuaConst.SettingKeyEnum.SoundState) then local state = MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.SoundState) if state then local value = MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.SoundProgress) if value >= 0 then return value / 100 else return 1 end else return 0 end else return 1 end end -- 需要在登录时处理的的写在这里 function Setting_Controller.LoginSync() --延时到游戏启动后再设置LOD,希望的启动时使用高质量的参数 if MDL.Setting.HasKey(LuaConst.SettingKeyEnum.SettingQuality) then local settingQuality=MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.SettingQuality) private.SetQuality(settingQuality, MDL.Setting.SwitchLodType.ReadSave) else private.SetQuality(SettingAPI.lodLevel, MDL.Setting.SwitchLodType.ReadSave) end logging.crit(LTAG.CRIT, "QualityLevel default", SettingAPI.deviceLevel, "current", SettingAPI.lodLevel) --同屏人数剔除容量 Setting_Controller.SetVisualCullingCapacityConfig() --特效播放剔除容量 Setting_Controller.SetPsCapacityConfig() -- 登录时同步给战斗是否跳过剧情 local passTimeLine = true if MDL.Setting.HasKey(LuaConst.SettingKeyEnum.PassTimeLine) then passTimeLine = MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.PassTimeLine) else MDL.Setting.SetKeyValue(LuaConst.SettingKeyEnum.PassTimeLine, passTimeLine) end NotSyncBattleSetter.SetCutsceneAutoPass(passTimeLine) -- PC包设置键位 if GameAppInfo.IsPCOrMacPackage() or UNITY_EDITOR then MDL.Setting.ApplyPCKeyMapToCSharp() end private.deviceLevel = SettingAPI.deviceLevel end function Setting_Controller.GetDeviceLevel() return private.deviceLevel end function Setting_Controller.SetLevelCulling(levelType, levelFeatureData) Setting_Controller.SetVisualCullingDistanceConfig(levelFeatureData) private.customVCullingCapacity[0] = levelFeatureData.VCullCapLevel0 private.customVCullingCapacity[1] = levelFeatureData.VCullCapLevel1 private.customVCullingCapacity[2] = levelFeatureData.VCullCapLevel2 Setting_Controller.SetVisualCullingCapacityConfig() Setting_Controller.SetPsCapacityConfig(levelFeatureData.IsEnlargeEffectCapacity) end function Setting_Controller.OnLevelExit() for i, v in pairs(private.customVCullingCapacity) do private.customVCullingCapacity[i] = nil end private.OnAdaptiveQualityTrigger(false) end function Setting_Controller.IsCustom() return MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.SettingQuality) == LodLevelCustom end function Setting_Controller.GetEnumSettingLevel(settingKeyEnum) local deviceLevel = SettingAPI.deviceLevel local settingLevel = deviceLevel if MDL.Setting.HasKey(LuaConst.SettingKeyEnum.SettingQuality) then settingLevel = MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.SettingQuality) end -- 使用画质降档前的LOD等级 if adaptiveQuality.lodLevel ~= nil then settingLevel = adaptiveQuality.lodLevel end return SettingHelper.GetSettingValue(settingKeyEnum, settingLevel, deviceLevel) end function Setting_Controller.GetLodLevel() if not MDL.Setting.HasKey(LuaConst.SettingKeyEnum.SettingQuality) then return SettingAPI.lodLevel end return MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.SettingQuality) end function Setting_Controller.ForceSetQuality(quality,switchLodType) MDL.Setting.SetKeyValue(LuaConst.SettingKeyEnum.SettingQuality,quality) private.SetQuality(quality,switchLodType) Setting_Controller.SaveFrameLimitation(private.fpsLevel) end function Setting_Controller.SetFrameLimitation() --TODO:由于增加了adaptiveQuality机制,对SettingAPI赋值都应该拦截处理,以后封装起来比较好 if adaptiveQuality.adaptCount > 0 then adaptiveQuality.fpsLevel = private.fpsLevel else SettingHelper.ExecuteFrameSetting(private.fpsLevel) end end function Setting_Controller.SaveFrameLimitation(fpsLevel) private.fpsLevel = fpsLevel MDL.Setting.SetKeyValue(LuaConst.SettingKeyEnum.FrameLimitation, private.fpsLevel) Setting_Controller.SetFrameLimitation() end function Setting_Controller.GetFrameLimitation() return private.fpsLevel end function Setting_Controller.SaveQuality() if Setting_Controller.IsCustom() then if adaptiveQuality.adaptCount <= 0 then MDL.Setting.SetKeyValue(LuaConst.SettingKeyEnum.ScreenResolution,SettingAPI.resolutionLevel) MDL.Setting.SetKeyValue(LuaConst.SettingKeyEnum.ParticleQuality,SettingAPI.ParticleLodLevel) MDL.Setting.SetKeyValue(LuaConst.SettingKeyEnum.AA,SettingAPI.aaLevel) MDL.Setting.SetKeyValue(LuaConst.SettingKeyEnum.ShaderQuality,SettingAPI.ShaderLodLevel) MDL.Setting.SetKeyValue(LuaConst.SettingKeyEnum.ShadowQuality,SettingAPI.shadowLevel) MDL.Setting.SetKeyValue(LuaConst.SettingKeyEnum.Bloom,SettingAPI.glow) --如果是自定义,如果ShaderQuality为1或者2,需要给水面开启深度+颜色图 if SettingAPI.ShaderLodLevel >= 1 then SettingAPI.waterLevel = 1 else SettingAPI.waterLevel = 0 end end end end function Setting_Controller.OpenSettingQualityView() if viewContent == nil then viewContent = {} end viewContent.index = 1 UIManager.OpenView(Const_UI_Lua.UIEnum.UISettingMainPanel,viewContent) end function Setting_Controller.SwitchLanguage(param,isLogout) --"en" "zh-Hans" if Localization.GetLanguage() ~= param then Localization.SwitchLanguage(param) LuaNetManager.RebootGame() end end function Setting_Controller.OpenRideHorse() LuaUpdater.StartUpdate(Setting_Controller.OnUpdate) end --主城开启上马 (cheat) 随机马 local _lastTime=0 local _horseID=1 function Setting_Controller.OnUpdate(deltaTime, timeSinceUpdate) if LevelManager.IsTown then if timeSinceUpdate> (_lastTime+2) then _lastTime=timeSinceUpdate for i,entity in pairs(LogicUpdateManager._entityDic) do if entity:IsHero() and not entity.components.buff:CheckHasBuffState(LuaConst.SpecialBuffs.InRiding) and entity:IsActive() then entity:SetHorseData(_horseID) SystemManager.ExecuteRideHorse(entity) _horseID=_horseID+1 if _horseID >7 then _horseID=1 end end end end else LuaUpdater.StopUpdate(Setting_Controller.OnUpdate) end end function Setting_Controller.SetCustomQualityValue(type, value) if adaptiveQuality.adaptCount > 0 then adaptiveQuality[type] = value else if DeviceLODSetting.SettingAPI[type] then DeviceLODSetting.SettingAPI[type](value) end end MDL.Setting.SetKeyValue(type, value) end function private.OnAdaptiveQualityTrigger(status) if status then if adaptiveQuality.adaptCount <= 0 then local config = DeviceLODSetting.AdaptiveQualitySetting[adaptiveQuality.adaptCount] for k, v in pairs(config) do private.AdaptiveSetSettingAPILevel(k, v) end elseif adaptiveQuality.adaptCount <= 1 then -- adaptiveQuality.lodLevel是保证自适应画质期间在BI埋点中使用适应之后的档位 adaptiveQuality.lodLevel = SettingAPI.lodLevel -- 帧率单独设置 SettingHelper.ExecuteFrameSetting(LodLevelLow) local config = DeviceLODSetting.AdaptiveQualitySetting[adaptiveQuality.adaptCount] for k, v in pairs(config) do private.AdaptiveSetSettingAPILevel(k, v) end if adaptiveQuality.lodLevel == LodLevelHigh then SettingHelper.SwitchLOD(LodLevelMid) private.AdaptiveSetSettingAPILevel(LuaConst.SettingKeyEnum.Bloom, LodLevelLow) private.AdaptiveSetSettingAPILevel(LuaConst.SettingKeyEnum.ShadowQuality, LodLevelLow) elseif adaptiveQuality.lodLevel == LodLevelMid then SettingHelper.SwitchLOD(LodLevelLow) end CTL.Tips.AddTipsMsg(Const_IDS["IDS_LowFPS_SelfAdaption"]) elseif adaptiveQuality.adaptCount <= 2 then local config = DeviceLODSetting.AdaptiveQualitySetting[adaptiveQuality.adaptCount] for k, v in pairs(config) do private.AdaptiveSetSettingAPILevel(k, v) end if adaptiveQuality.lodLevel == LodLevelHigh then SettingHelper.SwitchLOD(LodLevelLow) end CTL.Tips.AddTipsMsg(Const_IDS["IDS_LowFPS_SelfAdaption"]) end --记录状态 adaptiveQuality.adaptCount = adaptiveQuality.adaptCount + 1 else adaptiveQuality.adaptCount = 0 for k, v in pairs(adaptiveQuality) do if DeviceLODSetting.SettingAPI[k] then DeviceLODSetting.SettingAPI[k](v) adaptiveQuality[k] = nil end end if adaptiveQuality.lodLevel then SettingHelper.SwitchLOD(adaptiveQuality.lodLevel) adaptiveQuality.lodLevel = nil end Setting_Controller.EnforceAllSettings() end end -- 画质降档,设置画质参数 function private.AdaptiveSetSettingAPILevel(settingKeyEnum, settingValue) local value = DeviceLODSetting.GetSettingAPIValue[settingKeyEnum]() DeviceLODSetting.SettingAPI[settingKeyEnum](math.min(settingValue, value)) if adaptiveQuality[settingKeyEnum] == nil then adaptiveQuality[settingKeyEnum] = CTL.Setting.GetEnumSettingLevel(settingKeyEnum) end end function private.SetQuality(quality,switchLodType) EventSystem.Dispatch(EventID.BI_SwitchLod,BIManager.BIType.SwitchLod, switchLodType, SettingAPI.lodLevel,quality) --自适应画质状态中的参数变更先缓存起来备用 if adaptiveQuality.adaptCount > 0 then adaptiveQuality.lodLevel = quality if quality == LodLevelCustom then adaptiveQuality[LuaConst.SettingKeyEnum.ScreenResolution] = MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.ScreenResolution) or SettingAPI.resolutionLevel adaptiveQuality[LuaConst.SettingKeyEnum.ParticleQuality] = MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.ParticleQuality) or SettingAPI.ParticleLodLevel adaptiveQuality[LuaConst.SettingKeyEnum.AA] = MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.AA) or SettingAPI.aaLevel adaptiveQuality[LuaConst.SettingKeyEnum.ShaderQuality] = MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.ShaderQuality) or SettingAPI.ShaderLodLevel adaptiveQuality[LuaConst.SettingKeyEnum.ShadowQuality] = MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.ShadowQuality) or SettingAPI.shadowLevel adaptiveQuality[LuaConst.SettingKeyEnum.Bloom] = MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.Bloom) or SettingAPI.glow end else SettingAPI.lodLevel = quality if quality == LodLevelCustom then SettingAPI.resolutionLevel = MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.ScreenResolution) or SettingAPI.resolutionLevel SettingAPI.ParticleLodLevel = MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.ParticleQuality) or SettingAPI.ParticleLodLevel SettingAPI.aaLevel = MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.AA) or SettingAPI.aaLevel SettingAPI.ShaderLodLevel = MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.ShaderQuality) or SettingAPI.ShaderLodLevel SettingAPI.shadowLevel = MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.ShadowQuality) or SettingAPI.shadowLevel SettingAPI.glow = MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.Bloom) or SettingAPI.glow end private.LuaSetSettings() end EventSystem.Dispatch(EventID.Setting_SwitchLODLevel, quality) end function private.SyncQuitRoom() if LevelManager.IsInLevelWatchBattle() then --观战退出的话 ,直接关闭关卡并退出 if BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncTeamPVPPractice) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncSoloPractice) then MDL.CustomRoom.ManualLeaveRoom() end NotSyncBattleSetter.StopCurLevel(true) MDL.WatchBattle.OnQuitWatchWar() EventSystem.Dispatch(EventID.Level_SendRoleLeaveFuben ,false) else LuaInputManager.SetSpecialCommand(LuaConst.SpecialCommandType.QuitRoom) end end --region ****Setting**** --返回三挡屏幕高度,720、1080、超高分辨率(匹配失败 表示不支持超高分辨率 Fallback到默认最高1080的规则) --对应设置中LOD三挡的分辨率设置分别为 0/1/2,即LOD0:720 LOD1:1080 LOD2:超高分辨率 --自定义设置中,允许三种分辨率切换720/1080/超高分辨率 --较好的机器(iOS默认或0.8倍原生的配置里,安卓高于分数),LOD2:超高分辨率,LOD1:全1080,LOD0:UI1080+3D720 --不好的机器(iOS在low配置里,安卓低于分数),则LOD2:1080,LOD1:UI1080+3D720,LOD0:UI1080+3D720 --差异主要在于LOD1的3D相机分辨率,如果在白名单中,scale2=1,不在白名单中,scale2=0.667 function private.GetResolutionConfig(matchGPUName, deviceName, rankNumber, originHeight) if GameAppInfo.IsPCOrMacPackage() then local resolutionIndex = Setting_Controller.GetDefaultResolution() local tb = LuaConst.SupportResolution[resolutionIndex] if not tb then return LuaConst.SupportResolution[3][1], LuaConst.SupportResolution[3][2], 1, 1, 1, 1 else return tb[1], tb[2], 3, 1, 1, 1 end end local height3, height2, height1 if UNITY_IOS then local limitValue = DeviceLODSetting.UltraResolutionDeviceLimitInfo_iOS[deviceName] if limitValue == nil then --1.没有查到限制,提高到原生分辨率限制 if originHeight >= DeviceLODSetting.PadHeightCheck_iOS then height3 = math.min(DeviceLODSetting.ScreenResolutionSetting.UltraHigh_iOSPad, originHeight) else height3 = math.min(DeviceLODSetting.ScreenResolutionSetting.UltraHigh, originHeight) end elseif limitValue == 0 then -- 2.配成0,是low机器,不能用原生分辨率 height3 = math.min(DeviceLODSetting.ScreenResolutionSetting.High, originHeight) else --3.使用配置的值 height3 = math.min(limitValue, originHeight) end height1 = math.min(DeviceLODSetting.ScreenResolutionSetting.Low, originHeight) height2 = math.min(DeviceLODSetting.ScreenResolutionSetting.High, originHeight) if height3 <= height2 then height2 = height1 end return height1, height2, height3, 1, 1, 1 end --安卓设备走评分即可。未知设备即评分为0的,默认为好机器 if rankNumber == 0 or rankNumber > DeviceLODSetting.AndroidUltraResolutionRankLimit then --1.原生分辨率限制 if originHeight >= DeviceLODSetting.PadHeightCheck_Android then height3 = math.min(DeviceLODSetting.ScreenResolutionSetting.UltraHigh_AndroidPad, originHeight) else height3 = math.min(DeviceLODSetting.ScreenResolutionSetting.UltraHigh, originHeight) end else --评分不够,不允许用原生分辨率 height3 = math.min(DeviceLODSetting.ScreenResolutionSetting.High, originHeight) end height2 = math.min(DeviceLODSetting.ScreenResolutionSetting.High, originHeight) height1 = height2 local coreCameraHeight = DeviceLODSetting.ScreenResolutionSetting.Low local scale1 = math.min(coreCameraHeight / height1, 1) local scale3 = 1 local scale2 = 1 if height3 <= height2 then scale2 = math.min(coreCameraHeight / height2, 1) end return height1, height2, height3, scale1, scale2, scale3 end function private.GetGCDuration() --资源分析,GC时间为0,执行GC,即回收全部资源 if DEF.ENABLE_ASSET_ANALYSIS then return 0 end if UNITY_IOS then return 2 end return 10 end function private.GetHeroTransparentRenderQueue() return 2510 end function private.SetKeyMapInput(keycode) EventSystem.Dispatch(EventID.PCPackage_SetKeyMapInput, keycode) end function Setting_Controller.GetUploadLogCustom(problemType, problemDigest) local roleName, serverId = MDL.Login.GetRoleNameAndServerId() if not lastSavePlayerInfo then lastSavePlayerInfo = {} lastSavePlayerInfo.roleName = roleName or "" lastSavePlayerInfo.serverId = serverId or "" lastSavePlayerInfo.apkVersion = MDL.HotFix.GetVersionInfo() lastSavePlayerInfo.uniqueId = PersistentData.DeviceData:Get("lastLoginAccid") or "" lastSavePlayerInfo.roleId = PersistentData.DeviceData:Get("lastLoginRoleId") or "" lastSavePlayerInfo.serverName = PersistentData.DeviceData:Get("ServerName") or "" lastSavePlayerInfo.areaId = GameAppInfo.Global_ProductId end lastSavePlayerInfo.problemType = problemType lastSavePlayerInfo.problemDigest = problemDigest return JSON.encode(lastSavePlayerInfo) end function Setting_Controller.GetSdkServiceCustom() if not onlinePlayerJson then local onlinePlayerInfo = {} onlinePlayerInfo.roleName = BattleDataGetter.GetPlayerName() onlinePlayerInfo.serverId = MDL.Login.GetServerId() onlinePlayerInfo.apkVersion = MDL.HotFix.GetVersionInfo() onlinePlayerInfo.uniqueId = BattleDataGetter.GetAcID() onlinePlayerInfo.roleId = MDL.Player.GetRoleId() onlinePlayerInfo.serverName = MDL.Login.GetServerName() onlinePlayerInfo.areaId = GameAppInfo.Global_ProductId onlinePlayerJson = JSON.encode(onlinePlayerInfo) end return onlinePlayerJson end function Setting_Controller.UploadLog(problemType, problemDigest) local infoJson = Setting_Controller.GetUploadLogCustom(problemType, problemDigest) SDKUtil.UploadLog(infoJson) end function Setting_Controller.GetNewMessageNum(num) if num > 0 then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.Setting_Customer) else CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.Setting_Customer) end end function Setting_Controller.IsCantReturnTownLevel() local curLevelType = BattleDataGetter.GetCurLevelType() if curLevelType == LuaConst.LevelType.SyncPlanesEscort or curLevelType == LuaConst.LevelType.SyncCountryPVP then return true end return false end --部分oppo和vivio渠道的视频播放显示静态图片 日本地区添加部分闪退设备 function Setting_Controller.IsShowStaticPic(isOpeningCG) if not UNITY_ANDROID then return false end local deviceModel = SystemInfo.deviceModel or "" if MovieToStaticPicDevice[deviceModel] then return true end --如果是开场视频(长CG),不检测版本判断 if isOpeningCG then return false end -- 谷歌推荐 90版本升级了视频插件解决崩溃,低版本的屏蔽掉视频播放 if GameAppInfo.IsOverseaPackage() then return not GameAppInfo.IsVersionGreaterThan19000() end return false end --endregion ****Setting**** -- region 分辨率 function Setting_Controller.GetDefaultResolution() local resolutionIndex = 0 if GameAppInfo.IsMacPackage() then --6是 LuaConst.SupportResolution的下标 resolutionIndex = PersistentData.DeviceData:Get(ResolutionSaveKey, nil) if resolutionIndex == nil then local displayerWidth, displayerHeight = Setting_Controller.GetCurrentResolution() if LuaConst.SupportResolution[7][1] <= displayerWidth then resolutionIndex = 7 else resolutionIndex = 6 end end else resolutionIndex = PersistentData.DeviceData:Get(ResolutionSaveKey, 3) end return resolutionIndex end function Setting_Controller.GetCurrentResolution() if GameAppInfo.IsOverseaPackage() or GameAppInfo.IsVersionGreaterThan121000() then return UIUtils.GetCurrentResolution(0, 0) end return 1920, 1080 --PC默认最大分辨率 end function Setting_Controller.SetResolutionByIndex(index) PersistentData.DeviceData:Set(ResolutionSaveKey, index, true) private.ReSetResolution() end function private.ReSetResolution() SettingAPI.resolutionLevel = SettingAPI.resolutionLevel end -- endregion --加入执行设置接口,用于刷新当前的设置,从C#改造到Lua中 function Setting_Controller.EnforceAllSettings() AuxUtil.EnforceAllSettings() CTL.Setting.SetFrameLimitation() private.LuaSetSettings() end function private.LuaSetSettings() local isCustom, settingLevel, deviceLevel, systemMemory, isPCPackage = private.GetSettingParams() --贴图减半设置 SettingHelper.ExecuteTextureSetting(isCustom, settingLevel, deviceLevel, systemMemory, isPCPackage) --画面设置移植到Lua中 SettingHelper.ExecuteSetting(LuaConst.SettingKeyEnum.ParticleQuality, settingLevel, deviceLevel) SettingHelper.ExecuteSetting(LuaConst.SettingKeyEnum.ScreenResolution, settingLevel, deviceLevel) SettingHelper.ExecuteSetting(LuaConst.SettingKeyEnum.Bloom, settingLevel, deviceLevel) SettingHelper.ExecuteSetting(LuaConst.SettingKeyEnum.DOF, settingLevel, deviceLevel) SettingHelper.ExecuteSetting(LuaConst.SettingKeyEnum.LightShaft, settingLevel, deviceLevel) SettingHelper.ExecuteSetting(LuaConst.SettingKeyEnum.ColorGrading, settingLevel, deviceLevel) SettingHelper.ExecuteSetting(LuaConst.SettingKeyEnum.AA, settingLevel, deviceLevel) SettingHelper.ExecuteSetting(LuaConst.SettingKeyEnum.ShaderQuality, settingLevel, deviceLevel) SettingHelper.ExecuteSetting(LuaConst.SettingKeyEnum.ShadowQuality, settingLevel, deviceLevel) SettingHelper.ExecuteSetting(LuaConst.SettingKeyEnum.Water, settingLevel, deviceLevel) SettingHelper.ExecuteSetting(LuaConst.SettingKeyEnum.LodGroupBias, settingLevel, deviceLevel) end function private.GetSettingParams() --设备等级 local deviceLevel = SettingAPI.deviceLevel --是否自定义 local isCustom = false --设置等级 local settingLevel = deviceLevel if MDL.Setting.HasKey(LuaConst.SettingKeyEnum.SettingQuality) then settingLevel = MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.SettingQuality) isCustom = settingLevel == LodLevelCustom end --设备内存 local systemMemory = SystemInfo.systemMemorySize local isPCPackage = GameAppInfo.IsPCOrMacPackage() return isCustom, settingLevel, deviceLevel, systemMemory, isPCPackage end function Setting_Controller.InitPCConfig() if UNITY_EDITOR or GameAppInfo.IsPCOrMacPackage() then for k, v in pairs(DeviceLODSetting.QualitySettingOverridePC) do for key, value in pairs(v) do DeviceLODSetting.QualitySetting[k][key] = value end end end end function Setting_Controller.GetCustomTerrainHeight() return private.enableCustomTerrainHeight, private.customTerrainHeight end function Setting_Controller.SetCustomTerrainHeight(height) local enableCustomHeight = height ~= nil local customHeight = height or 0 private.enableCustomTerrainHeight = enableCustomHeight private.customTerrainHeight = customHeight SettingAPI.EnableCustomTerrainHeight = enableCustomHeight SettingAPI.CustomTerrainHeight = customHeight end --特效等级 function Setting_Controller.SetPsPresetConfig(presetID) local presetConfig = DeviceLODSetting.PSPresetConfig[presetID] if presetConfig == nil then presetConfig = DeviceLODSetting.PSPresetConfig[-1] end local self0, other0 = presetConfig[0].SelfLOD, presetConfig[0].OtherLOD local self1, other1 = presetConfig[1].SelfLOD, presetConfig[1].OtherLOD local self2, other2 = presetConfig[2].SelfLOD, presetConfig[2].OtherLOD SettingHelper.SetPsPresetConfig(self0, other0, self1, other1, self2, other2) end --特效容量 function Setting_Controller.SetPsCapacityConfig(isEnlargeCapacity) local capNear, capMedium, capFar if ForceEffectCullingCapacity then AuxUtil.SetEffectCullingCapacity(ForceEffectCullingCapacity.near, ForceEffectCullingCapacity.medium, ForceEffectCullingCapacity.far) return else local capInfo = EffectCullingCapacity[SettingAPI.deviceLevel] local enlargeCount = isEnlargeCapacity and 10000 or 0 capNear, capMedium, capFar = enlargeCount + capInfo.near, enlargeCount + capInfo.medium, enlargeCount + capInfo.far end SettingHelper.SetPsCapacityConfig(capNear, capMedium, capFar) end --同屏人数 function Setting_Controller.SetVisualCullingCapacityConfig() local cullingCount if ForceVisualCullingCapacity then cullingCount = ForceVisualCullingCapacity AuxUtil.SetVisualCullingCapacity(cullingCount) return else local deviceLevel = SettingAPI.deviceLevel if private.customVCullingCapacity[deviceLevel] and private.customVCullingCapacity[deviceLevel] ~= 0 then cullingCount = private.customVCullingCapacity[deviceLevel] else cullingCount = VisualCullingCapacity[deviceLevel] end end SettingHelper.SetVisualCullingCapacityConfig(cullingCount) end --同屏显示距离 function Setting_Controller.SetVisualCullingDistanceConfig(levelFeatureData) local visibleDistanceNear, visibleDistanceFar, visibleDistanceMax = levelFeatureData.VisibleDistanceNear, levelFeatureData.VisibleDistanceFar, levelFeatureData.VisibleDistanceMax SettingHelper.SetVisualCullingDistanceConfig(visibleDistanceNear, visibleDistanceFar, visibleDistanceMax) end function Setting_Controller.Set5SSkin(enabled) if SettingAPI.deviceLevel == 2 then AuxUtil.Set5SSkin(enabled, 1) end end --UI模型界面强制设置阴影距离,并开启阴影 function Setting_Controller.SetUIShadowDistance(distance) local setShadowFunction = DeviceLODSetting.SettingAPI[LuaConst.SettingKeyEnum.ShadowQuality] if distance and distance > 0 then SettingAPI.SetShadowDistance(distance) local shadowQualityLevel_High = 2; setShadowFunction(shadowQualityLevel_High) else SettingAPI.SetShadowDistance(0) local curShadowSettingValue = Setting_Controller.GetEnumSettingLevel(LuaConst.SettingKeyEnum.ShadowQuality) setShadowFunction(curShadowSettingValue) end end function Setting_Controller.GetLuaMemory() local luaMemory = math.floor(collectgarbage("count") / 1024) return luaMemory end function Setting_Controller.GetAppUsedMemory() local appUsedMemory = 0 if GameAppInfo.IsVersionGreaterThan121000() then appUsedMemory = math.floor(AuxUtil.GetAppUsedMemory() / 1024) end return appUsedMemory end function Setting_Controller.GetEngineGCReservedMemory() local engineGCReservedMemory = 0 if GameAppInfo.IsVersionGreaterThan121000() then engineGCReservedMemory = math.floor(AuxUtil.GetEngineGCReservedMemory() / 1024) end return engineGCReservedMemory end function Setting_Controller.GetEngineSystemUsedMemory() local engineSystemTotalMemory = 0 if GameAppInfo.IsVersionGreaterThan121000() then engineSystemTotalMemory = math.floor(AuxUtil.GetEngineSystemUsedMemory() / 1024) end return engineSystemTotalMemory end function Setting_Controller.GetSystemTotalMemory() local systemTotalMemory = SystemInfo.systemMemorySize return systemTotalMemory end function Setting_Controller.SetPCViewScale(transform) local scale = 0.8 local width = 1920 local height = 1080 local screenWidth, screenHeight = UIUtils.UIRoot:GetSizeDelta() scale = screenWidth/width * scale transform:SetLocalScale(scale, scale, scale) transform:SetSizeDelta(width/scale-width, height/scale-height) end function Setting_Controller.SetPCScrollMsgViewScale(transform) if GameAppInfo.IsPCOrMacPackage() then transform:SetLocalScale(0.8, 0.8, 0.8) end end return Setting_Controller