Пример #1
0
        //!!! IMPORTANT: Input happen every frame. If there is no refresh from the hardware device
        // Input give same values just states are refreshed from DOWN->HOLD (value=1 stay) and UP->NONE (value=0 stay)

        /// <summary>
        /// Gets the axis.
        /// </summary>
        /// <returns>The axis.</returns>
        /// <param name="action">Action.</param>
        public static float GetInputAnalog(InputAction action, IDevice device)
        {
            int code = action.getCode(device);

            // action.getCode(_currentPlayer._Device.profile);



            lock (syncRoot) {
                if (device != null)
                {
                    return(device.GetInputAnalog(code));
                }
                else
                {
                    float axisValue = 0f;

                    foreach (IDevice dev in Devices)
                    {
                        if ((axisValue = dev.GetInputAnalog(code)) != 0f)
                        {
                            return(axisValue);
                        }
                    }


                    return(0f);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Check if InputActin happened( SINGLE,DOUBLE,LONG)
        /// </summary>
        /// <returns>true/false</returns>
        /// <param name="action">InputAction to be compared with input</param>
        internal static bool GetAction(InputAction action, IDevice device)
        {
            if (action.type == InputActionType.SINGLE)
            {
                if (InputEx.GetInputDigital(action, ButtonState.Down, device))
                {
                    Debug.Log("Single <" + InputActionType.SINGLE);
                    //action.startTime = Time.time;
                    _lastCode = action.getCode(device);
                    return(true);
                }

                return(false);
            }


            if (action.type == InputActionType.DOUBLE)
            {
                if (InputEx.GetInputDigital(action, ButtonState.Down, device))
                {
                    if (_lastCode != action.getCode(device))                                                              //first click

                    {
                        _lastCode        = action.getCode(device);
                        action.startTime = Time.time;
                        Debug.Log("First Click" + Time.time + ":" + action.startTime + " going for " + InputActionType.DOUBLE);
                        return(false);
                    }
                    else                                                                //InputEx.LastCode==_pointer.Current.code //second click
                    //check time diffrence if less then
                    {
                        if (Time.time - action.startTime < InputAction.DOUBLE_CLICK_SENSITIVITY)
                        {
                            _lastCode        = 0;                                                                             //???
                            action.startTime = 0;
                            Debug.Log("Double " + Time.time + ":" + action.startTime + "<" + InputActionType.DOUBLE);

                            return(true);
                        }

                        // Debug.Log("Lost Double " + Time.time + ":" + action.startTime + "<" + InputActionType.DOUBLE);
                    }
                }

                return(false);
            }


            if (action.type == InputActionType.LONG)
            {
                if (InputEx.GetInputDigital(action, ButtonState.Hold, device))                                                  //if hold
                {
                    if (_lastCode != action.getCode(device))
                    {
                        _lastCode = action.getCode(device);

                        action.startTime = Time.time;

                        return(false);
                    }
                    else                                                                //InputEx.LastCode==_pointer.Current.getCode(device) //hold
                    //check time diffrence if less then
                    {
                        if (Time.time - action.startTime >= InputAction.LONG_CLICK_SENSITIVITY)
                        {
                            _lastCode        = 0;                                                                             //KeyCode.None;
                            action.startTime = 0;
                            Debug.Log("Long " + (Time.time - action.startTime) + " " + InputActionType.LONG);

                            return(true);
                        }
                    }
                }

                return(false);
            }


            return(false);
        }
Пример #3
0
 private static bool GetInputDigital(InputAction action, ButtonState buttonState, IDevice device)
 {
     return(GetInputDigital(action.getCode(device), buttonState, device));
 }
Пример #4
0
				/// <summary>
				/// Check if InputActin happened( SINGLE,DOUBLE,LONG)
				/// </summary>
				/// <returns>true/false</returns>
				/// <param name="action">InputAction to be compared with input</param>
				internal static bool GetAction (InputAction action,IDevice device)
				{

						if (action.type == InputActionType.SINGLE) {
								if (InputEx.GetInputDigital (action, ButtonState.Down,device)) {
										Debug.Log ("Single <" + InputActionType.SINGLE);
										//action.startTime = Time.time;
										_lastCode = action.getCode(device);
										return true;
								}

								return false;
						}


						if (action.type == InputActionType.DOUBLE) {
								if (InputEx.GetInputDigital (action, ButtonState.Down,device)) {
										if (_lastCode != action.getCode(device)) {//first click

												_lastCode = action.getCode(device);
												action.startTime = Time.time;
												Debug.Log ("First Click" + Time.time + ":" + action.startTime + " going for " + InputActionType.DOUBLE);
												return false;
										} else {//InputEx.LastCode==_pointer.Current.code //second click
												//check time diffrence if less then
												if (Time.time - action.startTime < InputAction.DOUBLE_CLICK_SENSITIVITY) {

														_lastCode = 0;//???
														action.startTime = 0;
														Debug.Log ("Double " + Time.time + ":" + action.startTime + "<" + InputActionType.DOUBLE);

														return true;
												}

												// Debug.Log("Lost Double " + Time.time + ":" + action.startTime + "<" + InputActionType.DOUBLE);
										}
								}

								return false;
						}


						if (action.type == InputActionType.LONG) {
								if (InputEx.GetInputDigital (action, ButtonState.Hold,device)) {//if hold
										if (_lastCode != action.getCode(device)) {

												_lastCode = action.getCode(device);

												action.startTime = Time.time;

												return false;
										} else {//InputEx.LastCode==_pointer.Current.getCode(device) //hold
												//check time diffrence if less then
												if (Time.time - action.startTime >= InputAction.LONG_CLICK_SENSITIVITY) {

														_lastCode = 0;//KeyCode.None;
														action.startTime = 0;
														Debug.Log ("Long " + (Time.time - action.startTime) + " " + InputActionType.LONG);

														return true;
												}
										}
								}

								return false;

						}


						return false;


				}
Пример #5
0
				private static bool GetInputDigital (InputAction action, ButtonState buttonState,IDevice device)
				{

						return GetInputDigital (action.getCode(device), buttonState,device);

				}
Пример #6
0
				//!!! IMPORTANT: Input happen every frame. If there is no refresh from the hardware device 
				// Input give same values just states are refreshed from DOWN->HOLD (value=1 stay) and UP->NONE (value=0 stay)

				/// <summary>
				/// Gets the axis.
				/// </summary>
				/// <returns>The axis.</returns>
				/// <param name="action">Action.</param>
				public static float GetInputAnalog (InputAction action,IDevice device)
				{
						int code = action.getCode(device);
                       // action.getCode(_currentPlayer._Device.profile);


					
						
						lock (syncRoot) {
							
							
							if (device!=null) {
								
								
								return device.GetInputAnalog (code);
								
								
								
							} else {
								float axisValue=0f;

									foreach (IDevice dev in Devices)
										if((axisValue=dev.GetInputAnalog (code))!=0f)
										return axisValue;
										
								
									return 0f;		
					
							}
							
						}



		}
Пример #7
0
				/////////////////////////                  UPDATE              /////////////////////////
				/// <summary>
				/// Update this instance.
				/// </summary>
				void Update ()
				{
						InputState state;


						if (!Application.isPlaying && !__wereDevicesEnumerated) {
								__wereDevicesEnumerated = true;
								InputManager.hidInterface.SetProfiles (AssetDatabase.LoadAssetAtPath ("Assets/Resources/DeviceProfiles.asset", typeof(DeviceProfiles)) as DeviceProfiles);

								InputManager.hidInterface.Enumerate ();

						}

						if (!Application.isPlaying && _selectedStateHash != 0) {

							

									
								_action = InputManager.GetAction (_deviceByProfile);
				

								if (_action != null && (_action.getCode (_deviceByProfile) ^ (int)KeyCode.Escape) != 0 && (_action.getCode (_deviceByProfile) ^ (int)KeyCode.Return) != 0) {



										if ((_action.getCode (_deviceByProfile) ^ (int)KeyCode.Backspace) == 0) {
												state = _stateInputCombinations [_selectedStateHash];
												state.combinations [_isPrimary].Clear ();
												state.combinations [_isPrimary].Add (new InputAction (KeyCode.None));

										} else {

												
						                        


												if (!_isComplexActionTypesAllowed)
														_action.type = InputActionType.SINGLE;

												_action.setCode (InputCode.toCodeAnyDevice (_action.getCode (_deviceByProfile)), _deviceByProfile);
					

												if (_isDeviceAxisPositionFull) {
														_action.setCode (InputCode.toCodeAxisFull (_action.getCode (_deviceByProfile)), _deviceByProfile);
                                                       
												}

												toInputCombination (_stateInputCombinations [_selectedStateHash].combinations [_isPrimary], _action);
										}



										//Debug.Log ("Action:" + _action + " " + _action.getCode(_deviceByProfile)+" type:"+_action.type);
								}


								//Debug.Log ("Action:"+action);
						}
               

				

				}