//====================== // UpdateInputMapping // Updates a single input mapping. //====================== private static void UpdateInputMapping(int joystickNumber, MonoBehaviour comp) { for (int i = 0; i < KeyInfos.Count; ++i) { bool keyDown = false; // query the correct device KeyInfo keyInfo = KeyInfos[i]; if (keyInfo.DeviceType == eDeviceType.Gamepad) { //DebugUtils.Print( "Checking gamepad button " + keyInfo.KeyName ); keyDown = GetJoystickButton(joystickNumber, keyInfo.JoystickButton); } else if (keyInfo.DeviceType == eDeviceType.Axis) { float axisValue = GetJoystickAxis(joystickNumber, keyInfo.JoystickAxis); keyDown = (axisValue >= keyInfo.Threshold); } else if (AllowKeyControls) { if (keyInfo.DeviceType == eDeviceType.Mouse) { keyDown = GetMouseButton(keyInfo.MouseButton); } else if (keyInfo.DeviceType == eDeviceType.Keyboard) { keyDown = Input.GetKey(keyInfo.KeyName); } } // handle the event if (keyDown == false) { if (keyInfo.WasDown) { // key was just released keyInfo.UpHandler(comp); } } else { if (keyInfo.WasDown == false) { // key was just pressed //DebugUtils.Print( "Key or Button down: " + keyInfo.KeyName ); keyInfo.DownHandler(comp); } else { // key is held keyInfo.HeldHandler(comp); } } // update the key info keyInfo.WasDown = keyDown; } }
//====================== // UpdateInputMapping // Updates a single input mapping. //====================== private static void UpdateInputMapping(InputMapping im) { blockedKeys.Clear(); for (int i = im.KeyInfos.Count - 1; i >= 0; --i) //for ( int i = 0; i < im.KeyInfos.Count; ++i ) { bool keyDown = false; // query the correct device KeyInfo keyInfo = im.KeyInfos[i]; if (keyInfo.DeviceType == eDeviceType.Gamepad) { //Debug.Log( "Checking gamepad button " + keyInfo.KeyName ); keyDown = GetJoystickButton(im.JoystickNumber, keyInfo.JoystickButton); } else if (keyInfo.DeviceType == eDeviceType.Axis) { float axisValue = GetJoystickAxis(im.JoystickNumber, keyInfo.JoystickAxis); keyDown = (axisValue >= keyInfo.Threshold); } else if (AllowKeyControls) { if (keyInfo.DeviceType == eDeviceType.Mouse) { keyDown = GetMouseButton(keyInfo.MouseButton); } else if (keyInfo.DeviceType == eDeviceType.Keyboard) { keyDown = Input.GetKey(keyInfo.KeyName); } } // handle the event if (keyDown == false) { if (keyInfo.WasDown) { //Debug.Log(PlatformPrefix + "Joy " + im.JoystickNumber + ":" + ButtonNames[(int)keyInfo.JoystickButton]); // key was just released if (keyInfo.UpHandler != null) { if (!KeyBlocked(keyInfo)) { keyInfo.UpHandler(im.Component); } } } } else { if (keyInfo.WasDown == false) { // key was just pressed //Debug.Log( "Key or Button down: " + keyInfo.KeyName ); if (keyInfo.DownHandler != null) { if (!KeyBlocked(keyInfo)) { keyInfo.DownHandler(im.Component); } } } else { // key is held if (keyInfo.HeldHandler != null) { if (!KeyBlocked(keyInfo)) { keyInfo.HeldHandler(im.Component); } } } } if (keyInfo.exclusive) { blockedKeys.Add(keyInfo); } // update the key info keyInfo.WasDown = keyDown; } }