unity创建新脚本自动添加版权声明,文件名,作者,创建时间等

  • 1.修改81-C# Script-NewBehaviourScript.cs.txt文件

打开unity安装目录对应.\Unity\Editor\Data\Resources\ScriptTemplates\81-C# Script-NewBehaviourScript.cs.txt文件
我的目录:C:\Program Files\Unity\Editor\Data\Resources\ScriptTemplates\81-C# Script-NewBehaviourScript.cs.txt
我的文件修改如下:

//=====================================================
// - FileName:      #SCRIPTNAME#.cs
// - Created:       #AuthorName#
// - UserName:      #CreateTime#
// - Email:         #AuthorEmail#
// - Description:   
// -  (C) Copyright 2008 - 2015, hehehuyu,Inc.
// -  All Rights Reserved.
//======================================================
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class #SCRIPTNAME# : MonoBehaviour {

    // Use this for initialization
    void Start () {
        #NOTRIM#
    }
    
    // Update is called once per frame
    void Update () {
        #NOTRIM#
    }
}

  • 2.添加脚本Copyright.cs

image.png

在工程中的Editor目录下添加脚本Copyright.cs

//=====================================================
// - FileName:      #SCRIPTNAME#.cs
// - Created:       #AuthorName#
// - UserName:      #CreateTime#
// - Email:         #AuthorEmail#
// - Description:   
// -  (C) Copyright 2008 - 2015, hehehuyu,Inc.
// -  All Rights Reserved.
//======================================================
using UnityEngine;
using System.Collections;
using System.IO;

public class Copyright: UnityEditor.AssetModificationProcessor
{
    private const string AuthorName="wangguoqing";
    private const string AuthorEmail = "wangguoqing@hehegames.cn";

    private const string DateFormat = "yyyy/MM/dd HH:mm:ss";
    private static void OnWillCreateAsset(string path)
    {
        path = path.Replace(".meta", "");
        if (path.EndsWith(".cs"))
        {
            string allText = File.ReadAllText(path);
            allText = allText.Replace("#AuthorName#", AuthorName);
            allText = allText.Replace("#AuthorEmail#", AuthorEmail);
            allText = allText.Replace("#CreateTime#", System.DateTime.Now.ToString(DateFormat));            
            File.WriteAllText(path, allText);
            UnityEditor.AssetDatabase.Refresh();
        }

    }
}

效果如下

image.png

参考文章:http://blog.csdn.net/u013108312/article/details/54174757

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 很多人一起可能都使用过VS或者Eclipse之类的IDE来开发,都使用过在脚本的头部添加注释,标注时间,作者,修改...
    游戏开发小Y阅读 1,783评论 0 0
  • 这篇文字是Kinect v2 Examples with MS-SDK 这个插件的作者编写,笔者觉得非常值得一看,...
    雨落随风阅读 16,545评论 0 18
  • 1、第一次自己贴手机膜,每次贴膜都是让他们给贴,收费还挺高的。所以这次我在超市买了手机膜,才十块钱,反正想着贴坏就...
    我心我愿秀阅读 148评论 0 2
  • 嗡嗡嗡…… “喂,我正伤感着呢” “哦,那你继续” “我说,你别现在打扰我!要吸,待会来” “我一会就完工” “那...
    嘆墨阅读 160评论 0 1
  • 天鹅一生严守一夫一妻制,若一方死亡,另一方则不食不眠,一意殉情 所以,天鹅,被视为忠诚和永恒爱情的象征。人们常...
    someway阅读 22,241评论 0 1