using System;
|
using UnityEngine;
|
|
/// <summary>
|
/// 性能档次枚举
|
/// </summary>
|
public enum PerformanceLevel
|
{
|
/// <summary>低端设备(内存 < 2GB,2019年前机型)</summary>
|
Low,
|
|
/// <summary>中端设备(内存 2-4GB,2019-2021年机型)</summary>
|
Medium,
|
|
/// <summary>高端设备(内存 > 4GB,2021年后旗舰)</summary>
|
High
|
}
|
|
/// <summary>
|
/// 设备性能档次和屏幕信息
|
/// </summary>
|
[Serializable]
|
public class DeviceProfile
|
{
|
/// <summary>性能档次</summary>
|
public PerformanceLevel PerformanceLevel = PerformanceLevel.Medium;
|
|
/// <summary>总内存大小(MB)</summary>
|
public long TotalMemory;
|
|
/// <summary>屏幕宽度(像素)</summary>
|
public int ScreenWidth;
|
|
/// <summary>屏幕高度(像素)</summary>
|
public int ScreenHeight;
|
|
/// <summary>安全区域</summary>
|
public Rect SafeArea;
|
|
/// <summary>屏幕DPI</summary>
|
public float DPI;
|
|
/// <summary>设备型号</summary>
|
public string DeviceModel;
|
|
/// <summary>
|
/// 从Unity SystemInfo检测设备配置
|
/// </summary>
|
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;
|
}
|
}
|