以前のリビジョンの文書です
—-
Warning: Declaration of syntax_plugin_linebreak::handle($match, $state, $pos, &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in
/home/stepism/www/ue4/wiki/lib/plugins/linebreak/syntax.php on line
52
Warning: Declaration of syntax_plugin_linebreak::render($mode, &$renderer, $data) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in
/home/stepism/www/ue4/wiki/lib/plugins/linebreak/syntax.php on line
74
Warning: Declaration of syntax_plugin_markdownextra::handle($match, $state, $pos, &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in
/home/stepism/www/ue4/wiki/lib/plugins/markdownextra/syntax.php on line
38
Warning: Declaration of syntax_plugin_markdownextra::render($mode, &$renderer, $data) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in
/home/stepism/www/ue4/wiki/lib/plugins/markdownextra/syntax.php on line
47
Warning: Declaration of syntax_plugin_syntaxhighlighter3_syntax::handle($match, $state, $pos, &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in
/home/stepism/www/ue4/wiki/lib/plugins/syntaxhighlighter3/syntax/syntax.php on line
53
Warning: Declaration of syntax_plugin_syntaxhighlighter3_syntax::render($mode, &$renderer, $data) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in
/home/stepism/www/ue4/wiki/lib/plugins/syntaxhighlighter3/syntax/syntax.php on line
82
045 GUIコントロールについて
概要
UnityでGUIのコントロールは各スクリプトに記述出来るOnGUIコールバック関数で実装します。
using UnityEngine;
using System.Collections;
public class HogeScript : MonoBehaviour
{
void OnGUI()
{
GUI.Box( new Rect(10,10,100,90), "GUI Menu" );
if(GUI.Button(new Rect(20,40,80,20), "Button1"))
{
// ボタンを押した時の処理を記述します。
}
}
}
GUI.Box でButton背景の四角形を配置し、その後、GUI.Button でボタンを配置しています。
OnGUI 関数は毎フレームよばれる点に注意して下さい。
ボタンに画像を配置する
GUI.Button の第2引数は文字列の代わりにテクスチャを指定することもできます。
using UnityEngine;
using System.Collections;
public class HogeScript : MonoBehaviour
{
public Texture2D icon;
void OnGUI()
{
GUI.Box( new Rect(10,10,100,90), "GUI Menu" );
if(GUI.Button(new Rect(20,40,80,20), icon))
{
// ボタンを押した時の処理を記述します。
}
}
}
ボタンにテキストと画像を配置する
GUI.Button の第3引数にGUIContent を指定すればボタンとテキストの両方を表示できます。
GUI.Button(new Rect(20,40,80,20), new GUIContent( "テキスト", icon ) );
Unity - Unity Manual