Version: 2020.3
言語: 日本語

PopupWindow

class in UnityEditor

/

継承:EditorWindow

マニュアルに切り替える

説明

PopupWindowContent から継承するポップアップウィンドウを表示するのに使用されるクラス

ポップアップウィンドウはフチがなく、ドラッグやサイズ変更ができません。フォーカスを失ったとき、自動的に閉じます。短時間表示する情報やオプションを表示するときに使用します。

エディターのポップアップウィンドウの例はエディターの Scene View ツールバーの "Scene View Effects" オプションです。



以下はエディターウィンドウのボタンを介して表示されるカスタムポップアップウィンドウの例です。ポップアップは 3 つのトグル値があり、フォーカスを失ったときに自動的に閉じます。この例では二つのスクリプトが与えられています。一つ目はメニュー項目を介して開くことができるエディターウィンドウを定義します。そのエディターウィンドウにはポップアップを表示するボタンがあります。 二つ目のスクリプトは独立したクラスとしてポップアップ自身の内容を定義します。

一つ目はポップアップを起動する単純なエディターウィンドウのコードを示します。

using UnityEngine;
using UnityEditor;

public class EditorWindowWithPopup : EditorWindow { // Add menu item [MenuItem("Example/Popup Example")] static void Init() { EditorWindow window = EditorWindow.CreateInstance<EditorWindowWithPopup>(); window.Show(); }

Rect buttonRect; void OnGUI() { { GUILayout.Label("Editor window with Popup example", EditorStyles.boldLabel); if (GUILayout.Button("Popup Options", GUILayout.Width(200))) { PopupWindow.Show(buttonRect, new PopupExample()); } if (Event.current.type == EventType.Repaint) buttonRect = GUILayoutUtility.GetLastRect(); } } }

二つ目は、ポップアップ自身のコードです。

using UnityEngine;
using UnityEditor;

public class PopupExample : PopupWindowContent { bool toggle1 = true; bool toggle2 = true; bool toggle3 = true;

public override Vector2 GetWindowSize() { return new Vector2(200, 150); }

public override void OnGUI(Rect rect) { GUILayout.Label("Popup Options Example", EditorStyles.boldLabel); toggle1 = EditorGUILayout.Toggle("Toggle 1", toggle1); toggle2 = EditorGUILayout.Toggle("Toggle 2", toggle2); toggle3 = EditorGUILayout.Toggle("Toggle 3", toggle3); }

public override void OnOpen() { Debug.Log("Popup opened: " + this); }

public override void OnClose() { Debug.Log("Popup closed: " + this); } }

これらはそれぞれそのクラス名にちなんで別のファイルとして保存する必要があります。いずれも動作しませんので ゲームオブジェクト上にそれらを配置する必要はありません。プロジェクトの開始後、新しい "Example" メニューに行き、ポップアップの例を選択してみてください。ポップアップのオプションウィンドウを表示する新しいエディターウィンドウのボタンをクリックします。

.

Protected 関数

OnDisableSee ScriptableObject.OnEnable.
OnEnableSee ScriptableObject.OnDisable.

Static 関数

ShowPopupWindowContent をポップアップで表示します

継承メンバー

Static 変数

focusedWindow現在キーボードフォーカスがある EditorWindow (Read Only)
mouseOverWindow現在マウスのカーソルの下の EditorWindow (Read Only)

変数

autoRepaintOnSceneChangeDoes the window automatically repaint whenever the Scene has changed?
dockedReturns true if EditorWindow is docked.
hasFocusReturns true if EditorWindow is focused.
hasUnsavedChangesWhen set to true in a derived class, the editor will prompt the user to save unsaved changes if the window is about to be closed.
maximizedIs this window maximized?
maxSizeこのウィンドウの最大サイズ
minSizeこのウィンドウの最小サイズ
positionThe desired position of the window in screen space.
rootVisualElementRetrieves the root visual element of this window hierarchy.
saveChangesMessageThe message that displays to the user if they are prompted to save
titleContentGUIContent は EditorWindows のタイトルを描画するために使用します。
wantsLessLayoutEventsSpecifies whether a layout pass is performed before all user events (for example, EventType.MouseDown or [[EventType, KeyDown]]), or is only performed before repaint events.
wantsMouseEnterLeaveWindowChecks whether MouseEnterWindow and MouseLeaveWindow events are received in the GUI in this Editor window.
wantsMouseMoveChecks whether MouseMove events are received in the GUI in this Editor window.
hideFlagsShould the object be hidden, saved with the Scene or modifiable by the user?
nameオブジェクト名

