214 lines
6.8 KiB
C#
214 lines
6.8 KiB
C#
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using System.IO;
|
||
using System.Text.RegularExpressions;
|
||
using System;
|
||
using System.Text;
|
||
using System.Runtime.InteropServices;
|
||
|
||
public class readDeviceInfo : MonoBehaviour
|
||
{
|
||
public Button reread_button;
|
||
public Button export_button;
|
||
public Text deviceInfo_text;
|
||
|
||
void Start()
|
||
{
|
||
if (reread_button != null)
|
||
{
|
||
reread_button.onClick.AddListener(read_deviceInfo);
|
||
}
|
||
|
||
if (export_button != null)
|
||
{
|
||
export_button.onClick.AddListener(ExportToFile);
|
||
}
|
||
|
||
if (deviceInfo_text != null)
|
||
deviceInfo_text.supportRichText = true;
|
||
|
||
read_deviceInfo();
|
||
}
|
||
|
||
void OnDestroy()
|
||
{
|
||
if (reread_button != null)
|
||
reread_button.onClick.RemoveListener(read_deviceInfo);
|
||
if (export_button != null)
|
||
export_button.onClick.RemoveListener(ExportToFile);
|
||
}
|
||
|
||
void Update()
|
||
{
|
||
|
||
}
|
||
|
||
private void read_deviceInfo()
|
||
{
|
||
System.Text.StringBuilder sb = new System.Text.StringBuilder();
|
||
|
||
void AddEntry(string title, object value)
|
||
{
|
||
string str;
|
||
if (value == null) str = "";
|
||
else if (value is bool b) str = b ? "����" : "����";
|
||
else str = value.ToString();
|
||
|
||
sb.AppendLine($"<b>{title}</b>");
|
||
sb.AppendLine(str);
|
||
sb.AppendLine();
|
||
}
|
||
|
||
AddEntry("ƽ̨", Application.platform.ToString());
|
||
AddEntry("����Ŀ¼", Application.dataPath);
|
||
AddEntry("persistent ����·��", Application.persistentDataPath);
|
||
|
||
AddEntry("����ϵͳ", SystemInfo.operatingSystem);
|
||
AddEntry("�豸����", SystemInfo.deviceName);
|
||
AddEntry("�豸�ͺ�", SystemInfo.deviceModel);
|
||
AddEntry("�豸ΨһID", SystemInfo.deviceUniqueIdentifier);
|
||
|
||
AddEntry("CPU", SystemInfo.processorType);
|
||
AddEntry("CPU������", SystemInfo.processorCount);
|
||
AddEntry("ϵͳ�ڴ� (MB)", SystemInfo.systemMemorySize);
|
||
|
||
AddEntry("ͼ���豸����", SystemInfo.graphicsDeviceName);
|
||
AddEntry("ͼ���豸��Ӧ��", SystemInfo.graphicsDeviceVendor);
|
||
AddEntry("DirectX", SystemInfo.graphicsDeviceType.ToString());
|
||
AddEntry("�Դ� (MB)", SystemInfo.graphicsMemorySize);
|
||
|
||
AddEntry("��Ļ�ֱ���", $"{Screen.currentResolution.width} x {Screen.currentResolution.height} @ {Screen.currentResolution.refreshRateRatio.value:0.##}Hz");
|
||
AddEntry("��ĻDPI", Screen.dpi);
|
||
AddEntry("��ʾģʽ", Screen.fullScreenMode.ToString());
|
||
|
||
try
|
||
{
|
||
AddEntry("��ص���", $"{SystemInfo.batteryLevel * 100:F0}%");
|
||
}
|
||
catch
|
||
{
|
||
AddEntry("���״̬", "��֧��");
|
||
}
|
||
|
||
AddEntry("�����������������༭��", "v1.1h02e");
|
||
AddEntry("����������С��Ϸ����", "v1.301");
|
||
AddEntry("����Ϸ�汾��", "code::testingVersion1062");
|
||
AddEntry("��¼����", "Steam Client");
|
||
|
||
AddEntry(".NET Framework", "8.0 +");
|
||
AddEntry("��������ߴ�", SystemInfo.maxTextureSize);
|
||
|
||
AddEntry("���ú�̨����", Application.runInBackground);
|
||
AddEntry("���߳���Ⱦ", SystemInfo.graphicsMultiThreaded);
|
||
|
||
string output = sb.ToString();
|
||
|
||
if (deviceInfo_text != null)
|
||
{
|
||
deviceInfo_text.text = output;
|
||
}
|
||
}
|
||
|
||
void ExportToFile()
|
||
{
|
||
if (deviceInfo_text == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
string path = ShowSaveFileDialog();
|
||
if (string.IsNullOrEmpty(path))
|
||
{
|
||
return;
|
||
}
|
||
|
||
try
|
||
{
|
||
string raw = deviceInfo_text.text;
|
||
// Remove <b> tags and add colon after title
|
||
string cleaned = Regex.Replace(raw, "<b>(.*?)</b>", "$1:");
|
||
File.WriteAllText(path, cleaned);
|
||
}
|
||
catch (System.Exception)
|
||
{
|
||
}
|
||
}
|
||
|
||
string ShowSaveFileDialog()
|
||
{
|
||
#if UNITY_EDITOR
|
||
string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
|
||
string path = UnityEditor.EditorUtility.SaveFilePanel("�����豸��Ϣ", desktop, "device_info", "txt");
|
||
return string.IsNullOrEmpty(path) ? null : path;
|
||
#elif UNITY_STANDALONE_WIN
|
||
try
|
||
{
|
||
// Use native Windows SaveFile dialog via comdlg32 GetSaveFileName
|
||
OpenFileName ofn = new OpenFileName();
|
||
ofn.structSize = Marshal.SizeOf(ofn);
|
||
ofn.filter = "Text files (*.txt)\0*.txt\0All files (*.*)\0*.*\0";
|
||
ofn.file = new string('\0', 260);
|
||
ofn.maxFile = ofn.file.Length;
|
||
ofn.fileTitle = new string('\0', 260);
|
||
ofn.maxFileTitle = ofn.fileTitle.Length;
|
||
ofn.initialDir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
|
||
ofn.title = "�����豸��Ϣ";
|
||
ofn.defExt = "txt";
|
||
ofn.flags = OpenFileNameFlags.OFN_OVERWRITEPROMPT;
|
||
|
||
if (GetSaveFileName(ofn))
|
||
{
|
||
// Trim any trailing nulls
|
||
return ofn.file.TrimEnd('\0');
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
|
||
return null;
|
||
#else
|
||
string defaultPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "device_info.txt");
|
||
return defaultPath;
|
||
#endif
|
||
}
|
||
|
||
#if UNITY_STANDALONE_WIN
|
||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
||
private class OpenFileName
|
||
{
|
||
public int structSize = 0;
|
||
public IntPtr dlgOwner = IntPtr.Zero;
|
||
public IntPtr instance = IntPtr.Zero;
|
||
public string filter = null;
|
||
public string customFilter = null;
|
||
public int maxCustFilter = 0;
|
||
public int filterIndex = 0;
|
||
public string file = null;
|
||
public int maxFile = 0;
|
||
public string fileTitle = null;
|
||
public int maxFileTitle = 0;
|
||
public string initialDir = null;
|
||
public string title = null;
|
||
public int flags = 0;
|
||
public short fileOffset = 0;
|
||
public short fileExtension = 0;
|
||
public string defExt = null;
|
||
public IntPtr custData = IntPtr.Zero;
|
||
public IntPtr hook = IntPtr.Zero;
|
||
public string templateName = null;
|
||
public IntPtr reservedPtr = IntPtr.Zero;
|
||
public int reservedInt = 0;
|
||
public int flagsEx = 0;
|
||
}
|
||
|
||
private static class OpenFileNameFlags
|
||
{
|
||
public const int OFN_OVERWRITEPROMPT = 0x00000002;
|
||
}
|
||
|
||
[DllImport("comdlg32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||
private static extern bool GetSaveFileName([In, Out] OpenFileName ofn);
|
||
#endif
|
||
}
|