yyl
2026-05-11 51b0f6ed9f4e1d3bb6f8144470b46908c7699a96
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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;
        }
    }