Kan*_*gam 5 c# unity-game-engine vuforia
我已经将一个脚本附加到Vuforia AR相机组件,以便为Ar相机表面添加按钮.
void OnGUI()
{
if (showComponent)
{
bool isOverlayClicked;
int onePartHeight = Screen.width / 10;
GUILayout.BeginArea(new Rect(0, 0, Screen.width, Screen.height)); // x,y,w,h
GUI.backgroundColor = Color.clear;
isOverlayClicked= GUI.Button(new Rect(0, 0, Screen.width, (Screen.height / 2) + 100 + (onePartHeight * 2)), "");
GUI.DrawTexture(new Rect(0, 0, Screen.width, (Screen.height / 2) + 100 + (onePartHeight * 2)), btntexture);
thisMenu.blocksRaycasts = thisMenu.interactable = false;//disallows clicks
thisMenu.alpha = 0; //makes menu invisible
if (isOverlayClicked)
{
Debug.Log("Overlay clicked in unity");
}
GUILayout.EndArea();
bool isProfileButtonClicked;
GUILayout.BeginArea(new Rect((Screen.width) - (iconSize + (25 * DPinPixels)), iconSize - (30 * DPinPixels), iconSize, iconSize));
GUI.backgroundColor = Color.clear;
isProfileButtonClicked = GUI.Button(new Rect(0, 0, iconSize, iconSize), "");
GUI.DrawTexture(new Rect(0, 0, iconSize, iconSize), profileViewTexture);
if (isProfileButtonClicked)
{
Debug.Log("Profile icon clicked in unity");
openProfileActivity();
}
GUILayout.EndArea();
}
}
Run Code Online (Sandbox Code Playgroud)
每当我单击配置文件图像时,始终会调用叠加图像单击.
注意:叠加图像填满整个屏幕.
一般来说,我强烈建议不要使用OnGUI而是使用Unity.Ui!
但是,您可以将 GUI 绘图和布尔值设置与反应代码的执行分开:
void OnGUI()
{
if (showComponent)
{
// First only draw the GUI and set the bools
bool isOverlayClicked;
int onePartHeight = Screen.width / 10;
GUILayout.BeginArea(new Rect(0, 0, Screen.width, Screen.height)); // x,y,w,h
GUI.backgroundColor = Color.clear;
isOverlayClicked= GUI.Button(new Rect(0, 0, Screen.width, (Screen.height / 2) + 100 + (onePartHeight * 2)), "");
GUI.DrawTexture(new Rect(0, 0, Screen.width, (Screen.height / 2) + 100 + (onePartHeight * 2)), btntexture);
thisMenu.blocksRaycasts = thisMenu.interactable = false;//disallows clicks
thisMenu.alpha = 0; //makes menu invisible
GUILayout.EndArea();
bool isProfileButtonClicked;
GUILayout.BeginArea(new Rect((Screen.width) - (iconSize + (25 * DPinPixels)), iconSize - (30 * DPinPixels), iconSize, iconSize));
GUI.backgroundColor = Color.clear;
isProfileButtonClicked = GUI.Button(new Rect(0, 0, iconSize, iconSize), "");
GUI.DrawTexture(new Rect(0, 0, iconSize, iconSize), profileViewTexture);
GUILayout.EndArea();
// Than later only react to the bools
if (isProfileButtonClicked)
{
Debug.Log("Profile icon clicked in unity");
openProfileActivity();
// Return so nothing else is executed
return;
}
// This is only reached if the other button was not clicked
if (isOverlayClicked)
{
Debug.Log("Overlay clicked in unity");
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
338 次 |
| 最近记录: |