【Unity日常开发】创建脚本自动添加头注
发布日期:2021-06-30 11:40:16 浏览次数:2 分类:技术文章

本文共 1421 字,大约阅读时间需要 4 分钟。

推荐阅读

一、前言

有些代码,会在代码的头部写上一大堆的注释:

(1)说明这是谁写的
(2)什么时候创建的
(3)什么版本
(4)什么作用
(5)版本变更时间

这样就可以很清晰的看到这个脚本是谁写的,写了什么,变更的时间版本等,利于开发。

总是总是写一个脚本,复制过去,改一下,也感觉有些繁琐。

接下来就教大家如何自动为脚本添加头注。

二、实现

using System.IO;namespace Editor{
/// /// 创建脚本自动添加头注 /// public class FirstComment : UnityEditor.AssetModificationProcessor {
/// /// 在资源创建生成.meta时调用 /// /// 自动传入资源路径 public static void OnWillCreateAsset(string path) {
path = path.Replace(".meta", ""); if (!path.EndsWith(".cs")) return; string allText = "// ========================================================\r\n" + "// 描述:\r\n" + "// 功能:\r\n" + "// 作者:XXX \r\n" + "// 创建时间:#CreateTime#\r\n" + "// 版本:1.0\r\n" + "// 变更时间:\r\n" + "// 变更版本:#CreateTime2#\r\n" + "// 脚本路径:#ScripsPath#\r\n" + "// ========================================================\r\n"; allText += File.ReadAllText(path); allText = allText.Replace("#CreateTime#", System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); allText = allText.Replace("#ScripsPath#", path); File.WriteAllText(path, allText); } }}

效果图:

在这里插入图片描述

转载地址:https://itmonon.blog.csdn.net/article/details/117330558 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:【Unity3D应用案例系列】计算器工具开发
下一篇:【Unity3D应用案例系列】时钟、钟表小组件开发

发表评论

最新留言

能坚持,总会有不一样的收获!
[***.219.124.196]2024年04月29日 01时23分39秒