メニューを構成するボタンを (GUI.FocusControl() でフォーカスをボタンからボタンに変更することで) ナビゲートできるようにするメニュー スクリプトの機能をコーディングしました。ただし、現在フォーカスされているボタンを「アクティブ化」/「選択」する方法については困惑しています。理想的には、ユーザーはメニューを上下にナビゲートし、ユーザーが選択したいオプションに到達したときに「Enter」を押すことができます。どんな提案も素晴らしいでしょう。
3520 次
1 に答える
0
これを行う方法を理解するのにしばらく時間がかかりましたが、最終的に解決策を見つけました。あなたがまだ答えを探しているなら、ここに私のやり方があります。基本的にはGUIクラスのSelectionGrid関数を利用したい。ここでピークを取得して、それがどのように機能するかを確認できますが、求めているものの実際の例を示すコードを次に示します。
#pragma strict
@script ExecuteInEditMode;
var selGridInt : int = 0; //This integer is the index of the button we are hovering above or have selected
var selStrings : String[] = ["Grid 1", "Grid 2", "Grid 3", "Grid 4"];
private var maxButton : int; // The total number of buttons in our grid
function Start()
{
maxButton = selStrings.Length; // Set the total no. of buttons to our String array size
}
function Update()
{
// Get keyboard input and increase or decrease our grid integer
if(Input.GetKeyUp(KeyCode.UpArrow))
{
// Here we want to create a wrap around effect by resetting the selGridInt if it exceeds the no. of buttons
if(selGridInt > 0)
{
selGridInt--;
}
else
{
selGridInt = maxButton - 1;
}
}
if(Input.GetKeyUp(KeyCode.DownArrow))
{
// Create the same wrap around effect as above but alter for down arrow
if(selGridInt < (maxButton-1))
{
selGridInt++;
}
else
{
selGridInt = 0;
}
}
if(Input.GetKeyUp(KeyCode.Return))
{
switch(selGridInt)
{
case 0: Debug.Log("Button "+(selGridInt + 1 )+ " pressed.");
break;
case 1: Debug.Log("Button "+(selGridInt + 1 )+" pressed.");
break;
case 2: Debug.Log("Button "+(selGridInt + 1 )+ " pressed.");
break;
case 3: Debug.Log("Button "+(selGridInt + 1 )+ " pressed.");
break;
}
}
}
function OnGUI ()
{
selGridInt = GUI.SelectionGrid (Rect (Screen.width/2-75, Screen.height/2-25, 150, 200), selGridInt, selStrings, 1);
}
于 2012-09-08T22:23:26.177 に答える