unity之定制脚本模板
1、unity的脚本模板
using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class NewBehaviourScript : MonoBehaviour { // Use this for initialization
void Start () { } // Update is called once per frame
void Update () { }
}
2、修改默认脚本模板
////////////////////////////////////////////////////////////////////
// _ooOoo_ //
// o8888888o //
// 88" . "88 //
// (| ^_^ |) //
// O\ = /O //
// ____/`---'\____ //
// .' \\| |// `. //
// / \\||| : |||// \ //
// / _||||| -:- |||||- \ //
// | | \\\ - /// | | //
// | \_| ''\---/'' | | //
// \ .-\__ `-` ___/-. / //
// ___`. .' /--.--\ `. . ___ //
// ."" '< `.___\_<|>_/___.' >'"". //
// | | : `- \`.;`\ _ /`;.`/ - ` : | | //
// \ \ `-. \_ __\ /__ _/ .-` / / //
// ========`-.____`-.___\_____/___.-`____.-'======== //
// `=---=' //
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //
// 佛祖保佑 永不宕机 永无BUG //
//////////////////////////////////////////////////////////////////// using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class #SCRIPTNAME# : MonoBehaviour { // Use this for initialization
void Start () {
#NOTRIM#
} // Update is called once per frame
void Update () {
#NOTRIM#
}
}
3、拓展脚本模板
using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class MyNewBehaviourScript : MonoBase { //添加事件监听
protected override void AddMsgListener()
{ } //处理消息
protected override void HandleMsg(MsgBase msg)
{
switch (msg.id)
{
default:
break;
}
} }

using UnityEditor;
using UnityEngine;
using System;
using System.IO;
using UnityEditor.ProjectWindowCallback;
using System.Text;
using System.Text.RegularExpressions; public class CreateTemplateScript { //脚本模板路径
private const string TemplateScriptPath = "Assets/Editor/MyTemplateScript.cs.txt"; //菜单项
[MenuItem("Assets/Create/C# FrameScript", false, )]
static void CreateScript()
{
string path = "Assets";
foreach (UnityEngine.Object item in Selection.GetFiltered(typeof(UnityEngine.Object),SelectionMode.Assets))
{
path = AssetDatabase.GetAssetPath(item);
if (!string.IsNullOrEmpty(path) && File.Exists(path))
{
path = Path.GetDirectoryName(path);
break;
}
}
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(, ScriptableObject.CreateInstance<CreateScriptAsset>(),
path + "/MyNewBehaviourScript.cs",
null, TemplateScriptPath); } } class CreateScriptAsset : EndNameEditAction
{
public override void Action(int instanceId, string newScriptPath, string templatePath)
{
UnityEngine.Object obj= CreateTemplateScriptAsset(newScriptPath, templatePath);
ProjectWindowUtil.ShowCreatedAsset(obj);
} public static UnityEngine.Object CreateTemplateScriptAsset(string newScriptPath, string templatePath)
{
string fullPath = Path.GetFullPath(newScriptPath);
StreamReader streamReader = new StreamReader(templatePath);
string text = streamReader.ReadToEnd();
streamReader.Close();
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(newScriptPath);
//替换模板的文件名
text = Regex.Replace(text, "MyTemplateScript", fileNameWithoutExtension);
bool encoderShouldEmitUTF8Identifier = true;
bool throwOnInvalidBytes = false;
UTF8Encoding encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier, throwOnInvalidBytes);
bool append = false;
StreamWriter streamWriter = new StreamWriter(fullPath, append, encoding);
streamWriter.Write(text);
streamWriter.Close();
AssetDatabase.ImportAsset(newScriptPath);
return AssetDatabase.LoadAssetAtPath(newScriptPath, typeof(UnityEngine.Object));
} }

