文章目录

  • 环境
  • GameQualitySettings

Show me Your Code, Talk Is Cheap.

以前自己写的类,现在重新写一份 代码

便于日后直接搬运使用,代码都是相当简单,都是直接调用 unity 的 API 设置即可,可以理解为就是搬运而已


环境

Unity : 2018.2.11f1
Pipeline : BRP

改用在:URP 也是很简单(部分 API 修改一下即可)


GameQualitySettings

// jave.lin 2022.03.17using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;// jave.lin : 输出系统的信息工具类
public class DumpSystemInfoUtil
{// jave.lin : 通过反射得方式获取不了public static string DumpSystemInfoByReflection(){var type = typeof(SystemInfo);// jave.lin : 下面发现反射不成功var fields = type.GetFields(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);var fieldsToStrList = new List<string>();foreach (var field in fields){// 过滤 过期得 APIvar obsoAttris = field.GetCustomAttributes(typeof(ObsoleteAttribute), true);if (obsoAttris != null && obsoAttris.Length > 0) continue;fieldsToStrList.Add(field.Name + ":" + field.GetValue(null).ToString());}return string.Join("\n", fieldsToStrList.ToArray());}// jave.lin : 所以只能通过一个个得去输出public static string DumpSystemInfoByManualyPrint(){var list = new List<string>(new string[]{"SystemInfo:\n","\tbatteryLevel:" + SystemInfo.batteryLevel,"\tbatteryStatus:" + SystemInfo.batteryStatus,"\toperatingSystem:" + SystemInfo.operatingSystem,"\toperatingSystemFamily:" + SystemInfo.operatingSystemFamily,"\tprocessorType:" + SystemInfo.processorType,"\tprocessorFrequency:" + SystemInfo.processorFrequency,"\tprocessorCount:" + SystemInfo.processorCount,"\tsystemMemorySize:" + SystemInfo.systemMemorySize,"\tdeviceUniqueIdentifier:" + SystemInfo.deviceUniqueIdentifier,"\tdeviceName:" + SystemInfo.deviceName,"\tdeviceModel:" + SystemInfo.deviceModel,"\tsupportsAccelerometer:" + SystemInfo.supportsAccelerometer,"\tsupportsGyroscope:" + SystemInfo.supportsGyroscope,"\tsupportsLocationService:" + SystemInfo.supportsLocationService,"\tsupportsVibration:" + SystemInfo.supportsVibration,"\tsupportsAudio:" + SystemInfo.supportsAudio,"\tdeviceType:" + SystemInfo.deviceType,"\tgraphicsMemorySize:" + SystemInfo.graphicsMemorySize,"\tgraphicsDeviceName:" + SystemInfo.graphicsDeviceName,"\tgraphicsDeviceVendor:" + SystemInfo.graphicsDeviceVendor,"\tgraphicsDeviceID:" + SystemInfo.graphicsDeviceID,"\tgraphicsDeviceVendorID:" + SystemInfo.graphicsDeviceVendorID,"\tgraphicsDeviceType:" + SystemInfo.graphicsDeviceType,"\tgraphicsUVStartsAtTop:" + SystemInfo.graphicsUVStartsAtTop,"\tgraphicsDeviceVersion:" + SystemInfo.graphicsDeviceVersion,"\tgraphicsShaderLevel:" + SystemInfo.graphicsShaderLevel,"\tgraphicsMultiThreaded:" + SystemInfo.graphicsMultiThreaded,"\tsupportsShadows:" + SystemInfo.supportsShadows,"\tsupportsRawShadowDepthSampling:" + SystemInfo.supportsRawShadowDepthSampling,"\tsupportsMotionVectors:" + SystemInfo.supportsMotionVectors,"\tsupports3DTextures:" + SystemInfo.supports3DTextures,"\tsupports2DArrayTextures:" + SystemInfo.supports2DArrayTextures,"\tsupports3DRenderTextures:" + SystemInfo.supports3DRenderTextures,"\tsupportsCubemapArrayTextures:" + SystemInfo.supportsCubemapArrayTextures,"\tcopyTextureSupport:" + SystemInfo.copyTextureSupport,"\tsupportsComputeShaders:" + SystemInfo.supportsComputeShaders,"\tsupportsInstancing:" + SystemInfo.supportsInstancing,"\tsupportsHardwareQuadTopology:" + SystemInfo.supportsHardwareQuadTopology,"\tsupports32bitsIndexBuffer:" + SystemInfo.supports32bitsIndexBuffer,"\tsupportsSparseTextures:" + SystemInfo.supportsSparseTextures,"\tsupportedRenderTargetCount:" + SystemInfo.supportedRenderTargetCount,"\tsupportsMultisampledTextures:" + SystemInfo.supportsMultisampledTextures,"\tsupportsMultisampleAutoResolve:" + SystemInfo.supportsMultisampleAutoResolve,"\tsupportsTextureWrapMirrorOnce:" + SystemInfo.supportsTextureWrapMirrorOnce,"\tusesReversedZBuffer:" + SystemInfo.usesReversedZBuffer,"\tnpotSupport:" + SystemInfo.npotSupport,"\tmaxTextureSize:" + SystemInfo.maxTextureSize,"\tmaxCubemapSize:" + SystemInfo.maxCubemapSize,"\tsupportsAsyncCompute:" + SystemInfo.supportsAsyncCompute,"\tsupportsAsyncGPUReadback:" + SystemInfo.supportsAsyncGPUReadback,"\tsupportsMipStreaming:" + SystemInfo.supportsMipStreaming,});return string.Join("\n", list.ToArray());}
}// jave.lin : 设备定档级别枚举
public enum eDeviceLevel
{Unknow = -1,VeryLow = 0,Low,Middle,High,
}// jave.lin : 画质级别
public enum eQualityLevel
{Low = 1,Middle = 2,High = 3,Ultra = 4,
}// jave.lin : shader lod
public enum eShaderLOD
{//High = 800,//Middle = 400,//Low = 200,//VeryLow = 100,//UnLimit = -1,// jave.lin : 太低的值对 built-in shader 的影响太大High = 800,Middle = 600,Low = 400,VeryLow = 200,UnLimit = -1,
}// jave.lin : 游戏的质量设置类
public class GameQualitySettings
{private const string QS_POWER_SAVE_MODE_KEY = "graphics_setting.power_save_mode";private const string QS_QUALITY_LEVEL_KEY = "graphics_setting.quality_level";// 当 品质有调整事出发的事件函数public static Action<eQualityLevel> onLevelChanged;// 源来的 AA 和 阴影设置private static int srcAntiAliasing;private static ShadowQuality srcShadows;// 当前 品质等级private static eQualityLevel curLevel;// 获取 设备定档的质量级别public static eQualityLevel DeviceAdapterLevel{get; private set;}// 获取 或 设置 公开给外部的画质设置的属性public static eQualityLevel GraphicsLevel{get { return curLevel; }set{if (curLevel != value){curLevel = value;_SetCurLevel(value);PlayerPrefs.SetInt(QS_QUALITY_LEVEL_KEY, (int)value);if (null != onLevelChanged){onLevelChanged.Invoke(value);}}}}// 获取 或 设置 省电模式, true: 30FPS, false: 60FPSpublic static bool PowerSaveMode{get{return Application.targetFrameRate < 40;}set{var src_v = PlayerPrefs.GetInt(QS_POWER_SAVE_MODE_KEY, -1);var tar_v = value ? 1 : 0;if (src_v != tar_v){PlayerPrefs.SetInt(QS_POWER_SAVE_MODE_KEY, tar_v);}Application.targetFrameRate = value ? 30 : 60;}}// 静态构造函数static GameQualitySettings(){// 备份 原始 AA 和 阴影srcAntiAliasing = QualitySettings.antiAliasing;srcShadows = QualitySettings.shadows;// 初始化 品质 和 省电模式_SetDefaultPowerSaveMode();_SetDefaultLevel();}// 设置默认的品质等级private static void _SetDefaultLevel(){// 先 分析 并 设置 设备默认品质等级DeviceAdapterLevel = _AnalysicDeviceLevel();var src_v = PlayerPrefs.GetInt(QS_QUALITY_LEVEL_KEY, -1);// 如果品质等级没有设置过if (src_v == -1){// 那么使用 设备默认品质PlayerPrefs.SetInt(QS_QUALITY_LEVEL_KEY, (int)DeviceAdapterLevel);curLevel = GraphicsLevel;}// 如果品质等级有设置过else{curLevel = (eQualityLevel)src_v;}}// 设置默认的省电模式private static void _SetDefaultPowerSaveMode(){var src_v = PlayerPrefs.GetInt(QS_POWER_SAVE_MODE_KEY, 0);if (src_v == 0){PowerSaveMode = true;PlayerPrefs.SetInt(QS_POWER_SAVE_MODE_KEY, 1);}else{PowerSaveMode = src_v == 1;}}// 分析设备所属默认的品质等级private static eQualityLevel _AnalysicDeviceLevel(){if (SystemInfo.processorFrequency >= 2500 &&SystemInfo.processorCount >= 8 &&SystemInfo.systemMemorySize >= (6 * 1024) &&SystemInfo.graphicsMemorySize >= (2 * 1024) &&SystemInfo.graphicsShaderLevel >= 30 &&SystemInfo.graphicsMultiThreaded &&SystemInfo.supportsShadows &&SystemInfo.supportsInstancing &&SystemInfo.supports32bitsIndexBuffer){return eQualityLevel.Ultra;}else if (SystemInfo.processorFrequency >= 2000 &&SystemInfo.processorCount >= 4 &&SystemInfo.systemMemorySize >= (4 * 1024) &&SystemInfo.graphicsMemorySize >= (1 * 1024) &&SystemInfo.graphicsShaderLevel >= 20){return eQualityLevel.High;}else if (SystemInfo.processorFrequency >= 1500 &&SystemInfo.processorCount >= 2 &&SystemInfo.systemMemorySize >= (2 * 1024) &&SystemInfo.graphicsMemorySize >= (512) &&SystemInfo.graphicsShaderLevel >= 10){return eQualityLevel.Middle;}else{return eQualityLevel.Low;}}// 设置 当前品质等级private static void _SetCurLevel(eQualityLevel level){_SetAntiAliasing(level);_SetResolution(level);_SetTexMipmapOffset(level);_SetShadow(level);_SetLODBias(level);_SetGraphicsTier(level);_SetShaderLOD(level);_SetGlobalShaderKW(level);}// 设置 AAprivate static void _SetAntiAliasing(eQualityLevel level){if (level >= eQualityLevel.High){QualitySettings.antiAliasing = srcAntiAliasing;}else{QualitySettings.antiAliasing = 0;}}// 设置分辨率private static void _SetResolution(eQualityLevel level){// jave.lin : BRP(Built-In Rendering Pipeline) 中// 需要对应的 Camera 开启 AllowDynamicResolution 后才能生效switch (level){case eQualityLevel.Low:QualitySettings.resolutionScalingFixedDPIFactor = 0.75f;break;case eQualityLevel.Middle:QualitySettings.resolutionScalingFixedDPIFactor = 0.85f;break;case eQualityLevel.High:QualitySettings.resolutionScalingFixedDPIFactor = 0.85f;break;case eQualityLevel.Ultra:QualitySettings.resolutionScalingFixedDPIFactor = 1.00f;break;}}// 设置 Tex 纹理 mipmap offsetprivate static void _SetTexMipmapOffset(eQualityLevel level){switch (level){case eQualityLevel.Low:QualitySettings.masterTextureLimit = DeviceAdapterLevel < eQualityLevel.High ? 3 : 2;break;case eQualityLevel.Middle:QualitySettings.masterTextureLimit = DeviceAdapterLevel < eQualityLevel.High ? 2 : 1;break;case eQualityLevel.High:QualitySettings.masterTextureLimit = 0;break;case eQualityLevel.Ultra:QualitySettings.masterTextureLimit = 0;break;}}// 设置阴影private static void _SetShadow(eQualityLevel level){switch (level){case eQualityLevel.Low:case eQualityLevel.Middle://QualitySettings.shadows = ShadowQuality.Disable; // jave.lin : 有 BUG,会导致,Animator 组件中的 culling mode 不是 always animated 的对象超出屏幕的画,会被自动停止掉// 所以下面使用 shadowDistance 来替代关闭QualitySettings.shadowDistance = 0;break;case eQualityLevel.High:QualitySettings.shadows = srcShadows;QualitySettings.shadowResolution = ShadowResolution.Low;QualitySettings.shadowDistance = 70;break;case eQualityLevel.Ultra:QualitySettings.shadows = srcShadows;QualitySettings.shadowResolution = ShadowResolution.High;QualitySettings.shadowDistance = 100;break;}}// 设置 LOD 偏移private static void _SetLODBias(eQualityLevel level){switch (level){case eQualityLevel.Low:QualitySettings.lodBias = 0.5f;break;case eQualityLevel.Middle:QualitySettings.lodBias = 0.75f;break;case eQualityLevel.High:case eQualityLevel.Ultra:QualitySettings.lodBias = 1.0f;break;}}// 设置 GraphicsTier 的层级private static void _SetGraphicsTier(eQualityLevel level){switch (level){case eQualityLevel.Low:case eQualityLevel.Middle:Graphics.activeTier = GraphicsTier.Tier1;break;case eQualityLevel.High:Graphics.activeTier = GraphicsTier.Tier2;break;case eQualityLevel.Ultra:Graphics.activeTier = GraphicsTier.Tier3;break;}}// 设置 Shader LODprivate static void _SetShaderLOD(eQualityLevel level){switch (level){case eQualityLevel.Low:Shader.globalMaximumLOD = (int)eShaderLOD.VeryLow;break;case eQualityLevel.Middle:Shader.globalMaximumLOD = (int)eShaderLOD.Low;break;case eQualityLevel.High:Shader.globalMaximumLOD = (int)eShaderLOD.Middle;break;case eQualityLevel.Ultra:Shader.globalMaximumLOD = (int)eShaderLOD.High;break;default:Shader.globalMaximumLOD = (int)eShaderLOD.UnLimit;break;}}// 设置全局Shader Keywordprivate static void _SetGlobalShaderKW(eQualityLevel level){switch (level){case eQualityLevel.Low:case eQualityLevel.Middle:Shader.DisableKeyword("_SOFT_PARTICLE_ON");break;case eQualityLevel.High:case eQualityLevel.Ultra:Shader.EnableKeyword("_SOFT_PARTICLE_ON");break;}}
}// jave.lin : 后效基类
public class PPBasic : MonoBehaviour { }
// jave.lin : Bloom 后效
public class BloomPP : PPBasic
{// jave.lin : start 时 先处理,处理当前品质// 然后监听 品质变化的时间private void Start(){OnQualityLevelChanged(GameQualitySettings.GraphicsLevel);GameQualitySettings.onLevelChanged -= OnQualityLevelChanged;GameQualitySettings.onLevelChanged += OnQualityLevelChanged;}// jave.lin : 销毁时记得删除回调private void OnDestroy(){GameQualitySettings.onLevelChanged -= OnQualityLevelChanged;}private void OnQualityLevelChanged(eQualityLevel ql){// jave.lin : 当 品质等级大于或等于高时,才开启 Bloom 后效enabled = ql >= eQualityLevel.High;}
}

