コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Unity】Project ビューに Custom Inspector を作成するメニューを追加するエディタ拡張「CustomInspectorCreator.cs」紹介

ソースコード

上記のスクリプトを Unity プロジェクトの「Editor」フォルダに追加します

使い方

f:id:baba_s:20171227151246p:plain

MonoBehaviour を継承したクラスのスクリプトを右クリックして
「Create>Custom Inspector」を選択します

f:id:baba_s:20171227151358p:plain

すると、Editor フォルダに Custom Inspector のスクリプトが追加されます

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

[CustomEditor(typeof(NewBehaviourScript))]
//[CanEditMultipleObjects]
public class NewBehaviourScriptInspector : Editor
{
    void OnEnable()
    {
        // TODO: find properties we want to work with
        //serializedObject.FindProperty();
    }

    public override void OnInspectorGUI()
    {
        // Update the serializedProperty - always do this in the beginning of OnInspectorGUI.
        serializedObject.Update();

        // TODO: Draw UI here
        //EditorGUILayout.PropertyField();
        DrawDefaultInspector();

        // Apply changes to the serializedProperty - always do this in the end of OnInspectorGUI.
        serializedObject.ApplyModifiedProperties();
    }
}

コードの内容はこのようになっています

参考ツイート

関連記事