189 lines
5.2 KiB
C#
189 lines
5.2 KiB
C#
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 示例调试函数集合
|
|
/// 使用 [DebugButton] 特性来标记方法,它们会自动出现在调试工具中
|
|
/// </summary>
|
|
public static class SampleDebugFunctions
|
|
{
|
|
// 基础示例
|
|
[DebugButton("打印Hello World")]
|
|
public static void PrintHelloWorld()
|
|
{
|
|
Debug.Log("Hello World from Debug Tool!");
|
|
}
|
|
|
|
// 带颜色的按钮
|
|
[DebugButton("绿色按钮示例", 0.2f, 0.8f, 0.2f)]
|
|
public static void GreenButtonExample()
|
|
{
|
|
Debug.Log("这是一个绿色按钮");
|
|
}
|
|
|
|
[DebugButton("红色按钮示例", 0.8f, 0.2f, 0.2f)]
|
|
public static void RedButtonExample()
|
|
{
|
|
Debug.LogWarning("这是一个红色按钮 - 通常用于危险操作");
|
|
}
|
|
|
|
[DebugButton("蓝色按钮示例", 0.2f, 0.5f, 0.8f)]
|
|
public static void BlueButtonExample()
|
|
{
|
|
Debug.Log("这是一个蓝色按钮");
|
|
}
|
|
|
|
// 时间相关
|
|
[DebugButton("显示当前时间", 0.7f, 0.7f, 0.2f)]
|
|
public static void ShowCurrentTime()
|
|
{
|
|
Debug.Log($"当前时间: {System.DateTime.Now:yyyy-MM-dd HH:mm:ss}");
|
|
}
|
|
|
|
[DebugButton("暂停游戏", 0.9f, 0.5f, 0.2f)]
|
|
public static void PauseGame()
|
|
{
|
|
Time.timeScale = 0f;
|
|
Debug.Log("游戏已暂停");
|
|
}
|
|
|
|
[DebugButton("恢复游戏", 0.2f, 0.9f, 0.5f)]
|
|
public static void ResumeGame()
|
|
{
|
|
Time.timeScale = 1f;
|
|
Debug.Log("游戏已恢复");
|
|
}
|
|
|
|
// 系统信息
|
|
[DebugButton("打印系统信息")]
|
|
public static void PrintSystemInfo()
|
|
{
|
|
Debug.Log($"平台: {Application.platform}");
|
|
Debug.Log($"Unity版本: {Application.unityVersion}");
|
|
Debug.Log($"设备型号: {SystemInfo.deviceModel}");
|
|
Debug.Log($"操作系统: {SystemInfo.operatingSystem}");
|
|
}
|
|
|
|
// 内存管理
|
|
[DebugButton("强制GC", 0.9f, 0.3f, 0.3f)]
|
|
public static void ForceGarbageCollection()
|
|
{
|
|
System.GC.Collect();
|
|
Debug.Log("已触发垃圾回收");
|
|
}
|
|
|
|
[DebugButton("清理未使用资源", 0.9f, 0.5f, 0.3f)]
|
|
public static void UnloadUnusedAssets()
|
|
{
|
|
Resources.UnloadUnusedAssets();
|
|
Debug.Log("已清理未使用的资源");
|
|
}
|
|
|
|
// 场景管理
|
|
[DebugButton("重新加载当前场景", 0.8f, 0.4f, 0.2f)]
|
|
public static void ReloadCurrentScene()
|
|
{
|
|
UnityEngine.SceneManagement.SceneManager.LoadScene(
|
|
UnityEngine.SceneManagement.SceneManager.GetActiveScene().name);
|
|
Debug.Log("正在重新加载当前场景");
|
|
}
|
|
|
|
// 屏幕设置
|
|
[DebugButton("切换全屏")]
|
|
public static void ToggleFullscreen()
|
|
{
|
|
Screen.fullScreen = !Screen.fullScreen;
|
|
Debug.Log($"全屏模式: {Screen.fullScreen}");
|
|
}
|
|
|
|
[DebugButton("设置目标帧率60")]
|
|
public static void SetTargetFrameRate60()
|
|
{
|
|
Application.targetFrameRate = 60;
|
|
Debug.Log("目标帧率设置为60");
|
|
}
|
|
|
|
[DebugButton("设置目标帧率30")]
|
|
public static void SetTargetFrameRate30()
|
|
{
|
|
Application.targetFrameRate = 30;
|
|
Debug.Log("目标帧率设置为30");
|
|
}
|
|
|
|
[DebugButton("取消帧率限制")]
|
|
public static void UnlimitedFrameRate()
|
|
{
|
|
Application.targetFrameRate = -1;
|
|
Debug.Log("已取消帧率限制");
|
|
}
|
|
|
|
// 音频设置
|
|
[DebugButton("静音", 0.5f, 0.5f, 0.5f)]
|
|
public static void MuteAudio()
|
|
{
|
|
AudioListener.volume = 0f;
|
|
Debug.Log("已静音");
|
|
}
|
|
|
|
[DebugButton("取消静音", 0.2f, 0.8f, 0.8f)]
|
|
public static void UnmuteAudio()
|
|
{
|
|
AudioListener.volume = 1f;
|
|
Debug.Log("已取消静音");
|
|
}
|
|
|
|
// 输入对话框示例
|
|
[DebugButton("输入测试", 0.5f, 0.7f, 0.9f)]
|
|
public static void ShowInputDialogExample()
|
|
{
|
|
UniversalDebugTool.ShowInputDialog("请输入内容", (input) =>
|
|
{
|
|
Debug.Log($"你输入了: {input}");
|
|
}, "默认值");
|
|
}
|
|
|
|
// 数字输入示例
|
|
[DebugButton("数字输入测试", 0.5f, 0.7f, 0.9f)]
|
|
public static void ShowNumberInputDialog()
|
|
{
|
|
UniversalDebugTool.ShowInputDialog("请输入数字", (input) =>
|
|
{
|
|
if (float.TryParse(input, out float value))
|
|
{
|
|
Debug.Log($"你输入的数字是: {value}");
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning("输入的不是有效数字");
|
|
}
|
|
}, "100", TMPro.TMP_InputField.ContentType.DecimalNumber);
|
|
}
|
|
|
|
// PlayerPrefs相关
|
|
[DebugButton("清空PlayerPrefs", 0.9f, 0.2f, 0.2f)]
|
|
public static void ClearPlayerPrefs()
|
|
{
|
|
PlayerPrefs.DeleteAll();
|
|
PlayerPrefs.Save();
|
|
Debug.Log("已清空所有PlayerPrefs数据");
|
|
}
|
|
|
|
[DebugButton("保存PlayerPrefs")]
|
|
public static void SavePlayerPrefs()
|
|
{
|
|
PlayerPrefs.Save();
|
|
Debug.Log("已保存PlayerPrefs");
|
|
}
|
|
|
|
// 退出游戏
|
|
[DebugButton("退出应用", 1f, 0f, 0f)]
|
|
public static void QuitApplication()
|
|
{
|
|
Debug.Log("退出应用");
|
|
#if UNITY_EDITOR
|
|
UnityEditor.EditorApplication.isPlaying = false;
|
|
#else
|
|
Application.Quit();
|
|
#endif
|
|
}
|
|
}
|