using System;
using UnityEngine;
///
/// 性能档次枚举
///
public enum PerformanceLevel
{
/// 低端设备(内存 < 2GB,2019年前机型)
Low,
/// 中端设备(内存 2-4GB,2019-2021年机型)
Medium,
/// 高端设备(内存 > 4GB,2021年后旗舰)
High
}
///
/// 设备性能档次和屏幕信息
///
[Serializable]
public class DeviceProfile
{
/// 性能档次
public PerformanceLevel PerformanceLevel = PerformanceLevel.Medium;
/// 总内存大小(MB)
public long TotalMemory;
/// 屏幕宽度(像素)
public int ScreenWidth;
/// 屏幕高度(像素)
public int ScreenHeight;
/// 安全区域
public Rect SafeArea;
/// 屏幕DPI
public float DPI;
/// 设备型号
public string DeviceModel;
///
/// 从Unity SystemInfo检测设备配置
///
public static DeviceProfile DetectFromSystem()
{
var profile = new DeviceProfile
{
TotalMemory = UnityEngine.SystemInfo.systemMemorySize,
ScreenWidth = Screen.width,
ScreenHeight = Screen.height,
SafeArea = Screen.safeArea,
DPI = Screen.dpi,
DeviceModel = UnityEngine.SystemInfo.deviceModel
};
// 根据内存判定性能档次
#if UNITY_WEBGL
// WebGL下systemMemorySize不准确,默认中端
profile.PerformanceLevel = PerformanceLevel.Medium;
#else
if (profile.TotalMemory < 2048)
profile.PerformanceLevel = PerformanceLevel.Low;
else if (profile.TotalMemory < 4096)
profile.PerformanceLevel = PerformanceLevel.Medium;
else
profile.PerformanceLevel = PerformanceLevel.High;
#endif
return profile;
}
}