Unity - 画质设置相关推荐

  1. Unity Camera设置-Culling Mask

    Unity Camera设置-Culling Mask 参考文档:Unity中Camera参数-Culling Mask详解_-MCQ-的博客-CSDN博客_unity相机cullingmask 简介 ...

  2. 为什么超凡先锋显示未选择服务器,超凡先锋画质不太流畅怎么弄 游戏画质设置方法介绍_超凡先锋...

    超凡先锋是一款逃离塔科夫玩法的射击游戏,这款游戏对玩家的手机配置需求还是比较高的,那么超凡先锋画质不太流畅怎么弄呢?下面我们就一起来看一下游戏画质设置方法介绍吧. 一.画质设置步骤介绍 超凡先锋的优化 ...

  3. Unity Animation设置动画播放初始时间

    Unity Animation设置动画播放初始时间 需求 在需要播放动作时, 从动作序列帧指定位置开始播放 实现 在指定位置等待播放 public Animation animation; void ...

  4. 玩战塔英雄不显示服务器,战塔英雄手游画质怎么设置?画质设置方法图文介绍...

    战塔英雄手游画质怎么设置?不了解战塔英雄手游画质怎么设置的玩家,电玩之家小编为你准备了最新的图文攻略,感兴趣的玩家赶快一起来看看吧! 战塔英雄手游画质设置方法图文介绍 1.首先我们进入到战塔英雄游戏当 ...

  5. unity build设置_Microsoft Build上的Unity:展会上的7个重点

    unity build设置 The Microsoft Build 2018 developer conference just wrapped up in Seattle and Unity was ...

  6. unity桌面设置vnc_win7系统通过VNCViewer访问Ubuntu桌面环境的操作方法

    电脑系统通过VNCViewer访问Ubuntu桌面环境的问题每个人都有不同的操作门路,小编在大量的搜集通过VNCViewer访问Ubuntu桌面环境的解法之后,总结出来一套比较简单的通过VNCView ...

  7. pcss评分_GTA5画质设置 N卡画质选项设置指南

    GTA5的配置需求对于很多玩家来说都有着不小的压力,下面为大家带来的是GTA5画质选项设置指南,N卡官网发布的GTA5画质选项详细对比,一起来看看吧.

  8. unity怎么设置游戏页面_杭州有没有正规的unity游戏开发培训机构?

    现在Unity游戏开发是个火热的行业,薪资待遇比较高,未来的发展方向和前景也比较不错,很多人也都想成为专业Unity游戏开发工程师,学习Unity游戏开发已经成为很多追求更好就业前景的人的选择.学习专 ...

  9. Unity - Humanoid设置Bip骨骼导入报错

    报错如下: 解决: 原因是biped骨骼必须按照Unity humanoid的要求设置,在max中设置如下: 转载于:https://www.cnblogs.com/CloudLiu/p/107460 ...

