Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gatosyocora/19e9291f079b7b6a465be2d087826acf to your computer and use it in GitHub Desktop.
Save gatosyocora/19e9291f079b7b6a465be2d087826acf to your computer and use it in GitHub Desktop.
UnityでCreateから作成できるEditorWindow用のC#テンプレートコード
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Linq;
namespace #SCRIPTNAME#
{
public class #SCRIPTNAME# : EditorWindow
{
[MenuItem("Window/#SCRIPTNAME#")]
public static void Open()
{
GetWindow<#SCRIPTNAME#>("#SCRIPTNAME#");
}
private void OnGUI()
{
if (GUILayout.Button("Do Action"))
{
}
}
}
}

使い方

  1. Assetsフォルダの下に「ScriptTemplates」フォルダを作成してこのテンプレートファイルを配置する
  2. UnityEditorを再起動する
  3. Projectタブで右クリック > Create > C# EditorWindow Script で用意したテンプレートファイルに沿ったファイルが作成される

#SCRIPTNAME#に作成時に入力したファイル名が入る

仕組み

Unityが内部的に使っている仕組み

C://Program Files/Unity/Hub/Editor/{Unityのバージョン}/Editor/Data/Resources/ScriptTemplates
にUnityが使っているテンプレートファイルがある

テンプレートファイル名が重要っぽい?
{どこに表示するか(?)}-{表示名}-{生成されるファイルのデフォルト名}.txt
e.g.)

  • 81-C# Script-NewBehaviourScript.cs.txt
  • 83-C# Script-NewTestScript.cs.txt
  • 83-Shader__Standard Surface Shader-NewSurfaceShader.shader.txt

参考

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment