言語: 日本語
  • C#
  • JS
  • Boo

スクリプト言語

お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。

GUI.Window

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static function Window(id: int, clientRect: Rect, func: WindowFunction, title: GUIContent, style: GUIStyle): Rect;
public static Rect Window(int id, Rect clientRect, WindowFunction func, GUIContent title, GUIStyle style);
public static def Window(id as int, clientRect as Rect, func as WindowFunction, title as GUIContent, style as GUIStyle) as Rect

Parameters

style ウィンドウのスタイル
id ウィンドウのID番号(ただし値はユニークでなければいけません)
clientRect ウィンドウの位置とサイズを示すスクリーン上のRect
func ウィンドウのコンテンツを表示するメソッド
text ウィンドウ内で描画するテキスト
image ウィンドウ内で描画する画像
content ウィンドウ内で描画するGUIContent
title ウィンドウのタイトルバーに表示されるテキスト

Returns

Rect ウィンドウの位置とサイズを示すスクリーン上のRect

Description

ポップアップウィンドウ

ウィンドウは通常のGUIコントロールより上に浮いているようになっており、クリックしてフォーカスされ、必要に応じてユーザーの手でドラッグすることができます。他のコントロールとは異なり、ウィンドウ内にGUIコントロールを描画するために別の関数を渡す必要があります。 注意: ウィンドウ内でGUILayoutを使用する場合はGUILayout.Windowを使用する必要があります。また、 MonoBehaviour.useGUILayout がfalseに設定されている場合では、 GUI.Window 内のGUIコントロールがGUILayoutでなくても表示されません。

	var windowRect : Rect = Rect (20, 20, 120, 50);

	function OnGUI () {
		// Register the window. Notice the 3rd parameter 
		windowRect = GUI.Window (0, windowRect, DoMyWindow, "My Window");
	}

	// Make the contents of the window
	function DoMyWindow (windowID : int) {
		if (GUI.Button (Rect (10,20,100,20), "Hello World"))
			print ("Got a click");
	}
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public Rect windowRect = new Rect(20, 20, 120, 50);
    void OnGUI() {
        windowRect = GUI.Window(0, windowRect, DoMyWindow, "My Window");
    }
    void DoMyWindow(int windowID) {
        if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
            print("Got a click");
        
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	public windowRect as Rect = Rect(20, 20, 120, 50)

	def OnGUI() as void:
		windowRect = GUI.Window(0, windowRect, DoMyWindow, 'My Window')

	def DoMyWindow(windowID as int) as void:
		if GUI.Button(Rect(10, 20, 100, 20), 'Hello World'):
			print('Got a click')

同じ関数を使用して複数のウィンドウを作成することができます。ただし、 ウィンドウ毎にユニークなIDを持つ ことを確認してください。例:

	var windowRect0 : Rect = Rect (20, 20, 120, 50);
	var windowRect1 : Rect = Rect (20, 100, 120, 50);

	function OnGUI () {
		// Register the window. We create two windows that use the same function
		// Notice that their IDs differ
		windowRect0 = GUI.Window (0, windowRect0, DoMyWindow, "My Window");
		windowRect1 = GUI.Window (1, windowRect1, DoMyWindow, "My Window");
	}

	// Make the contents of the window
	function DoMyWindow (windowID : int) {
		if (GUI.Button (Rect (10,20,100,20), "Hello World"))
			print ("Got a click in window " + windowID);
		// Make the windows be draggable.
		GUI.DragWindow (Rect (0,0,10000,10000));
	}
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public Rect windowRect0 = new Rect(20, 20, 120, 50);
    public Rect windowRect1 = new Rect(20, 100, 120, 50);
    void OnGUI() {
        windowRect0 = GUI.Window(0, windowRect0, DoMyWindow, "My Window");
        windowRect1 = GUI.Window(1, windowRect1, DoMyWindow, "My Window");
    }
    void DoMyWindow(int windowID) {
        if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
            print("Got a click in window " + windowID);
        
        GUI.DragWindow(new Rect(0, 0, 10000, 10000));
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	public windowRect0 as Rect = Rect(20, 20, 120, 50)

	public windowRect1 as Rect = Rect(20, 100, 120, 50)

	def OnGUI() as void:
		windowRect0 = GUI.Window(0, windowRect0, DoMyWindow, 'My Window')
		windowRect1 = GUI.Window(1, windowRect1, DoMyWindow, 'My Window')

	def DoMyWindow(windowID as int) as void:
		if GUI.Button(Rect(10, 20, 100, 20), 'Hello World'):
			print(('Got a click in window ' + windowID))
		GUI.DragWindow(Rect(0, 0, 10000, 10000))

ウィンドウの表示をやめるには、OnGUIメソッド内でGUI.Windowの呼び出しを止めるだけです:

	// boolean variable to decide whether to show the window or not.
	// Change this from the in-game GUI, scripting, the inspector or anywhere else to
	// decide whether the window is visible
	var doWindow0 : boolean = true;

	// Make the contents of the window.
	function DoWindow0 (windowID : int) {
		GUI.Button (Rect (10,30, 80,20), "Click Me!");
	}

	function OnGUI () {
		// Make a toggle button for hiding and showing the window
		doWindow0 = GUI.Toggle (Rect (10,10,100,20), doWindow0, "Window 0");
		
		// Make sure we only call GUI.Window if doWindow0 is true.
		if (doWindow0)
			GUI.Window (0, Rect (110,10,200,60), DoWindow0, "Basic Window");
	}
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public bool doWindow0 = true;
    void DoWindow0(int windowID) {
        GUI.Button(new Rect(10, 30, 80, 20), "Click Me!");
    }
    void OnGUI() {
        doWindow0 = GUI.Toggle(new Rect(10, 10, 100, 20), doWindow0, "Window 0");
        if (doWindow0)
            GUI.Window(0, new Rect(110, 10, 200, 60), DoWindow0, "Basic Window");
        
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	public doWindow0 as bool = true

	def DoWindow0(windowID as int) as void:
		GUI.Button(Rect(10, 30, 80, 20), 'Click Me!')

	def OnGUI() as void:
		doWindow0 = GUI.Toggle(Rect(10, 10, 100, 20), doWindow0, 'Window 0')
		if doWindow0:
			GUI.Window(0, Rect(110, 10, 200, 60), DoWindow0, 'Basic Window')

自動GUIレイアウトからサイズを取得するウィンドウを作成するには、GUILayout.Windowを使用してください。 Call Ordering Windows need to be drawn back-to-front; windows on top of other windows need to be drawn later than the ones below them. This means that you can not count on your DoWindow functions to be called in any particular order. In order for this to work seamlessly, the following values are stored when you create your window (using the Window function), and retrieved when your DoWindow gets called: GUI.skin, GUI.enabled, GUI.color, GUI.backgroundColor, GUI.contentColor, GUI.matrix.

	var windowRect0 : Rect = Rect (20, 20, 120, 50);
	var windowRect1 : Rect = Rect (20, 100, 120, 50);

	function OnGUI () {
		// Here we make 2 windows. We set the GUI.color value to something before each.
		GUI.color = Color.red;		
		windowRect0 = GUI.Window (0, windowRect0, DoMyWindow, "Red Window");

		GUI.color = Color.green;		
		windowRect1 = GUI.Window (1, windowRect1, DoMyWindow, "Green Window");
	}

	// Make the contents of the window.
	// The value of GUI.color is set to what it was when the window
	// was created in the code above.
	function DoMyWindow (windowID : int) {
		if (GUI.Button (Rect (10,20,100,20), "Hello World"))
			print ("Got a click in window with color " + GUI.color);
		// Make the windows be draggable.
		GUI.DragWindow (Rect (0,0,10000,10000));
	}
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public Rect windowRect0 = new Rect(20, 20, 120, 50);
    public Rect windowRect1 = new Rect(20, 100, 120, 50);
    void OnGUI() {
        GUI.color = Color.red;
        windowRect0 = GUI.Window(0, windowRect0, DoMyWindow, "Red Window");
        GUI.color = Color.green;
        windowRect1 = GUI.Window(1, windowRect1, DoMyWindow, "Green Window");
    }
    void DoMyWindow(int windowID) {
        if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
            print("Got a click in window with color " + GUI.color);
        
        GUI.DragWindow(new Rect(0, 0, 10000, 10000));
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	public windowRect0 as Rect = Rect(20, 20, 120, 50)

	public windowRect1 as Rect = Rect(20, 100, 120, 50)

	def OnGUI() as void:
		GUI.color = Color.red
		windowRect0 = GUI.Window(0, windowRect0, DoMyWindow, 'Red Window')
		GUI.color = Color.green
		windowRect1 = GUI.Window(1, windowRect1, DoMyWindow, 'Green Window')

	def DoMyWindow(windowID as int) as void:
		if GUI.Button(Rect(10, 20, 100, 20), 'Hello World'):
			print(('Got a click in window with color ' + GUI.color))
		GUI.DragWindow(Rect(0, 0, 10000, 10000))

ウィンドウの内側と外側をフェードするGUI.colorのアルファコンポーネントを使用できることに注意してください。 See Also: DragWindow, BringWindowToFront, BringWindowToBack.