/// @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; } }
private Rect tempRect; ///< @brief Temporary rectangle which sets the position of items (defined here to avoid creating on the fly). /// @brief mono-behavior start for initialization void Start() { m_mode = SkeletonGUIModes.SkeletonMode; // initialize all the external links if (m_input == null) { m_input = FindObjectOfType(typeof(NIInput)) as NIInput; if (m_input == null) { throw new System.Exception("Please add an NIInput object to the scene"); } } if (m_settings == null) { m_settings = FindObjectOfType(typeof(OpenNISettingsManager)) as OpenNISettingsManager; if (m_settings == null) { throw new System.Exception("Please add an OpenNISettingsManager object to the scene"); } } // a rect used later, this is mainly an initialization tempRect = new Rect(); tempRect.x = Screen.width / 2 - 60; tempRect.y = Screen.height / 2 - 20; tempRect.width = 120; tempRect.height = 40; m_controllers = FindObjectsOfType(typeof(NISkeletonController)) as NISkeletonController[]; NIGUI.SetActive(false); // we don't want to see the cursor yet so we deactivate NIGUI }
/// @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) foreach (NISkeletonController controller in m_controllers) { controller.SetSkeletonActive(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 foreach (NISkeletonController controller in m_controllers) { controller.SetSkeletonActive(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; } }
/// @brief mono-behavior start for initialization void Start() { m_mode = SkeletonGUIModes.SkeletonMode; // initialize all the external links if(m_input==null) { m_input = FindObjectOfType(typeof(NIInput)) as NIInput; if (m_input == null) throw new System.Exception("Please add an NIInput object to the scene"); } if (m_settings == null) { m_settings = FindObjectOfType(typeof(OpenNISettingsManager)) as OpenNISettingsManager; if (m_settings == null) throw new System.Exception("Please add an OpenNISettingsManager object to the scene"); } // a rect used later, this is mainly an initialization tempRect = new Rect(); tempRect.x = Screen.width / 2 - 60; tempRect.y = Screen.height / 2 - 20; tempRect.width = 120; tempRect.height = 40; m_controllers = FindObjectsOfType(typeof(NISkeletonController)) as NISkeletonController[]; NIGUI.SetActive(false); // we don't want to see the cursor yet so we deactivate NIGUI }