Public 関数

BeginWindowsすべてのポップアップウィンドウを表示するための開始領域をマークします
Closeエディターウィンドウを閉じます
EndWindows EditorWindow.BeginWindows で開始したウィンドウグループを閉じます
FocusMoves keyboard focus to another EditorWindow.
GetExtraPaneTypesGets the extra panes associated with the window.
RemoveNotification表示している通知メッセージを停止します
Repaintウィンドウの再描画を行います
SaveChangesPerforms a save action on the contents of the window.
SendEventEvent をウィンドウに送信します
ShowShow the EditorWindow window.
ShowAsDropDownドロップダウンの動作とスタイルを持つウィンドウを表示します
ShowAuxWindow補助ウィンドウでエディターウィンドウを表示します
ShowModalShow modal editor window.
ShowModalUtilityShow the EditorWindow as a floating modal window.
ShowNotification通知メッセージを表示します
ShowPopupポップアップスタイルのフレーミングを使用するエディターウィンドウを表示します
ShowUtilityフローティングのユーティリティウィンドウとしてエディターウィンドウを表示します
GetInstanceIDオブジェクトのインスタンス ID を返します
ToStringReturns the name of the object.

Static 関数

CreateWindowCreates an EditorWindow of type T.
FocusWindowIfItsOpenエディターウィンドウが開いている場合に探し出し、最初に見つけたものにフォーカスを当てます
GetWindow現在画面上にある t タイプの最初に見つけた EditorWindow を返します
GetWindowWithRect現在画面上にある t タイプの最初に見つけた EditorWindow を返します
HasOpenInstancesChecks if an editor window is open.
DestroyRemoves a GameObject, component or asset.
DestroyImmediateDestroys the object obj immediately. You are strongly recommended to use Destroy instead.
DontDestroyOnLoadDo not destroy the target Object when loading a new Scene.
FindObjectOfTypeタイプ type から最初に見つけたアクティブのオブジェクトを返します
FindObjectsOfTypeGets a list of all loaded objects of Type type.
Instantiateoriginal のオブジェクトをクローンします
CreateInstanceScriptableObject のインスタンスを作成します。

Operator

boolオブジェクトが存在するかどうか
operator !=二つのオブジェクトが異なるオブジェクトを参照しているか比較します
operator ==2つのオブジェクト参照が同じオブジェクトを参照しているか比較します。

メッセージ

Awake新規ウィンドウが開くときに呼び出されます
CreateGUICreateGUI is called when the EditorWindow's rootVisualElement is ready to be populated.
hasUnsavedChangesWhen set to true in a derived class, the editor will prompt the user to save unsaved changes if the window is about to be closed.
OnDestroyOnDestroy is called to close the EditorWindow window.
OnFocusウィンドウがキーボードフォーカスを取得するときに呼び出されます
OnGUIここに独自のエディターの GUI を実装します
OnHierarchyChangeHandler for message that is sent when an object or group of objects in the hierarchy changes.
OnInspectorUpdateOnInspectorUpdate は更新する機会をインスペクターに与え、秒当たり 10 回呼ばれます
OnLostFocusウィンドウがキーボードフォーカスを失ったときに呼び出されます
OnProjectChangeHandler for message that is sent whenever the state of the project changes.
OnSelectionChange選択が変更されるたび呼び出されます
saveChangesMessageThe message that displays to the user if they are prompted to save
Updateすべての表示されているウィンドウは秒あたり複数回呼び出されます
Awake ScriptableObject スクリプトを開始するとき、この関数は呼び出されます。
OnDestroyScriptableObject が破棄されるとき、この関数は呼び出されます。
OnValidateEditor-only function that Unity calls when the script is loaded or a value changes in the Inspector.
Resetデフォルト値にリセットします