強火で進め

このブログではプログラム関連の記事を中心に書いてます。

メニューから独自の編集ウィンドウを表示させる方法


Unityのエディタ拡張についての話。

メニューから独自の編集ウィンドウを表示させる方法。リファレンスはこちら。

Unity Script Reference – EditorWindow
http://unity3d.com/support/documentation/ScriptReference/EditorWindow.html

ここに記載されているサンプルをそのまま実行してみたのですが以下の様なエラーが出て上手く動作しませんでした。

Instance of MyWindow couldn't be created because there is no script with that name.
UnityEditor.EditorWindow:GetWindow(Type)
MyWindow:Init() (at Assets/Editor/NewBehaviourScript.js:11)
NullReferenceException: Object reference not set to an instance of an object
UnityEditor.EditorWindow.GetWindow (System.Type t, Boolean utility, System.String title, Boolean focus)
UnityEditor.EditorWindow.GetWindow (System.Type t)
MyWindow.Init () (at Assets/Editor/NewBehaviourScript.js:11)

試行錯誤の末、クラス名とファイル名が異なるのが問題だと突き止めました。
今回のサンプルではクラス名が MyWindow なのでJavaScriptのファイル名も MyWindow に変更し、以下の様にすれば正しく動作しました。