/// Tells us if a click occurred in the current frame. /// @note This is a problematic method! The problem is that one cannot be sure /// the click won't occur AFTER the update which caused the gesture to be detected. /// @return true if a click occurred this frame and false otherwise public override bool HasClickedThisFrame() { if (m_active == false) { return(false); } return(m_input.GetAxis("NIGUI_CLICK") >= 1.0f); }
/// the mono-behavior update public void OnGUI() { float x = m_input.GetAxis("Horizontal"); float y = -m_input.GetAxis("Vertical"); x += 0.5f; x *= (Screen.width - 20); y += 0.5f; y *= (Screen.height - 20); GUI.Box(new Rect(x, y, 20, 20), ""); }
/// the mono-behavior update public void OnGUI() { float x = m_input.GetAxis("NI_X"); float y = m_input.GetAxis("NI_Y"); // since the axes are between -0.5 and 0.5 we add 0.5 to get a value between 0 and 1. x += 0.5f; y += 0.5f; // The value is multiplied by the screen width (minus 20 for the cursor size) to decide // where to place it x *= (Screen.width - 20); y *= (Screen.height - 20); // draw the cursor GUI.Box(new Rect(x, y, 20, 20), ""); }
/// @brief mono-behavior OnGUI for GUI logic. Is also responsible for mode change void OnGUI() { // option 1: we are in skeleton mode. All we need to do is try to detect the exit pose if (m_mode == SkeletonGUIModes.SkeletonMode) { // this tells us if we are detecting the exit pose. float val = m_input.GetAxis("SkeletonSwitch"); if (val >= 1.0f) { // we have detected the exit pose so we are moving to GUI mode. m_mode = SkeletonGUIModes.GUIMode; // deactivate the skeleton (controller, not the capability) m_skeletonManager.SetAllSkeletonPlayersToState(false); // when tracking a hand we need a high smoothing factor. m_settings.SmoothFactor = 0.95f; // reactivate NIGUI. NIGUI.SetActive(true); return; } if (val > 0) { // The value is between 0 and 1 so we have detected the exit pose and are waiting // for it to continue long enough. // Just pop up a message telling the user to continue holding the pose... tempRect.y = 40; if (m_image != null) { Rect tmpRect2 = tempRect; tmpRect2.height = 128; tmpRect2.width = 128; GUI.Box(tmpRect2, m_image); tempRect.y = 168; } GUI.Box(tempRect, "Hold the pose until " + val + " reaches 1"); return; } return; // nothing to do } // here we are on GUI mode. Lets draw the GUI tempRect.y = Screen.height / 2 - 20; if (NIGUI.Button(tempRect, "Resume")) { // move back to skeleton mode. m_mode = SkeletonGUIModes.SkeletonMode; // reactivate the skeleton controllers m_skeletonManager.SetAllSkeletonPlayersToState(true); // set a regular smoothing m_settings.SmoothFactor = 0.5f; // deactivate NIGUI. NIGUI.SetActive(false); return; } tempRect.y = Screen.height / 2 + 30; if (NIGUI.Button(tempRect, "Exit")) { // note: in editor mode this doesn't really do anything... Application.Quit(); return; } }
void OnGUI() { // move the cursor float x = m_input.GetAxis("Horizontal"); float y = -m_input.GetAxis("Vertical"); x += 0.5f; x *= (Screen.width - 20); y += 0.5f; y *= (Screen.height - 20); GUI.Box(new Rect(x, y, 20, 20), ""); // show the clicks GUILayout.Box(string.Format("Current Time={0:000.00}, current frame={1:0000}", Time.time, Time.frameCount)); if (m_lastCallbackTime < 0) { GUILayout.Box("Click by moving your hand straight forward and back"); } else { GUILayout.Box(string.Format("Last time click callback was called on time={0:00.00}, frame={1:0000}", m_lastCallbackTime, m_lastCallbackFrame)); } }
/// mono-behavior OnGUI to show GUI elements public void OnGUI() { // create a regular label myRect.x = (Screen.width / 2) - 40; myRect.y = 20; myRect.width = 80; myRect.height = 30; GUI.Label(myRect, "Example GUI"); // place the first button myRect.x = 200; myRect.y = 50; myRect.width = 80; myRect.height = 40; if (NIGUI.Button(myRect, "Button1")) { buttonPressedMessage = "Button 1 was pressed at time=" + Time.time; } // place the second button myRect.x = 300; myRect.y = 50; if (NIGUI.Button(myRect, "Button2")) { buttonPressedMessage = "Button 2 was pressed at time=" + Time.time; } // place the repeat button myRect.x = 200; myRect.y = 100; if (NIGUI.RepeatButton(myRect, "Repeat")) { buttonPressedMessage = "Repeat button was pressed at time=" + Time.time; } // place the toggle button myRect.x = 300; myRect.y = 100; myRect.width = 250; m_toggle1 = NIGUI.Toggle(myRect, m_toggle1, "Toggle example"); // place the GUI changed frame myRect.x = 50; myRect.y = (Screen.height / 2) - 140; myRect.width = 250; myRect.height = 30; GUI.Box(myRect, guiFrameCahngedMessage); // place the vScroll value label myRect.x = 50; myRect.y = (Screen.height / 2) - 100; myRect.width = 250; myRect.height = 30; GUI.Box(myRect, "vScroll=" + vScroll); // place the hScroll value label myRect.x = 50; myRect.y = (Screen.height / 2) - 60; myRect.width = 250; myRect.height = 30; GUI.Box(myRect, "hScroll=" + hScroll); // place the button pressed label myRect.x = 50; myRect.y = (Screen.height / 2) - 20; myRect.width = 250; myRect.height = 30; GUI.Box(myRect, buttonPressedMessage); // Click axis value label myRect.x = 50; myRect.y = (Screen.height / 2) + 20; myRect.width = 250; myRect.height = 30; GUI.Box(myRect, "value=" + m_input.GetAxis("NIGUI_CLICK")); // place the toolbar GUI myRect.x = 50; myRect.y = Screen.height - 200; myRect.width = 350; myRect.height = 30; toolbarInt = NIGUI.Toolbar(myRect, toolbarInt, toolbarStrings); // place the selection grid GUI element myRect.x = 50; myRect.y = Screen.height - 150; myRect.width = 350; myRect.height = 90; selectionGridInt = NIGUI.SelectionGrid(myRect, selectionGridInt, toolbarStrings, 2); // place the horizontal scrollbar of the clipped button myRect.x = (Screen.width) - 500; myRect.y = (Screen.height / 2) - 240; myRect.width = 400; myRect.height = 20; hScroll = NIGUI.HorizontalScrollbar(myRect, hScroll, 0.0f, 0.0f, 300.0f); // place the vertical scrollbar of the clipped button myRect.x = (Screen.width) - 510; myRect.y = (Screen.height / 2) - 225; myRect.width = 10; myRect.height = 200; vScroll = NIGUI.VerticalScrollbar(myRect, vScroll, 40.0f, 0.0f, 140.0f); // placed the clipped area for the button myRect.x = (Screen.width) - 500; myRect.y = (Screen.height / 2) - 225; myRect.width = 400; myRect.height = 200; NIGUI.BeginGroup(myRect); // place the internal button myRect.x = 0; myRect.y = 0; Color c = GUI.backgroundColor; Color almostClear = c; almostClear.a = 0.2f; GUI.backgroundColor = almostClear; GUI.Box(myRect, ""); GUI.backgroundColor = c; if (NIGUI.Button(new Rect(150 - hScroll, 50 - vScroll, 300, 200), "a button to be clipped by the view")) { buttonPressedMessage = "Internal button to group was pressed"; } NIGUI.EndGroup(); // place the float slider myRect.x = (Screen.width) - 500; myRect.y = (Screen.height / 2) + 110; myRect.width = 350; myRect.height = 30; floatSlider = NIGUI.HorizontalSlider(myRect, floatSlider, -5.0f, 5.0f); // place the float slider label myRect.x = (Screen.width) - 500; myRect.y = (Screen.height / 2) + 80; myRect.width = 350; myRect.height = 30; GUI.Label(myRect, "float slide=" + floatSlider); // place the int slider myRect.x = (Screen.width) - 510; myRect.y = (Screen.height / 2) + 120; myRect.width = 30; myRect.height = 150; intSlider = NIGUI.VerticalSlider(myRect, intSlider, -10.0f, 10.0f); // place the int slider label myRect.x = (Screen.width) - 490; myRect.y = (Screen.height / 2) + 180; myRect.width = 350; myRect.height = 30; GUI.Label(myRect, "int slide=" + Mathf.RoundToInt(intSlider)); // update the GUI changed frame if (NIGUI.changed) { guiFrameCahngedMessage = "GUI changed at frame=" + Time.frameCount; } }
/// mono-behavior OnGUI to show GUI elements public void OnGUI() { // create a regular label myRect.x = (Screen.width / 2) - 40; myRect.y = 20; myRect.width = 80; myRect.height = 30; GUI.Label(myRect, "Example GUI"); // place the first button myRect.x = 200; myRect.y = 50; myRect.width = 80; myRect.height = 40; if (NIGUI.Button(myRect, "Button1")) { lastMessage = "Button 1 was pressed at time=" + Time.time; } myRect.x = 500; myRect.y = 50; if (NIGUI.Button(myRect, "Button2")) { lastMessage = "Button 2 was pressed at time=" + Time.time; } myRect.x = 700; myRect.y = 50; if (NIGUI.RepeatButton(myRect, "Repeat")) { lastMessage = "Repeat button was pressed at time=" + Time.time; } myRect.x = 500; myRect.y = 125; myRect.width = 250; m_toggle1 = NIGUI.Toggle(myRect, m_toggle1, "Toggle example"); myRect.x = 200; myRect.y = (Screen.height / 2) - 15; myRect.width = 250; myRect.height = 30; GUI.Box(myRect, lastMessage); myRect.x = 200; myRect.y = (Screen.height / 2) + 40; myRect.width = 250; myRect.height = 30; if (Time.time > 10) { GUI.Box(myRect, "value=" + m_input.GetAxis("NIGUI_CLICK")); } myRect.x = 200; myRect.y = (Screen.height / 2) + 80; myRect.width = 350; myRect.height = 30; toolbarInt = NIGUI.Toolbar(myRect, toolbarInt, toolbarStrings); myRect.x = 200; myRect.y = (Screen.height / 2) + 120; myRect.width = 350; myRect.height = 90; selectionGridInt = NIGUI.SelectionGrid(myRect, selectionGridInt, toolbarStrings, 2); myRect.x = 700; myRect.y = 200; myRect.width = 400; myRect.height = 20; hScroll = NIGUI.HorizontalScrollbar(myRect, hScroll, 0.0f, 0.0f, 300.0f); myRect.x = 200; myRect.y = (Screen.height / 2) - 50; myRect.width = 250; myRect.height = 30; GUI.Box(myRect, "hScroll=" + hScroll); myRect.x = 680; myRect.y = 215; myRect.width = 10; myRect.height = 200; vScroll = NIGUI.VerticalScrollbar(myRect, vScroll, 40.0f, 0.0f, 140.0f); myRect.x = 200; myRect.y = (Screen.height / 2) - 90; myRect.width = 250; myRect.height = 30; GUI.Box(myRect, "vScroll=" + vScroll); myRect.x = 700; myRect.y = 215; myRect.width = 400; myRect.height = 200; NIGUI.BeginGroup(myRect); myRect.x = 0; myRect.y = 0; Color c = GUI.backgroundColor; Color almostClear = c; almostClear.a = 0.2f; GUI.backgroundColor = almostClear; GUI.Box(myRect, ""); GUI.backgroundColor = c; if (NIGUI.Button(new Rect(150 - hScroll, 50 - vScroll, 300, 200), "a button to be clipped by the view")) { lastMessage = "Internal button to group was pressed"; } NIGUI.EndGroup(); myRect.x = 700; myRect.y = (Screen.height / 2) + 80; myRect.width = 350; myRect.height = 30; GUI.Label(myRect, "float slide=" + floatSlider); myRect.x = 700; myRect.y = (Screen.height / 2) + 110; myRect.width = 350; myRect.height = 30; floatSlider = NIGUI.HorizontalSlider(myRect, floatSlider, -5.0f, 5.0f); myRect.x = 750; myRect.y = (Screen.height / 2) + 120; myRect.width = 350; myRect.height = 30; GUI.Label(myRect, "int slide=" + Mathf.RoundToInt(intSlider)); myRect.x = 700; myRect.y = (Screen.height / 2) + 110; myRect.width = 30; myRect.height = 150; intSlider = NIGUI.VerticalSlider(myRect, intSlider, -10.0f, 10.0f); if (NIGUI.changed) { lastMessage2 = "GUI changed at frame=" + Time.frameCount; } myRect.x = 200; myRect.y = (Screen.height / 2) - 130; myRect.width = 250; myRect.height = 30; GUI.Box(myRect, lastMessage2); }