Ejemplo n.º 1
0
//				private static int GetJoystickInput ()
//				{
//
//
//						int numAxis = 8;
//						float axisValue = 0f;
//						string axisName;
//						KeyCode code;
//
//						if (_frameCountPrev == Time.frameCount)
//								return 0;
//
//
//						_frameCountPrev = Time.frameCount;
//
//
//
//
//						_numJoysticks = Input.GetJoystickNames ().Length;
//
//
//						//check for joysticks clicks
//						for (int i=0; i<_numJoysticks; i++) {
//
//						for (int k=0; k < 1; k++) {
//							axisName=i.ToString () + k.ToString ();
//							axisValue = Input.GetAxisRaw(axisName);// + 1f;//index-of joystick, k-ord number of axis
//
//					Debug.Log("axisValue :"+axisValue);
//
////							if(axisValue>0)
////								return InputCode.toCode((Joysticks)i,(JoystickAxis)k,JoystickPosition.Positive);
////							else if(axisValue<0)
////								return InputCode.toCode((Joysticks)i,(JoystickAxis)k,JoystickPosition.Negative);
//						}
//
//
//								//Let Unity handle JoystickButtons
//								for (int j=0; j<_numJoystickButtons; j++) {
//
//										code = (KeyCode)Enum.Parse (typeof(KeyCode), "Joystick" + (i + 1) + "Button" + j);
//
//										//Debug.Log("Joystick"+i+"Button"+j+" code:"+code);
//
//										if (Input.GetKeyDown (code)) {
//												return InputCode.toCode ((Joysticks)i, JoystickAxis.None, j);
//
//												// InputCode.toCode(code);
//										}
//								}
//						}
//
//
//						return 0;
//
//
//				}


        /// <summary>
        /// Gets the GUI keyboard input.
        /// first found key or mouse button pressed would be returned
        /// used for mapping states to current input
        /// </summary>
        /// <returns>The GUI keyboard input.</returns>
        private static int GetGUIKeyboardInput()
        {
            KeyCode keyCode;
            int     numKeys = _keys.Length;

            if (_frameCountEditorPrev == _frameCountEditor)
            {
                return(0);
            }
            else
            {
                _frameCountEditorPrev = _frameCountEditor;
            }


            for (int i = 0; i < numKeys; i++)
            {
                //check for mouse clicks
                if (i < _numMouseButtons)
                {
                    keyCode = (KeyCode)Enum.Parse(typeof(KeyCode), "Mouse" + i);

                    if (InputEx.GetMouseButtonDown(keyCode))
                    {
                        return((int)keyCode);
                    }
                }


                keyCode = _keys [i];                                                //
                if (InputEx.GetKeyDown(keyCode))
                {
                    return((int)keyCode);
                }
            }


            return(0);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Processes the input code into InputAction
        /// </summary>
        /// <returns>InputAction (single,double,long) or null.</returns>
        /// <param name="code">Code.</param>
        /// <param name="time">Time.</param>
        internal static InputAction processInputCode(int code, float time, IDevice device)
        {
            InputAction action = null;

            // Debug.Log ("process "+code);

            if (code != 0)                                      //=KeyCode.None


            {
                if (_lastCode == 0)                                                  //=KeyCode.None
                //save key event and time needed for double check
                {
                    _lastCode     = code;
                    _lastCodeTime = time;

                    Debug.Log("Last code " + InputCode.toEnumString(_lastCode) + " at time:" + _lastCodeTime);
                    //	Debug.Log("Take time "+_lastCodeTime);
                }
                else
                {
                    //if new pressed key is different then the last
                    if (_lastCode != code)
                    {
                        //consturct string from lastCode
                        action = new InputAction(_lastCode, InputActionType.SINGLE, device);

                        //take new pressed code as lastCode
                        _lastCode = code;

                        Debug.Log("Single " + time + ":" + _lastCodeTime + " " + InputActionType.SINGLE);
                    }
                    else
                    {
                        if (time - _lastCodeTime < InputAction.DOUBLE_CLICK_SENSITIVITY)
                        {
                            action    = new InputAction(_lastCode, InputActionType.DOUBLE, device);
                            _lastCode = 0;                                                                                    //KeyCode.None;
                            Debug.Log("Double " + time + ":" + _lastCodeTime + "<" + InputActionType.DOUBLE);
                        }
                    }
                }
            }
            else
            {
                if (_lastCode != 0)                                                  //=KeyCode.None
                //if key is still down and time longer then default long time click => display long click
                {
                    if (InputEx.GetInputHold(_lastCode, device) || (!Application.isPlaying && InputEx.GetKeyDown(_lastCode)))
                    {
                        if (time - _lastCodeTime >= InputAction.LONG_CLICK_SENSITIVITY)
                        {
                            action    = new InputAction(_lastCode, InputActionType.LONG, device);
                            _lastCode = 0;                                                                                    //KeyCode.None;
                            Debug.Log("Long " + (time - _lastCodeTime) + " <" + InputActionType.LONG);
                        }
                    }
                    else                                                                //time wating for double click activity passed => display last code
                    {
                        if (time - _lastCodeTime >= InputAction.DOUBLE_CLICK_SENSITIVITY)
                        {
                            action    = new InputAction(_lastCode, InputActionType.SINGLE, device);
                            _lastCode = 0;                                                                                    //KeyCode.None;

                            Debug.Log("Single after wating Double time pass " + (time - _lastCodeTime) + " " + InputActionType.SINGLE);
                        }
                    }
                }
            }
            return(action);
        }