Unity将默认命名空间添加到脚本模板? [英] Unity Add Default Namespace to Script Template?

查看:551
本文介绍了Unity将默认命名空间添加到脚本模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题.我刚刚找到了C#脚本的Unitys脚本模板. 为了获得脚本名称,您可以编写#SCRIPTNAME#,它看起来像这样:

I got a question. I just found Unitys Script template for C# Scripts. And to get the Script name you write #SCRIPTNAME# so it looks like this:

using UnityEngine;
using System.Collections;

public class #SCRIPTNAME# : MonoBehaviour 
{
    void Start () 
    {

    }

    void Update () 
    {

    }
}

比用正确的名称创建脚本,但是是否有#FOLDERNAME#之类的东西,所以我可以在创建脚本时直接将其放在正确的名称空间中?

Than it would create the script with the right name, but is there somthing like #FOLDERNAME# So I can put it in the right namespace dirrectly when creating the script?

推荐答案

没有像 #FOLDERNAME#这样的内置模板变量.

There is no built-in template variables like #FOLDERNAME#.

根据这篇文章只有3个魔术变量.

According to this post, there are only 3 magic variables.

  • #NAME#"
  • #SCRIPTNAME#"
  • #SCRIPTNAME_LOWER#"

但是您始终可以加入脚本的创建过程,并使用 .

But you can always hook into the creation process of a script and append the namespace yourself using AssetModificationProcessor.

此处是向创建的脚本中添加一些自定义数据的示例.

Here is an example that adds some custom data to the created script.

//Assets/Editor/KeywordReplace.cs
using UnityEngine;
using UnityEditor;
using System.Collections;

public class KeywordReplace : UnityEditor.AssetModificationProcessor
{

   public static void OnWillCreateAsset ( string path )
   {
     path = path.Replace( ".meta", "" );
     int index = path.LastIndexOf( "." );
     string file = path.Substring( index );
     if ( file != ".cs" && file != ".js" && file != ".boo" ) return;
     index = Application.dataPath.LastIndexOf( "Assets" );
     path = Application.dataPath.Substring( 0, index ) + path;
     file = System.IO.File.ReadAllText( path );

     file = file.Replace( "#CREATIONDATE#", System.DateTime.Now + "" );
     file = file.Replace( "#PROJECTNAME#", PlayerSettings.productName );
     file = file.Replace( "#SMARTDEVELOPERS#", PlayerSettings.companyName );

     System.IO.File.WriteAllText( path, file );
     AssetDatabase.Refresh();
   }
}

这篇关于Unity将默认命名空间添加到脚本模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