Unity VS script automatically add header comments

1. First find the Unity installation directory folder ScriptTemplates: D: \ Program Files \ Unity \ Editor \ Data \ Resources \ ScriptTemplates, Unity in the script template is used to create a copy, a copy of the script is in the folder.
2. Open the inside of the 81-C # Script-NewBehaviourScript.cs, this is C # script to create a template, add annotation content in it:
/ **
* Copyright (C) 2015 by # COMPANY #
. * All Rights Reserved
* FileName: # # ScriptFullName
* the Author: the AUTHOR # #
* Version: VERSION # #
* UnityVersion: UNITYVERSION # #
* a Date: # DATE #
* the Description:
* History:
* /
the using UnityEngine;
the using the System.Collections;

public class SCRIPTNAME # #: {MonoBehaviour

Initialization for the Use the this //
void the Start () {

}

// Called the Update Once per IS Frame
void the Update () {

}
}

3. Modify saved, and then enter the Unit editor, create a script in the Editor folder: AddFileHeadComment.cs
a using UnityEditor;
a using UnityEngine;
a using the System.IO;

public class AddFileHeadComment: UnityEditor.AssetModificationProcessor
{
/// <the Summary>
// / this function is created in the asset finished, the file has been generated on a disk, but was not called before the file and generate .meta Import
/// </ the Summary>
/// <param name = "newFileMeta"> newfilemeta by creating a file the path coupled .meta composition </ param>
public static void OnWillCreateAsset (String newFileMeta)
{
String newFilePath = newFileMeta.Replace ( "Meta.", "");
String FileExt = Path.GetExtension (newFilePath);
IF (FileExt ! = ".cs")
{
return;
}
// Note, Application.datapath internet will vary according to the use
string realPath = Application.dataPath.Replace("Assets", "") + newFilePath;
string scriptContent = File.ReadAllText(realPath);

//这里实现自定义的一些规则
scriptContent = scriptContent.Replace("#SCRIPTFULLNAME#", Path.GetFileName(newFilePath));
scriptContent = scriptContent.Replace("#COMPANY#", PlayerSettings.companyName);
scriptContent = scriptContent.Replace("#AUTHOR#", "Passion");
scriptContent = scriptContent.Replace("#VERSION#", "1.0");
scriptContent = scriptContent.Replace("#UNITYVERSION#", Application.unityVersion);
scriptContent = scriptContent.Replace("#DATE#", System.DateTime.Now.ToString("yyyy-MM-dd"));

File.WriteAllText(realPath, scriptContent);
}

}

4. Save the script, the script uses the principle is to replace real information on the key ## at the time of Unity save the script, and the time to reach the company, author, etc. accurate information to customize.
5.OK, the right to create a script to try it!


Supplementary: Mac version of Unity address is:
 /Applications/Unity/Unity.app/Contents/Resources/ScriptTemplates/81-C \ # \ Script-NewBehaviourScript.cs.txt
------------- ---
Disclaimer: this article is CSDN blogger "PassionY 'original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/yupu56/article/details/52326930

Guess you like

Origin www.cnblogs.com/yunpeng130/p/11635052.html