【总】Unity Mono
版本Unity 6000.3.19f1Debug 扩展using System; using System.IO; using System.Text; using System.Threading.Tasks; using UnityEngine; public class DebugExtend { /// summary /// 是否记录日志信息 /// /summary public static bool IsRecordLog true; /// summary /// 打印日志信息 /// /summary /// param namemessage日志内容/param public static async void Log(object message) { Debug.Log(message); await RecordLogInfo(message, DebugLogType.Log); } /// summary /// 打印日志警告信息 /// /summary /// param namemessage日志内容/param public static async void LogWarning(object message) { Debug.LogWarning(message); await RecordLogInfo(message, DebugLogType.Warning); } /// summary /// 打印日志错误信息 /// /summary /// param namemessage日志内容/param public static async void LogError(object message) { Debug.LogError(message); await RecordLogInfo(message, DebugLogType.Error); } /// summary /// 打印日志信息 /// /summary /// param namemessage日志内容/param /// param namelogType打印日志类型/param public static void Log(object message, DebugLogType logType) { switch (logType) { case DebugLogType.Log: Log(message); break; case DebugLogType.Error: LogError(message); break; case DebugLogType.Warning: LogWarning(message); break; } } /// summary /// 记录日志信息 /// /summary /// param namemessage日志内容/param /// param namelogType打印日志类型/param /// returns/returns private static async Task RecordLogInfo(object message, DebugLogType logType) { if (!IsRecordLog) return; // 若关闭日志输出则不再进行记录 if (!Debug.unityLogger.logEnabled) return; string filePath ; string fileName ${logType}.txt; string newLine Environment.NewLine; // 换行符处理保证跨平台兼容性 string time_stamp ${DateTime.Now:yyyy-MM-dd HH:mm:ss}; // 当前时间戳 string appendContent $[{logType.ToString().ToLower()}] {time_stamp}{newLine}{message}{newLine}{newLine}; #if UNITY_EDITOR filePath Path.Combine(Application.dataPath, Editor, fileName); #elif UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL filePath Path.Combine(Application.persistentDataPath, fileName); #else filePath Path.Combine(Environment.CurrentDirectory, fileName); #endif #if UNITY_WEBGL !UNITY_EDITOR File.AppendAllText(filePath, appendContent, Encoding.UTF8); if (File.Exists(filePath)) Debug.Log($Save content\n{File.ReadAllText(filePath)}); await Task.Delay(1); #else Debug.Log(Save file path : filePath); // 确保目录存在 Directory.CreateDirectory(Path.GetDirectoryName(filePath)); // 异步追加文件内容避免主线程卡顿 await Task.Run(() { try { #if !UNITY_ANDROID !UNITY_IOS //// 方法一true表示追加模式 //using (StreamWriter writer new StreamWriter(filePath, true)) //{ // writer.Write(appendContent); //} #endif // 方法二追加文本如果文件不存在会自动创建指定编码格式 File.AppendAllText(filePath, appendContent, Encoding.UTF8); } catch (Exception e) { Debug.LogError($Unable to write log content{e.Message}); } }); #endif #if UNITY_EDITOR // 刷新资源数据刷新日志信息 UnityEditor.AssetDatabase.Refresh(); #endif } } public enum DebugLogType { Log, Warning, Error }获取本地IPusing System.Net.NetworkInformation; using System.Net.Sockets; public class MonoTools { public static string GetIP(AddressFAM addressFAM) { // https://blog.csdn.net/sinat_39291423/article/details/100733882 if (addressFAM AddressFAM.IPv6 !Socket.OSSupportsIPv6) { return null; } string output ; foreach (NetworkInterface item in NetworkInterface.GetAllNetworkInterfaces()) { #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN NetworkInterfaceType _type1 NetworkInterfaceType.Wireless80211; NetworkInterfaceType _type2 NetworkInterfaceType.Ethernet; if ((item.NetworkInterfaceType _type1 || item.NetworkInterfaceType _type2) item.OperationalStatus OperationalStatus.Up) #endif { foreach (UnicastIPAddressInformation ip in item.GetIPProperties().UnicastAddresses) { if (addressFAM AddressFAM.IPv4) { if (ip.Address.AddressFamily AddressFamily.InterNetwork) { output ip.Address.ToString(); } } else if (addressFAM AddressFAM.IPv6) { if (ip.Address.AddressFamily AddressFamily.InterNetworkV6) { output ip.Address.ToString(); } } } } } return output; } public enum AddressFAM { IPv4, IPv6 } }获取文件夹地址using UnityEngine; public class MonoTools { public static string GetPath(ProjectPath projectPath) { string path ; switch (projectPath) { case ProjectPath.Assets: path Application.dataPath; break; case ProjectPath.Data: path Application.persistentDataPath; break; case ProjectPath.Cache: path Application.temporaryCachePath; break; case ProjectPath.Project: path System.Environment.CurrentDirectory; break; case ProjectPath.StreamingAssets: path Application.streamingAssetsPath; break; } return path; } public enum ProjectPath { Project, Assets, Data, Cache, StreamingAssets } }关闭程序二次确定using System; using System.Runtime.InteropServices; using UnityEngine; public class ApplicationQuit : MonoBehaviour { #region variable /// summary 用于告诉Unity是否要退出 /summary private bool m_IsWantsToQuit false; /// summary 判断是否点击了退出程序按钮 /summary private bool m_IsClickCloseBtn false; /// summary 用于执行退出前的委托 /summary private Action m_WantsToQuitAction; #endregion [DllImport(User32.dll, SetLastError true, ThrowOnUnmappableChar true, CharSet CharSet.Auto)] public static extern int MessageBox(IntPtr handle, String message, String title, int type); private void Awake() { m_IsWantsToQuit false; m_IsClickCloseBtn false; Application.wantsToQuit WantsToQuit; } private void Start() { m_WantsToQuitAction () ShowMessageBox(); } private bool WantsToQuit() { if (!m_IsWantsToQuit !m_IsClickCloseBtn) m_WantsToQuitAction?.Invoke(); return m_IsWantsToQuit; } private void ShowMessageBox() { #if !UNITY_EDITOR m_IsClickCloseBtn true; int messageIndex MessageBox(IntPtr.Zero, 确定要退出程序吗, 提示, 1); if (messageIndex 1) { m_IsWantsToQuit true; Application.Quit(); // 杀死当前进程强制关闭 System.Diagnostics.Process.GetCurrentProcess().Kill(); } else { m_IsClickCloseBtn false; } #endif } }跳过启动Logo动画using UnityEngine; using UnityEngine.Rendering; using UnityEngine.Scripting; /// summary /// 项目运行初始化 /// Preserve此特性用于防止在打包的时候这个脚本没有被打包进程序 /// /summary [Preserve] public class RuntimeInitialize { [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSplashScreen)] private static void BeforeSplashScreen() { #if UNITY_WEBGL Application.focusChanged Application_FocusChanged; #else // 跳过Unity的启动Logo System.Threading.Tasks.Task.Run(AsyncSkip); //Task.Run(() SplashScreen.Stop(SplashScreen.StopBehavior.StopImmediate)); #endif } [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] private static void BeforeSceneLoad() { Debug.Log(加载开始); } [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)] private static void AfterSceneLoad() { Debug.Log(加载完成); } #if UNITY_WEBGL private static void Application_FocusChanged(bool obj) { Application.focusChanged - Application_FocusChanged; SplashScreen.Stop(SplashScreen.StopBehavior.StopImmediate); } #else private static void AsyncSkip() { SplashScreen.Stop(SplashScreen.StopBehavior.StopImmediate); } #endif }

相关新闻

第六届上海理工大学ACM程序设计全国挑战赛

第六届上海理工大学ACM程序设计全国挑战赛

比赛很不错,都不是很难,主要靠思维吧,学东西多了,喜欢把问题复杂化了,反而看不懂题目的本质 目录 A 签到题 L 签到题 G hsq的群 D hsq的神秘序列 问题:unordered_map查找配对元素位置会T N hsq的计组…

2026/11/2 2:33:44 阅读更多 →
AM335x PRCM时钟模块寄存器实战:从原理到DVFS与低功耗配置

AM335x PRCM时钟模块寄存器实战:从原理到DVFS与低功耗配置

1. 项目概述与PRCM模块核心价值在嵌入式系统开发,尤其是基于复杂SoC(片上系统)的设计中,时钟和电源管理往往是决定系统稳定性、性能与功耗的基石。很多开发者初次接触底层驱动时,面对动辄上千页的技术参考手册&#xf…

2026/11/2 19:08:44 阅读更多 →
YOLOv11导出为NCNN格式:移动端和嵌入式平台的轻量化部署方案

YOLOv11导出为NCNN格式:移动端和嵌入式平台的轻量化部署方案

前言:为什么你的YOLO模型在手机上跑不动? 做目标检测的兄弟们一定都有过这样的经历——在服务器上用YOLO模型跑得飞起,mAP漂亮得不行,结果一部署到手机或嵌入式设备上,要么推理慢得像PPT,要么内存直接爆掉,要么干脆闪退。 这不是你一个人的问题。 根据Ultralytics官方…

2026/10/28 15:35:40 阅读更多 →

最新新闻

Electron桌面应用开发实战:从环境搭建到打包发布全流程

Electron桌面应用开发实战:从环境搭建到打包发布全流程

做前端这些年,我大部分时间都在跟浏览器标签页打交道,直到第一次把桌面应用跑起来,才发现原来自己一直被限制在地址栏和刷新按钮围起来的框框里。Electron这个词,最开始是在某段时间频繁出现在同事的讨论里,一个用HTML…

2026/11/2 0:25:10 阅读更多 →
滑盖智能锁T109深度解析:结构原理、安装调试与故障排查

滑盖智能锁T109深度解析:结构原理、安装调试与故障排查

简介:亚太天能T109滑盖智能锁产品说明书是一份PDF格式的官方技术文档,主要面向智能锁安装人员、终端用户及售后维护者,帮助快速掌握产品安装、配置与常见故障处理。全包仅1个PDF文件,大小4.37MB,内容结构清晰&#xff…

2026/11/2 10:46:11 阅读更多 →
PMSM弱磁控制原理与Simulink建模:高速AGV驱动系统设计指南

PMSM弱磁控制原理与Simulink建模:高速AGV驱动系统设计指南

上个月我在调试一台高速AGV的驱动系统,整车要求空载跑到8m/s,电机转速已经拉到额定点,驱动器的输出电压也顶到了母线电压极限附近。再往上踩速度指令,转速纹丝不动,三相电流反而开始震荡。那会儿我的第一反应就是&…

2026/11/2 10:47:40 阅读更多 →
C++核心知识点:从内存管理到STL的实战指南

C++核心知识点:从内存管理到STL的实战指南

C 这门语言我前前后后折腾了十几年,用它写过嵌入式驱动、做过游戏服务端,也搭过基础组件库。每次看到新人一头扎进"C 核心知识点"这个搜索词,我其实挺感慨的——这门语言的难点从来不是语法多,而是知识点之间的耦合太深…

2026/11/2 1:16:51 阅读更多 →
T109滑盖智能锁怎么装?安装调试与故障排查全攻略

T109滑盖智能锁怎么装?安装调试与故障排查全攻略

简介:亚太天能T109滑盖智能锁产品说明书以PDF格式发布,适合智能锁用户、安装人员与售后维修人员阅读。内容围绕T109系列指纹密码刷卡锁展开,先介绍前面板、后面板、锁体、机械钥匙、电池盒盖等部件名称与功能,再给出完整安装步骤&…

2026/11/2 10:46:31 阅读更多 →
LLM知识降熵:从信息垄断到理解权下放

LLM知识降熵:从信息垄断到理解权下放

你有没有过这种经历:翻开源码注释、论文摘要或者一份专业报告,每个字都认识,连在一起却像天书。想找人聊聊,身边要么没人懂,要么懂的懒得跟你解释。后来我试着把同一段内容丢给一个大语言模型,几秒钟之后&a…

2026/11/2 10:46:26 阅读更多 →

日新闻

周新闻

月新闻