4、总结
unity之定制脚本模板的更多相关文章
- 定制自己的Unity脚本模板
有时候想给脚本添加符合自己编程习惯的内容,或是一些个性化信息.而作为一个多多少少有点强迫症的人,这种东西要加就得每个脚本都加上,不然看着多不爽! 于是就得每添加一个脚本就去修改一下,很麻烦. 但是,在 ...
- 修改Unity脚本模板的方法合计
作为一个习惯于偷懒的程序,重复性的无聊内容是最让人无奈的事,就比如我们创建Unity脚本之后,需要手动调整生成的新脚本的格式.编码.内容:如果我们要编写的是编辑器或者服务器端脚本,需要修改的内容就会更 ...
- 【Cocos谁学谁会】定制属于自己的脚本模板
版权申明: 本文原创首发于以下网站,您可以自由转载,但必须加入完整的版权声明 博客园:https://www.cnblogs.com/MogooStudio/ csdn博客:https://blog. ...
- Unity 添加,修改默认创建脚本模板
Unity 默认创建的脚本可以添加也可以修改,不需要修改Editor. 一.找到模板目录 \Editor\Data\Resources\ScriptTemplates 二.如果要修改模板,直接打开修改 ...
- Tips12: 私人定制 专属的Unity3D 脚本模板
在使用U3D的过程中,新建一个C#脚本,它包含着空的Start()和Update()函数. 根据个人习惯的不同,可能有些人有着自己的脚本风格,每次进去都增删改很麻烦,这里介绍一个更改新建脚本模板的方 ...
- 《转》Unity3D研究院编辑器之创建Lua脚本模板
Unity里能创建 c#脚本模板,但是如果我想创建Lua脚本模板怎么办呢?拓展一下编辑器吧. 设置一下Lua脚本的模板地址 : Assets/Editor/Lua/Template/lua.lua ...
- Unity3d自定义脚本模板
这是一个小技巧,打开Unity安装目录,如: C:\Program Files (x86)\Unity\Editor\Data\Resources\ScriptTemplates /* * * Tit ...
- 如何修改新建脚本模板-ScriptTemplates(Unity3D开发之十五)
猴子原创,欢迎转载.转载请注明: 转载自Cocos2Der-CSDN,谢谢! 原文地址: http://blog.csdn.net/cocos2der/article/details/44957631 ...
- unity中js脚本与c#脚本互相调用
unity中js脚本与c#脚本互相调用 test1.js function OnGUI() { if(GUI.Button(Rect(25,25,100,30),"JS Call CS& ...
随机推荐
- C#写文本文件,如何换行(添加换行符)
把文本写到文件中,如果是几段文字拼合起来输出到文件中,通常每段非结尾文字后需要添加换行符,不然几段文字都变成一段. 在 C# 中,文本换行有两种方法,一种在需要换行的文本后面添加换行符 \r\n 即可 ...
- Hello World! 我的程序员入坑之旅!
先说下本文标题,各行各业都有自己的行规和一些内行人玩的梗什么的,这是我开始写技术博客的第一篇,所以它的标题毫无疑问只能是Hello World! 介绍一下我自己 我算是一个少见的科班出身的开发者了,1 ...
- day 59 pymysql
PyMySQL介绍 PyMySQL 是在 Python3.x 版本中用于连接 MySQL 服务器的一个库,Python2中则使用mysqldb. PYmysql安装 pip install pymys ...
- D - 统计同成绩学生人数
点击打开链接 读入N名学生的成绩,将获得某一给定分数的学生人数输出. Input 测试输入包含若干测试用例,每个测试用例的格式为 第1行:N 第2行:N名学生的成绩,相邻两数字用一个空格间隔. ...
- python爬虫2——下载文件(中华网图片库下载)
# -*- coding: utf-8 -*- import requests import re import sys reload(sys) sys.setdefaultencoding('utf ...
- ES6新增变量
声明let let 声明的变量不存在预解析 console.log(flag) var flag = 123 //123 let flag = 456 //undefined let声明的变量不允许重 ...
- JSTL介绍及使用
JSTL介绍及使用 一.JSTL(JSP Standard Tag Library)简介 > JSTL是JSP的标准标签库 > JSTL为我们提供了一些常用的标签,供我们日常开发使用(if ...
- .gitignore中添加的某个忽略文件并不生效
最近项目中,来了一新同事,协同开发的过程中,发现老是提示pod install,于是照做了,做完项目可以跑成功但发现提示我跟同事一样的问题,Podfile.lock文件需要提交,于是便提交了,然而同事 ...
- vertical-tical
通常我们需要垂直对齐并排的元素. CSS提供了一些可实现的方法:有时我用浮动float来解决,有时用position: absolute来解决,有时甚至是“肮脏”地手动添加的margin或paddin ...
- linux下mysql主从复制搭建
目标:搭建两台MySQL服务器,一台作为主服务器,一台作为从服务器,实现主从复制 环境: 主数据库: 192.168.1.1 从数据库: 192.168.1.2 mysql安装可参考:https:// ...