いわゆる スニペット というやつで、定型文を登録しておいて数クリックで書ける機能です。
VSCodeでスニペット登録用ファイルを開く
メニューから Code > 基本設定 > ユーザースニペット とクリック
C#で書くので csharp を選択します。
スニペットを登録する
書き方は csharp.json に書いてあるので一読するのがよいでしょう。
今回は私がよく使う DOTWeen での、ボタンクリック時の Scale アニメーションを登録しました。
{ // Place your snippets for csharp here. Each snippet is defined under a snippet name and has a prefix, body and // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are: // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the // same ids are connected. // Example: // "Print to console": { // "prefix": "log", // "body": [ // "console.log('$1');", // "$2" // ], // "description": "Log output to console" // } "UI Button Click - DOTwween" : { "prefix": "click", "body": [ "transform.DOPunchScale(new Vector3(0.2f, 0.2f, 0.2f), 0.2f).OnComplete(() => {", "$0", "});" ] } }
prefix が呼び出し時にタイプする文字、body がスニペット本体です。
$ をbody内に入れることで、スニペット入力後のカーソルの位置を決められます。便利
スニペットを呼び出す
呼び出したい場所で prefix に登録した文字列をタイプします。
予測変換が出ている場合は Esc でキャンセルしてから。
出力したいスニペットが選択されていることを確認し、リターンキーで呼び出します。