zoukankan      html  css  js  c++  java
  • 不使用插件 修改Unity和C#创建时的默认模板




    1、修改Visual中创建类时的默认模板

    C:Program Files (x86)->
    Microsoft Visual Studio 14.0-> (选择对应自己版本的文件夹)
    Common7 -> IDE -> ItemTemplates -> CSharp -> Code -> 2052->
    Class->Class.cs

    注意此处的文件可能会因为保护的原因不让直接修改,我们可以先复制一份到其他地方,修改完之后再把源文件替换掉。

    /****************************************************
        文件:#SCRIPTNAME#.cs
        作者:Ffly
        邮箱: jitengfeiwork@gmail.com
        日期:#CreateTime#
        功能:Nothing
    *****************************************************/
    
    using System;
    using System.Collections.Generic;
    $if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
    $endif$using System.Text;
    $if$ ($targetframeworkversion$ >= 4.5)using System.Threading.Tasks;
    $endif$
    namespace $rootnamespace$
    {
        class $safeitemrootname$
        {
        }
    }
    
    
    //显示出当前文件的名称
    #SCRIPTNAME#
    //显示当前文件创建的时间
    #CreateTime#
    

    效果图

    2、修改Unity中创建脚本时的默认模板

    C:Program Files (x86)->
    Microsoft Visual Studio 14.0-> (选择对应自己版本的文件夹)
    Common7 -> IDE -> ItemTemplates -> CSharp -> Code -> 2052->
    Class->Class.cs

    安装目录:UnityEditorDataResources
    ScriptTemplates81-C# Script-NewBehaviourScript.cs.txt

    /****************************************************
        文件:#SCRIPTNAME#.cs
        作者:Ffly
        邮箱: jitengfeiwork@gmail.com
        日期:#CreateTime#
        功能:Nothing
    *****************************************************/
    
    using UnityEngine;
    
    public class #SCRIPTNAME# : MonoBehaviour 
    {
    	private void Start(){
    		
    	}
    	private void Update(){
    		
    	}
    }
    

    但是注意,此处的日期在我们创建文件的时候并不会转换为当前的时间。
    所以我们需要一些代码的帮助。

    1、在项目目录下创建Editor文件夹
    2、新建脚本ScriptCreateInit.cs

    using System;
    using System.IO;
    
    public class ScriptCreateInit: UnityEditor.AssetModificationProcessor
    {
        private static void OnWillCreateAsset(string path)
        {
            path = path.Replace(".meta", "");
            if (path.EndsWith(".cs"))
            {
                string str = File.ReadAllText(path);
                str = str.Replace("Plane", Environment.UserName).Replace(
                                  "#CreateTime#", string.Concat(DateTime.Now.Year, "/", DateTime.Now.Month, "/",
                                    DateTime.Now.Day, " ", DateTime.Now.Hour, ":", DateTime.Now.Minute, ":", DateTime.Now.Second));
                File.WriteAllText(path, str);
            }
        }
    }
    

    这段代码主要作用就是把#CreateTime#转换为当前创建文件的时间。

  • 相关阅读:
    1.4 build命令
    2.2-2 文章模块开发【添加文章页面脚本编写】
    2.2-1 文章模块开发 【入口脚本及模板的创建】
    2.1 开始一个项目 【功能梳理】
    [微信小程序]不在以下合法域名列表中
    [微信小程序]swiper保持宽高比
    爸爸一路走好
    LVM日记
    欲玩Discuz_X3.2,无奈不支持php7,再装个php5.3,编译到一半报错
    /sbin/ldconfig: /usr/local/lib64/libstdc++.so.6.0.22-gdb.py 不是 ELF 文件
  • 原文地址:https://www.cnblogs.com/Fflyqaq/p/12071616.html
Copyright © 2011-2022 走看看