LoginSignup
0
3

More than 3 years have passed since last update.

Commonクラスを自動で生成する仕組みを作ると人生が楽になる【Unity】

Last updated at Posted at 2019-11-27

UnityでC#スクリプトを生成した後毎回デフォルトで書かれているコードを決まったネームスペースやregionなど、チームのルールに沿って書き直す経験はありませんか。毎回同じコードを書くのは手間ですし、うっかりルールを守れていない状態で処理を書いていたなんてこともありますよね。

この問題は自分でテンプレートをカスタマイズする事で解決する事ができます。

1. UnityEditorをダウンロードしたパスからScriptTemplatesを探す

キャプチャ.PNG

2. 81-C# Script-NewBehaviourScript.cs.txt を好みで書き換える

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class #SCRIPTNAME# : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        #NOTRIM#
    }

    // Update is called once per frame
    void Update()
    {
        #NOTRIM#
    }
}

あとはUnityでスクリプト生成すると
上記で書き換えた通りにコードが書き換えられていると思います。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Common
{
    /// <summary>
    /// 
    /// </summary>
    public class NewBehaviourScript : MonoBehaviour
    {
        #region 定数

        #endregion

        #region 変数

        #endregion

        #region プロパティ

        #endregion

        #region ライフサイクル

        void Awake()
        {

        }

        void Start()
        {

        }

        void Update()
        {

        }

        void LateUpdate()
        {

        }

        #endregion

    }
}

おわりに

書き換えるだけでなくテンプレートを追加することもできます。

0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3