我已经给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();
}
}
每当我点击个人资料图片时,总是会调用叠加图像单击事件。
请注意: 叠加图像填充整个屏幕。