change
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user