浮动小游戏已经基本搞好
新做了两个设置界面 一些bug修复和优化
This commit is contained in:
@@ -0,0 +1,213 @@
|
||||
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.refreshRate}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
|
||||
}
|
||||
Reference in New Issue
Block a user