Unity创建脚本显示自己的名字以及时间

using UnityEngine;
using System.IO;
using System.Text;
using System;

public class QHF_Editor : UnityEditor.AssetModificationProcessor
{

    static string head = @"//**********************************************************************
// 文件名(File Name):             file
// 作者(Author):                  author
// 创建时间(CreateTime):          time
// **********************************************************************";

    private static void OnWillCreateAsset(string path)
    {
        StringBuilder sb = new StringBuilder();
        path = path.Replace(".meta", "");
        UnityEditor.AssetDatabase.Refresh();
        Debug.Log(path);
        if (path.EndsWith(".cs"))
        {
            string[] iterm = path.Split('/');
            sb.Append(head);
            sb.Replace("file", iterm[iterm.Length - 1]);
            sb.Replace("time", DateTime.Now.ToShortDateString());
            sb.Append("\n");
            sb.AppendLine(File.ReadAllText(path));
            File.WriteAllText(path, sb.ToString());
            UnityEditor.AssetDatabase.Refresh();
        }

    }
}
 

猜你喜欢

转载自blog.csdn.net/wxxqhf/article/details/85044863