1、在编辑器脚本模板文件夹中添加自己的模板,重启后会自动识别模板。
模板文件位置:编辑器安装位置\Editor\Data\Resources\ScriptTemplates.
模板文件命名格式说明:(以 80-Tmz Script-NewTmzScript.cs.txt 为例)
80 | Tmz Script | NewTmzScript.cs |
---|---|---|
菜单位置 | 菜单名称 (用 __ 做分隔可,有多级子菜单) | 默认文件名 |
2、添加自定义模板,方便团队共享,以添加UI模板为例:
添加模板,保存UITemplate.cs.txt。
///================================================
///
/// Created by : #AUTHOR#
/// CreateTime : #DATE#
/// Description :
///
///================================================
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
namespace HotFix_Project.UI
{
public sealed class #PANEL_SCRIPT# : Panel
{
#region 变量
#endregion
protected override void OnInit()
{
}
protected override void OnShow()
{
}
protected override void OnHide()
{
}
protected override void OnDestroy()
{
}
#region 界面更新
#endregion
#region 其他函数
#endregion
}
}
创建模板
[MenuItem("Assets/Create/Create PanelScript", false, 80)]
private static void CreateNewUIPanel()
{
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0,
ScriptableObject.CreateInstance<CreatePanelWithTemplate>(),
"New UIPanel.cs",
null, "");
}