我有一个问题.我刚刚找到了C#Scripts的Unitys Script模板.
要获取脚本名称,请编写#SCRIPTNAME#,如下所示:
using UnityEngine;
using System.Collections;
public class #SCRIPTNAME# : MonoBehavIoUr
{
void Start ()
{
}
void Update ()
{
}
}
比它创建具有正确名称的脚本,但有没有像#FOLDERNAME那样的东西#所以我可以在创建脚本时直接将它放在正确的命名空间中?
解决方法:
没有像#FOLDERNAME#这样的内置模板变量.
根据this post,只有3个魔术变量.
>“#NAME#”
>“#SCRIPTNAME#”
>“#SCRIPTNAME_LOWER#”
但是你总是可以挂钩脚本的创建过程并使用AssetModificationProcessor
自己附加命名空间.
//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();
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。