こちらのスライドで知った機能。
この機能を使うと編集中もGUIのレイアウトの確認が出来たりします。
サンプルコード
以下のJavaScriptかC#のいずれかのプログラムをMain Cameraなど適当なオブジェクトに貼り付けて下さい。
#pragma strict @script ExecuteInEditMode() function Update () { } function OnGUI () { GUI.Label(Rect(10, 10, 100, 30), "test"); GUI.Button(Rect(10, 50, 100, 30), "test2"); } function OnRenderObject () { }
【C#】
using UnityEngine; using System.Collections; [ExecuteInEditMode()] public class Test : MonoBehaviour { void Update () { } void OnGUI () { GUI.Label(new Rect(10, 10, 100, 30), "test"); GUI.Button(new Rect(10, 50, 100, 30), "test2"); } void OnRenderObject () { } }
Gameビューをクリックすると OnGUI イベントが発生します。プログラムを変更した後は一度、Gameビューをクリックすると画面が更新されます。
関連情報
Unity Script Reference – ExecuteInEditMode
http://unity3d.com/support/documentation/ScriptReference/ExecuteInEditMode