This commit is contained in:
2026-02-12 22:15:15 +08:00
parent 47a5cff08b
commit 502c6efedc
58 changed files with 2114 additions and 708 deletions

View File

@@ -44,5 +44,64 @@ namespace NBF
Debug.LogWarning($"androidId={androidId}");
return androidId;
}
public static string GetDeviceModel()
{
string deviceModel = string.Empty;
#if UNITY_EDITOR
// 在编辑器中使用 SystemInfo
deviceModel = SystemInfo.deviceModel;
#elif UNITY_ANDROID
if (Application.platform == RuntimePlatform.Android)
{
try
{
// 方法1使用 SystemInfo.deviceModel推荐最简单
deviceModel = SystemInfo.deviceModel;
// 方法2通过 Android API 获取更详细的信息(可选)
/*
using (AndroidJavaClass buildClass = new AndroidJavaClass("android.os.Build"))
{
string manufacturer = buildClass.GetStatic<string>("MANUFACTURER");
string model = buildClass.GetStatic<string>("MODEL");
string product = buildClass.GetStatic<string>("PRODUCT");
string device = buildClass.GetStatic<string>("DEVICE");
// 可以根据需要组合不同的信息
deviceModel = $"{manufacturer} {model}";
// 或者更详细的deviceModel = $"{manufacturer} {model} (Product: {product}, Device: {device})";
}
*/
}
catch (System.Exception e)
{
Debug.LogError("Error while fetching device model: " + e.Message);
deviceModel = SystemInfo.deviceModel; // 失败时回退到 SystemInfo
}
}
else
{
deviceModel = SystemInfo.deviceModel;
}
#elif UNITY_IOS
// iOS平台
deviceModel = SystemInfo.deviceModel;
// 如果需要获取更友好的设备名称(如 "iPhone 14 Pro" 而不是 "iPhone15,2"
if (Application.platform == RuntimePlatform.IPhonePlayer)
{
deviceModel = UnityEngine.iOS.Device.generation.ToString();
}
#else
// 其他平台
deviceModel = SystemInfo.deviceModel;
#endif
Debug.LogWarning($"Device Model: {deviceModel}");
return deviceModel;
}
}
}