最新文章

  1. python excel操作单元格_python 操作excel表格的方法
  2. oracle学习笔记三
  3. apache hadoop_使用Apache Hadoop计算PageRanks
  4. 阿里P8大牛亲自教你!史上最全的Android面试题集锦,这原因我服了
  5. element 增加自由验证
  6. ei会议论文录用但不参加会议_美国研究生和博士申请论文发表真的很重要吗?...
  7. c mysql触发器,mysql触发器使用笔记
  8. 【Deep Learning】genCNN: A Convolutional Architecture for Word Sequence Prediction
  9. Linux负载均衡软件LVS(概念篇)
  10. 程序员 | 我在大厂烧垃圾
  11. Windows数据类型探幽
  12. 快速设置 Docker 的三种网络代理配置
  13. 高逼格/高效率办公工具、开发工具、开发插件等各种骚操作汇总 —— [努力更新中...]
  14. 概率论与数理统计的学习
  15. yum install安装时 提示“Another app is currently holding the yum lock; waiting for it to exit...”原因和解决
  16. python调用有道翻译_Python通过调用有道翻译api实现翻译功能示例
  17. html%2b怎么转换成加号,url 参数的加号变成空格处理
  18. 音视频开发---音视频同步算法
  19. java导入导出excel文件
  20. log4j 使用记录

热门文章

  1. 点击按钮显示文字,再次点击隐藏文字
  2. 布局:px to vw、vh
  3. 笔记本电脑玩游戏延迟高怎么办
  4. PathInfo模式的支持
  5. Android ToggleButton:状态切换的Button
  6. 电磁兼容工程(Electromagnetic compatibility engineering Herry Ott )读书笔记-- 章14 抗射频和瞬态信号干扰能力
  7. 平安科技移动开发二队技术周报(第十二期)
  8. 北工大计算机网络95分复习——【第三章 数据链路层】
  9. 干货!小样本分子性质预测新方法——性质感知的关系网络
  10. QQ小程序——无法正常创建项目与uniapp联动问题