├── .hgignore ├── Input ├── Core.Extensions │ ├── GestureEvent.cs │ ├── TextEvent.cs │ ├── Mouse.cs.meta │ ├── Touch.cs.meta │ ├── Cursor.cs.meta │ ├── Gamepad.cs.meta │ ├── Joystick.cs.meta │ ├── KeyEvent.cs.meta │ ├── Keyboard.cs.meta │ ├── Pointer.cs.meta │ ├── PointerClickEvent.cs │ ├── Sensor.cs.meta │ ├── TextEvent.cs.meta │ ├── TouchEvent.cs.meta │ ├── GestureEvent.cs.meta │ ├── JoystickProfile.cs.meta │ ├── KeyboardEvent.cs.meta │ ├── PointerControl.cs.meta │ ├── PointerEvent.cs.meta │ ├── TouchControl.cs.meta │ ├── Touchscreen.cs.meta │ ├── VirtualJoystick.cs.meta │ ├── PointerClickEvent.cs.meta │ ├── PointerMoveEvent.cs.meta │ ├── JoystickControlMapping.cs.meta │ ├── Sensor.cs │ ├── JoystickControlMapping.cs │ ├── PointerMoveEvent.cs │ ├── KeyEvent.cs │ ├── Touch.cs │ ├── TouchEvent.cs │ ├── Mouse.cs │ ├── TouchControl.cs │ ├── KeyboardEvent.cs │ ├── PointerEvent.cs │ ├── Cursor.cs │ ├── Joystick.cs │ ├── PointerControl.cs │ ├── Keyboard.cs │ ├── JoystickProfile.cs │ ├── Pointer.cs │ ├── VirtualJoystick.cs │ ├── Touchscreen.cs │ └── Gamepad.cs ├── Core.meta ├── Actions.meta ├── Editor.meta ├── Players.meta ├── Core.Extensions.meta ├── Actions.Extensions.meta ├── Core │ ├── IInputConsumer.cs │ ├── InputDevice.cs.meta │ ├── InputEvent.cs.meta │ ├── InputState.cs.meta │ ├── InputSystem.cs.meta │ ├── IInputConsumer.cs.meta │ ├── InputControl.cs.meta │ ├── InputControlData.cs.meta │ ├── InputEventPool.cs.meta │ ├── InputEventQueue.cs.meta │ ├── SerializableType.cs.meta │ ├── GenericControlEvent.cs.meta │ ├── InputConsumerCallback.cs.meta │ ├── InputConsumerNode.cs.meta │ ├── InputControlProvider.cs.meta │ ├── InputDeviceManager.cs.meta │ ├── InputDeviceProfile.cs.meta │ ├── InputDeviceUtility.cs.meta │ ├── InputControlDescriptor.cs.meta │ ├── InputControlData.cs │ ├── InputEventPool.cs │ ├── GenericControlEvent.cs │ ├── InputConsumerCallback.cs │ ├── InputConsumerNode.cs │ ├── InputControlDescriptor.cs │ ├── SerializableType.cs │ ├── InputDeviceProfile.cs │ ├── InputEventQueue.cs │ ├── InputControlProvider.cs │ ├── InputDevice.cs │ ├── InputEvent.cs │ ├── InputDeviceUtility.cs │ ├── InputControl.cs │ ├── InputState.cs │ ├── InputSystem.cs │ └── InputDeviceManager.cs ├── Actions │ ├── ActionMap.cs.meta │ ├── ControlScheme.cs.meta │ ├── InputAction.cs.meta │ ├── ActionMapInput.cs.meta │ ├── ButtonAxisSource.cs.meta │ ├── ControlBinding.cs.meta │ ├── ButtonAxisSource.cs │ ├── InputAction.cs │ ├── ControlBinding.cs │ ├── ControlScheme.cs │ ├── ActionMap.cs │ └── ActionMapInput.cs ├── Players │ ├── ActionSlot.cs.meta │ ├── PlayerHandle.cs.meta │ ├── PlayerInput.cs.meta │ ├── PlayerDeviceAssignment.cs.meta │ ├── PlayerHandleManager.cs.meta │ ├── ActionSlot.cs │ ├── PlayerDeviceAssignment.cs │ ├── PlayerInput.cs │ ├── PlayerHandleManager.cs │ └── PlayerHandle.cs └── Editor │ ├── ActionMapEditor.cs.meta │ ├── ActionMapSlotDrawer.cs.meta │ ├── ActionSlotDrawer.cs.meta │ ├── InputActionEditor.cs.meta │ ├── DeviceAssignmentsWindow.cs.meta │ ├── InputActionEditor.cs │ ├── ActionSlotDrawer.cs │ ├── ActionMapSlotDrawer.cs │ └── DeviceAssignmentsWindow.cs ├── Input.meta ├── Utilities.meta ├── DeviceProfiles.meta ├── FakePrototypeStuff.meta ├── FakePrototypeStuff ├── Editor.meta ├── InputManager.cs ├── InputManagerEndFrame.cs ├── ExecuteAllEvents.cs.meta ├── InputManager.cs.meta ├── InputManagerEndFrame.cs.meta ├── JoystickInputToEvents.cs.meta ├── KeyboardInputToEvents.cs.meta ├── MouseInputToEvents.cs.meta ├── TouchInputToEvents.cs.meta ├── Editor │ ├── InputManagerAssetGenerator.cs.meta │ └── InputManagerAssetGenerator.cs ├── ExecuteAllEvents.cs ├── KeyboardInputToEvents.cs ├── TouchInputToEvents.cs ├── JoystickInputToEvents.cs └── MouseInputToEvents.cs ├── Utilities ├── Range.cs.meta ├── ArrayHelpers.cs.meta ├── EnumHelpers.cs.meta ├── EnumHelpers.cs ├── Range.cs └── ArrayHelpers.cs ├── DeviceProfiles ├── Xbox360MacProfile.cs.meta ├── Xbox360WinProfile.cs.meta ├── Xbox360WinProfile.cs └── Xbox360MacProfile.cs └── .hgeol /.hgignore: -------------------------------------------------------------------------------- 1 | syntax: glob 2 | 3 | Builds 4 | Library 5 | Temp 6 | obj 7 | *.csproj 8 | *.sln 9 | *.suo 10 | *.userprefs 11 | Assets/UnityVS 12 | Assets/UnityVS.meta 13 | ProjectSettings/ProjectVersion.txt 14 | -------------------------------------------------------------------------------- /Input/Core.Extensions/GestureEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | public class GestureEvent 8 | : InputEvent { } 9 | } 10 | -------------------------------------------------------------------------------- /Input.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5d94ada0e7c19164b96a69672989b593 3 | folderAsset: yes 4 | timeCreated: 1438866776 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Input/Core.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b9d9e0f4d11034a7894a8070bce1ccc1 3 | folderAsset: yes 4 | timeCreated: 1462194390 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Utilities.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 238d94545b8b76b478f23d4ff5ad89b1 3 | folderAsset: yes 4 | timeCreated: 1439283900 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /DeviceProfiles.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c135a034f3fc6432d8778682510cebdb 3 | folderAsset: yes 4 | timeCreated: 1453731602 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Input/Actions.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5f013c76ad5a3420cba7676ad7fab309 3 | folderAsset: yes 4 | timeCreated: 1462194390 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Input/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b3f3dc63eea794c7e91774db1494f071 3 | folderAsset: yes 4 | timeCreated: 1440166399 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Input/Players.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ce9781f9b261b42e9a340f51908f09a7 3 | folderAsset: yes 4 | timeCreated: 1462194390 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /FakePrototypeStuff.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: df17c7d5aa8c94ff5b8d6d6831a85de0 3 | folderAsset: yes 4 | timeCreated: 1439384589 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Input/Core.Extensions.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ea55b7ebb8bf04a47b5516cd5686c5c4 3 | folderAsset: yes 4 | timeCreated: 1462194390 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /FakePrototypeStuff/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b2a37880bca5d433ca4ebef05f027014 3 | folderAsset: yes 4 | timeCreated: 1453801144 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Input/Actions.Extensions.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3d09f3ad771ef47b093eb7dd6b77903b 3 | folderAsset: yes 4 | timeCreated: 1462194390 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Input/Core.Extensions/TextEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | public class TextEvent 8 | : InputEvent 9 | { 10 | public char text { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /FakePrototypeStuff/InputManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.InputNew; 5 | 6 | public class InputManager : MonoBehaviour 7 | { 8 | public void Update() 9 | { 10 | InputSystem.BeginFrame(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /FakePrototypeStuff/InputManagerEndFrame.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.InputNew; 5 | 6 | public class InputManagerEndFrame 7 | : MonoBehaviour 8 | { 9 | public void Update() 10 | { 11 | InputSystem.EndFrame(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Input/Core/IInputConsumer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | public interface IInputConsumer 8 | { 9 | bool ProcessEvent(InputEvent inputEvent); 10 | void BeginFrame(); 11 | void EndFrame(); 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /Utilities/Range.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e94828671465cd44ca375c223b5a152c 3 | timeCreated: 1439283900 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core/InputDevice.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 91652e7dc8dd95f48a99d411b216e3ae 3 | timeCreated: 1438866778 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core/InputEvent.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9d336f4f1c9952e47bde29191e03e0f4 3 | timeCreated: 1438866778 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core/InputState.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8265672e363b8754581717555cb126f7 3 | timeCreated: 1438866778 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core/InputSystem.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7afd8fde8508ab0489a38415969e0cfd 3 | timeCreated: 1438866777 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Utilities/ArrayHelpers.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fffbdb36db8919e4a926f44504a9bee4 3 | timeCreated: 1439283901 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Utilities/EnumHelpers.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 81f61fefbe878034390d876993e2ef64 3 | timeCreated: 1439283900 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Actions/ActionMap.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 24e5bc088c9caeb44bc4283dc321b033 3 | timeCreated: 1438866777 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Actions/ControlScheme.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: be54574798ac04553822fb2c7e00f8be 3 | timeCreated: 1447957811 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Actions/InputAction.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5eba7b4b2e3ea134991ccbff5f47c2c8 3 | timeCreated: 1438866777 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core.Extensions/Mouse.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6c169a842e1bbf74792b6abbd8db17f7 3 | timeCreated: 1438866777 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core.Extensions/Touch.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 676977f729bc51d47937d90f59d2b396 3 | timeCreated: 1438866777 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core/IInputConsumer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 88ce262226418ec449dc79e969840e99 3 | timeCreated: 1438866778 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core/InputControl.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cf91e402f83bc6a46a5a9343c728c326 3 | timeCreated: 1438866778 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core/InputControlData.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b49855ae3989aa54d90ea4c1c10d9676 3 | timeCreated: 1438866778 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core/InputEventPool.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0806ea6c4385d8a42939c777fa42999a 3 | timeCreated: 1438866777 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core/InputEventQueue.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0ca991092316cb344b6405edd0ee04e5 3 | timeCreated: 1438866777 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core/SerializableType.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 053bf0744a0274cd981fcae66e2d5b70 3 | timeCreated: 1456408627 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Players/ActionSlot.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8ab74857d630b4dc091937b6ed3396e3 3 | timeCreated: 1456492279 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Players/PlayerHandle.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bb18dad3c119e40519cda4476d466f40 3 | timeCreated: 1450356268 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Players/PlayerInput.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 84d2c07be54604d7d9acbaf6555da85a 3 | timeCreated: 1454432856 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /DeviceProfiles/Xbox360MacProfile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 74d5812f1f3a44d03aec9b98fb5ea458 3 | timeCreated: 1453731638 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /DeviceProfiles/Xbox360WinProfile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 000735baa6fbf4eb986e8a00e82f3f4f 3 | timeCreated: 1453731868 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Actions/ActionMapInput.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2c6df40d2545e4197bbd27add3946ab7 3 | timeCreated: 1450098586 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Actions/ButtonAxisSource.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 605c663ce2502dd4e82a523ae076a264 3 | timeCreated: 1438866777 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Actions/ControlBinding.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8fa1b86be289ea840bfc551419b73254 3 | timeCreated: 1438866778 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core.Extensions/Cursor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 077a47926b79777419c5e31b2c4a88ce 3 | timeCreated: 1441378542 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core.Extensions/Gamepad.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: abe5bc8c7385d5c49972ba6c6a449283 3 | timeCreated: 1438866778 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core.Extensions/Joystick.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cc5b87a2812aae74fb2308fc6c55ef77 3 | timeCreated: 1439279680 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core.Extensions/KeyEvent.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d282f4d051def9d4bad1251dd6e6e73f 3 | timeCreated: 1438866778 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core.Extensions/Keyboard.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 88cc1a7c3eac4e84bb90e769fe1ec823 3 | timeCreated: 1438866778 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core.Extensions/Pointer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ba6f868c51c7f4d4b8094d08cd10ef24 3 | timeCreated: 1438866778 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core.Extensions/PointerClickEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | public class PointerClickEvent 8 | : PointerEvent 9 | { 10 | #region Public Properties 11 | 12 | public int clickCount { get; set; } 13 | 14 | #endregion 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Input/Core.Extensions/Sensor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 77614d65e34cc7849a37e7c094a71e0b 3 | timeCreated: 1438866777 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core.Extensions/TextEvent.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1cbbbbc69fce7994bbc000025f5613fe 3 | timeCreated: 1438866777 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core.Extensions/TouchEvent.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 23a5b4a5f1eab664b971b62087302101 3 | timeCreated: 1438866777 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core/GenericControlEvent.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9506a4680d3ce1a44a98ac6add882ab5 3 | timeCreated: 1438866778 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core/InputConsumerCallback.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: afd14ef13294d41beab63c04e5a03317 3 | timeCreated: 1461078095 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core/InputConsumerNode.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e67d12e588ef345588252659d6a33d4a 3 | timeCreated: 1461078040 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core/InputControlProvider.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 335a0db9b64a16748be8c5d9d2e3e9a6 3 | timeCreated: 1438866777 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core/InputDeviceManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7554916c5584fb1499808fe45cb47dd3 3 | timeCreated: 1438866777 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core/InputDeviceProfile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 16f4e64dfca4f044c9f211c4fc717ea6 3 | timeCreated: 1439283900 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core/InputDeviceUtility.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7cea9b0730c04497e8be64bf2f2b32e9 3 | timeCreated: 1448541213 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Editor/ActionMapEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a4f91c0e4879d41089766cbd995257b9 3 | timeCreated: 1440166437 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Editor/ActionMapSlotDrawer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1758d0d30e8874f9a8ecf2ab00205450 3 | timeCreated: 1457100065 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Editor/ActionSlotDrawer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e8fa6639a562440e7af654fd36eff9d3 3 | timeCreated: 1456491637 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Editor/InputActionEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: de4463e06a3744671b40c2d998a37cd7 3 | timeCreated: 1456483255 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /FakePrototypeStuff/ExecuteAllEvents.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 53b34d6500cdc4b47b70e4834694fd5c 3 | timeCreated: 1439369965 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: -10 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /FakePrototypeStuff/InputManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fa2ae5dc56e8f0946bd21197f7ad682a 3 | timeCreated: 1439307112 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: -100 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core.Extensions/GestureEvent.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 01eb6b30f4dc7874fbe9eeb77a77f652 3 | timeCreated: 1438866776 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core.Extensions/JoystickProfile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5f75f6d775084214b8ce7f1bb99559c9 3 | timeCreated: 1439283900 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core.Extensions/KeyboardEvent.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c12cfdf39d80fa847a791f08d70aa1f0 3 | timeCreated: 1439384870 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core.Extensions/PointerControl.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 145becbb581d4a741abd1553e75b0081 3 | timeCreated: 1438866777 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core.Extensions/PointerEvent.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b837135aa4d90444cb7b7ea76f21fb44 3 | timeCreated: 1438866778 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core.Extensions/TouchControl.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 576d35f8a26c90141958eb90f881bce8 3 | timeCreated: 1439468098 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core.Extensions/Touchscreen.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6e5079f48a784754e9abd9483dafce7f 3 | timeCreated: 1438866777 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core.Extensions/VirtualJoystick.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 78d99ea085da745b2bc1ba184337fc13 3 | timeCreated: 1440158478 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core/InputControlDescriptor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2b04845b17bd2af4f9a9e220502dd90e 3 | timeCreated: 1438866777 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Editor/DeviceAssignmentsWindow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a7f0087ea8d89492796d1e7467d6eefd 3 | timeCreated: 1456328681 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Players/PlayerDeviceAssignment.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 63e9b3286970d44249c7e292ba1cac74 3 | timeCreated: 1450362227 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Players/PlayerHandleManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 99a846cfd60dc4145a66a65503323ec5 3 | timeCreated: 1457370273 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /FakePrototypeStuff/InputManagerEndFrame.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0bc9e4d06df9449e89dde99e67fbd830 3 | timeCreated: 1448979955 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: -5 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /FakePrototypeStuff/JoystickInputToEvents.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 69b9f73264982e34197f4f0c12305253 3 | timeCreated: 1439369967 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: -50 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /FakePrototypeStuff/KeyboardInputToEvents.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 330c8870b308a774a82a43198e179c33 3 | timeCreated: 1439384878 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: -15 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /FakePrototypeStuff/MouseInputToEvents.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2b151f756c495834fa63f07ea366132a 3 | timeCreated: 1439369966 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: -20 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /FakePrototypeStuff/TouchInputToEvents.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 776e5fc7985e7f64fa92c05511f18927 3 | timeCreated: 1439481839 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: -13 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core.Extensions/PointerClickEvent.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c81bf6be9b9422246a66c0ba19d09c23 3 | timeCreated: 1438866778 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core.Extensions/PointerMoveEvent.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 221f5ba89578bde46864a88177210370 3 | timeCreated: 1438866777 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Core.Extensions/JoystickControlMapping.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5464917b6fb44fb4b8de5f7f0b18a112 3 | timeCreated: 1439283900 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /FakePrototypeStuff/Editor/InputManagerAssetGenerator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5a7bb81a042934f669f64df85ef589e9 3 | timeCreated: 1453801156 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Input/Editor/InputActionEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.InputNew; 3 | using UnityEditor; 4 | 5 | [CustomEditor(typeof(InputAction))] 6 | public class InputActionEditor : Editor 7 | { 8 | public override void OnInspectorGUI () 9 | { 10 | EditorGUILayout.HelpBox("Select the main Action Map asset to edit actions.", MessageType.Info); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Input/Core/InputControlData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | [Serializable] 8 | public struct InputControlData 9 | { 10 | public int[] componentControlIndices; 11 | public SerializableType controlType; 12 | public string name; 13 | public float defaultValue; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Input/Core.Extensions/Sensor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | public abstract class Sensor 8 | : InputDevice 9 | { 10 | #region Constructors 11 | 12 | protected Sensor(string deviceName, List controls) 13 | : base(deviceName, controls) { } 14 | 15 | #endregion 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Input/Core.Extensions/JoystickControlMapping.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Assets.Utilities; 4 | using UnityEngine; 5 | 6 | namespace UnityEngine.InputNew 7 | { 8 | [Serializable] 9 | public struct JoystickControlMapping 10 | { 11 | public int targetIndex; 12 | public Range fromRange; 13 | public Range toRange; 14 | public Range interDeadZoneRange; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Input/Editor/ActionSlotDrawer.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.InputNew; 3 | using UnityEditor; 4 | using System.Collections; 5 | 6 | [CustomPropertyDrawer(typeof(ActionSlot), true)] 7 | public class ActionSlotDrawer : PropertyDrawer 8 | { 9 | public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) 10 | { 11 | EditorGUI.ObjectField(position, property.FindPropertyRelative("action"), label); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Input/Core.Extensions/PointerMoveEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | ////TODO: PointerClickEvent (important as unlike GenericControlEvent it tells the position of the click) 6 | 7 | namespace UnityEngine.InputNew 8 | { 9 | public class PointerMoveEvent 10 | : PointerEvent 11 | { 12 | #region Public Properties 13 | 14 | public Vector3 delta { get; set; } 15 | 16 | #endregion 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Input/Core/InputEventPool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | class InputEventPool 8 | { 9 | #region Public Methods 10 | 11 | public TEvent ReuseOrCreate() 12 | where TEvent : InputEvent, new() 13 | { 14 | ////TODO 15 | return new TEvent(); 16 | } 17 | 18 | public void Return(InputEvent inputEvent) 19 | { 20 | ////TODO 21 | inputEvent.Reset(); 22 | } 23 | 24 | #endregion 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Input/Core.Extensions/KeyEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | public class KeyEvent 8 | : InputEvent 9 | { 10 | #region Public Properties 11 | 12 | public KeyCode rawKey { get; set; } 13 | public KeyCode localizedKey { get; set; } 14 | public bool isPress { get; private set; } 15 | public bool isRelease { get; private set; } 16 | public bool isRepeat { get; private set; } 17 | 18 | #endregion 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Input/Core.Extensions/Touch.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | public struct Touch 8 | { 9 | public int fingerId; 10 | public TouchPhase phase; 11 | public Vector2 position; 12 | public Vector2 rawPosition; 13 | public Vector2 delta; 14 | public float diameter; 15 | public float deltaTime; 16 | public float time; 17 | 18 | public bool isValid 19 | { 20 | get { return fingerId != 0; } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Utilities/EnumHelpers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace Assets.Utilities 6 | { 7 | public static class EnumHelpers 8 | { 9 | public static int GetValueCount() 10 | { 11 | // Slow... 12 | var values = (int[])Enum.GetValues(typeof(TEnum)); 13 | var set = new HashSet(); 14 | var count = 0; 15 | foreach(var value in values) 16 | { 17 | if(set.Add(value)) 18 | count++; 19 | } 20 | return count; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /FakePrototypeStuff/ExecuteAllEvents.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.InputNew; 5 | 6 | public class ExecuteAllEvents 7 | : MonoBehaviour 8 | { 9 | public void Update() 10 | { 11 | InputSystem.ExecuteEvents(); 12 | } 13 | 14 | // We can't execute events in both Update and FixedUpdate until we have a solution 15 | // for how to make checks for wasJustPressed and wasJustReleased work in both. 16 | /*public void FixedUpdate() 17 | { 18 | InputSystem.ExecuteEvents(); 19 | }*/ 20 | } 21 | -------------------------------------------------------------------------------- /Input/Players/ActionSlot.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace UnityEngine.InputNew 5 | { 6 | // We need a non-generic base class so that we can create a PropertyDrawer for it. 7 | public abstract class ActionSlot {} 8 | 9 | public class ActionSlot : ActionSlot where T : InputControl 10 | { 11 | public InputAction action; 12 | public T control; 13 | 14 | public void Bind(PlayerHandle player) 15 | { 16 | ActionMapInput map = player.GetActions(action.actionMap); 17 | control = map[action.actionIndex] as T; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Utilities/Range.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace Assets.Utilities 6 | { 7 | [Serializable] 8 | public struct Range 9 | { 10 | public static Range full = new Range(-1, 1); 11 | public static Range negative = new Range(0, -1); 12 | public static Range positive = new Range(0, 1); 13 | public static Range fullInverse = new Range(1, -1); 14 | 15 | public float min; 16 | public float max; 17 | 18 | public Range(float min, float max) 19 | { 20 | this.min = min; 21 | this.max = max; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Input/Core.Extensions/TouchEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | public class TouchEvent 8 | : InputEvent 9 | { 10 | #region Public Methods 11 | 12 | public override string ToString() 13 | { 14 | return string.Format("{0} finger={1} phase={2} pos={3} delta={4}", 15 | base.ToString(), touch.fingerId, touch.phase, touch.position, touch.delta); 16 | } 17 | 18 | #endregion 19 | 20 | #region Public Properties 21 | 22 | public Touch touch; 23 | 24 | #endregion 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Input/Core.Extensions/Mouse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | public class Mouse 8 | : Pointer 9 | { 10 | #region Constructors 11 | 12 | public Mouse() 13 | : this("Mouse", null) { } 14 | 15 | public Mouse(string deviceName, List controls) 16 | : base(deviceName, controls) 17 | { 18 | cursor = new Cursor(); 19 | } 20 | 21 | #endregion 22 | 23 | public new static Mouse current { get { return InputSystem.GetMostRecentlyUsedDevice(); } } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Input/Core/GenericControlEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | public class GenericControlEvent 8 | : InputEvent 9 | { 10 | #region Public Methods 11 | 12 | public override string ToString() 13 | { 14 | return string.Format("({0}, index:{1}, value:{2})", base.ToString(), controlIndex, value); 15 | } 16 | 17 | #endregion 18 | 19 | #region Public Properties 20 | 21 | public int controlIndex { get; set; } 22 | public float value { get; set; } 23 | 24 | #endregion 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Input/Core.Extensions/TouchControl.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | public enum TouchControl 8 | { 9 | Touch0Position = PointerControlConstants.ControlCount, 10 | Touch0PositionX, 11 | Touch0PositionY, 12 | 13 | Touch0Delta, 14 | Touch0DeltaX, 15 | Touch0DeltaY, 16 | 17 | Touch0Phase, 18 | } 19 | 20 | public static class TouchControlConstants 21 | { 22 | public const int ControlCount = (int)TouchControl.Touch0Phase + 1; 23 | public const int ControlsPerTouch = TouchControl.Touch0Phase - TouchControl.Touch0Position; 24 | } 25 | } -------------------------------------------------------------------------------- /Input/Core.Extensions/KeyboardEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | public class KeyboardEvent 8 | : InputEvent 9 | { 10 | #region Public Methods 11 | 12 | public override string ToString() 13 | { 14 | return string.Format("({0}, key:{1}, isDown:{2})", base.ToString(), key, isDown); 15 | } 16 | 17 | #endregion 18 | 19 | #region Public Properties 20 | 21 | public KeyCode key { get; set; } 22 | public bool isDown { get; set; } 23 | public bool isRepeat { get; set; } 24 | public int modifiers { get; set; } 25 | 26 | #endregion 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Input/Core.Extensions/PointerEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | public class PointerEvent 8 | : InputEvent 9 | { 10 | #region Public Methods 11 | 12 | public override string ToString() 13 | { 14 | return string.Format("({0}, pos:{1})", base.ToString(), position); 15 | } 16 | 17 | #endregion 18 | 19 | #region Public Properties 20 | 21 | public Vector3 position { get; set; } 22 | public float pressure { get; set; } 23 | public float tilt { get; set; } 24 | public float rotation { get; set; } 25 | public int displayIndex { get; set; } 26 | 27 | #endregion 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Input/Core.Extensions/Cursor.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace UnityEngine.InputNew 4 | { 5 | public class Cursor 6 | { 7 | public bool isLocked 8 | { 9 | get { return UnityEngine.Cursor.lockState == CursorLockMode.Locked; } 10 | set 11 | { 12 | if (value) 13 | { 14 | UnityEngine.Cursor.lockState = CursorLockMode.Locked; 15 | isVisible = false; ////REVIEW: directly linking these two states is probably bogus 16 | } 17 | else 18 | { 19 | UnityEngine.Cursor.lockState = CursorLockMode.None; 20 | isVisible = true; 21 | } 22 | } 23 | } 24 | 25 | public bool isVisible 26 | { 27 | get { return UnityEngine.Cursor.visible; } 28 | set { UnityEngine.Cursor.visible = value; } 29 | } 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /Input/Players/PlayerDeviceAssignment.cs: -------------------------------------------------------------------------------- 1 | namespace UnityEngine.InputNew 2 | { 3 | public class PlayerDeviceAssignment 4 | { 5 | public readonly PlayerHandle player; 6 | public readonly InputDevice device; 7 | 8 | public PlayerDeviceAssignment(PlayerHandle playerHandle, InputDevice device) 9 | { 10 | this.device = device; 11 | this.player = playerHandle; 12 | } 13 | 14 | public void Assign() 15 | { 16 | player.assignments.Add(this); 17 | device.assignment = this; 18 | 19 | if (PlayerHandle.onChange != null) 20 | PlayerHandle.onChange.Invoke(); 21 | } 22 | 23 | public void Unassign() 24 | { 25 | player.assignments.Remove(this); 26 | device.assignment = null; 27 | 28 | if (PlayerHandle.onChange != null) 29 | PlayerHandle.onChange.Invoke(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Input/Core.Extensions/Joystick.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | // Must be different from Gamepad as the standardized controls for Gamepads don't 8 | // work for joysticks. 9 | public class Joystick 10 | : InputDevice 11 | { 12 | #region Constructors 13 | 14 | public Joystick() 15 | : this("Joystick", null) { } 16 | 17 | public Joystick(string deviceName, List additionalControls) 18 | { 19 | this.deviceName = deviceName; 20 | var controls = new List(); 21 | 22 | // TODO create default joystick buttons and axes 23 | 24 | if (additionalControls != null) 25 | controls.AddRange(additionalControls); 26 | 27 | SetControls(controls); 28 | } 29 | 30 | #endregion 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Input/Core.Extensions/PointerControl.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | public enum PointerControl 8 | { 9 | Position, 10 | PositionX, 11 | PositionY, 12 | PositionZ, 13 | 14 | Delta, 15 | DeltaX, 16 | DeltaY, 17 | DeltaZ, 18 | 19 | LockedDelta, 20 | LockedDeltaX, 21 | LockedDeltaY, 22 | LockedDeltaZ, 23 | 24 | Pressure, 25 | Tilt, 26 | Rotation, 27 | 28 | LeftButton, 29 | RightButton, 30 | MiddleButton, 31 | 32 | ScrollWheel, 33 | ScrollWheelX, 34 | ScrollWheelY, 35 | ////REVIEW: have Z for ScrollWheel, too? 36 | 37 | ForwardButton, 38 | BackButton, 39 | } 40 | 41 | public static class PointerControlConstants 42 | { 43 | public const int ControlCount = (int)PointerControl.BackButton + 1; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Utilities/ArrayHelpers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using UnityEngine; 5 | 6 | namespace Assets.Utilities 7 | { 8 | public static class ArrayHelpers 9 | { 10 | public static void Resize(ref T[] array, int newSize) 11 | { 12 | if (array == null) 13 | array = new T[1]; 14 | else 15 | { 16 | var newArray = new T[newSize]; 17 | Array.Copy(array, newArray, newSize); 18 | array = newArray; 19 | } 20 | } 21 | 22 | public static void AppendUnique(ref T[] array, T value) 23 | { 24 | if (array == null) 25 | { 26 | array = new T[1]; 27 | array[0] = value; 28 | } 29 | else 30 | { 31 | if (array.Contains(value)) 32 | return; 33 | 34 | Resize(ref array, array.Length + 1); 35 | array[array.Length - 1] = value; 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Input/Core/InputConsumerCallback.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | internal class InputConsumerCallback : IInputConsumer 8 | { 9 | public delegate bool ProcessInputDelegate(InputEvent inputEvent); 10 | public delegate void FrameDelegate(); 11 | 12 | public ProcessInputDelegate processEvent { get; set; } 13 | public FrameDelegate beginFrame { get; set; } 14 | public FrameDelegate endFrame { get; set; } 15 | 16 | public bool ProcessEvent(InputEvent inputEvent) 17 | { 18 | if (processEvent != null) 19 | return processEvent(inputEvent); 20 | return false; 21 | } 22 | 23 | public void BeginFrame() 24 | { 25 | if (beginFrame != null) 26 | beginFrame(); 27 | } 28 | 29 | public void EndFrame() 30 | { 31 | if (endFrame != null) 32 | endFrame(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Input/Core/InputConsumerNode.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using UnityEngine; 3 | 4 | namespace UnityEngine.InputNew 5 | { 6 | public class InputConsumerNode : IInputConsumer 7 | { 8 | List m_Children = new List(); 9 | public List children { get { return m_Children; } } 10 | 11 | public bool ProcessEvent(InputEvent inputEvent) 12 | { 13 | for (int i = 0; i < m_Children.Count; i++) 14 | { 15 | if (m_Children[i].ProcessEvent(inputEvent)) 16 | return true; 17 | } 18 | return false; 19 | } 20 | 21 | public void BeginFrame() 22 | { 23 | for (int i = 0; i < m_Children.Count; i++) 24 | { 25 | m_Children[i].BeginFrame(); 26 | } 27 | } 28 | 29 | public void EndFrame() 30 | { 31 | for (int i = 0; i < m_Children.Count; i++) 32 | { 33 | m_Children[i].EndFrame(); 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Input/Actions/ButtonAxisSource.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | [Serializable] 8 | public class ButtonAxisSource 9 | { 10 | public InputControlDescriptor negative; 11 | public InputControlDescriptor positive; 12 | 13 | public ButtonAxisSource() 14 | { 15 | } 16 | 17 | public virtual ButtonAxisSource Clone() 18 | { 19 | var clone = (ButtonAxisSource) Activator.CreateInstance(GetType()); 20 | clone.negative = negative.Clone(); 21 | clone.positive = positive.Clone(); 22 | return clone; 23 | } 24 | 25 | public ButtonAxisSource(InputControlDescriptor negative, InputControlDescriptor positive) 26 | { 27 | this.negative = negative; 28 | this.positive = positive; 29 | } 30 | 31 | public override string ToString() 32 | { 33 | return string.Format("({0}, {1})", negative, positive); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Input/Actions/InputAction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.Serialization; 5 | 6 | namespace UnityEngine.InputNew 7 | { 8 | public class InputAction : ScriptableObject 9 | { 10 | public new string name 11 | { 12 | get 13 | { 14 | return m_ControlData.name; 15 | } 16 | set 17 | { 18 | m_ControlData.name = value; 19 | base.name = value; 20 | } 21 | } 22 | 23 | [SerializeField] 24 | private ActionMap m_ActionMap; 25 | public ActionMap actionMap { get { return m_ActionMap; } set { m_ActionMap = value; } } 26 | 27 | [SerializeField] 28 | private int m_ActionIndex; 29 | public int actionIndex { get { return m_ActionIndex; } set { m_ActionIndex = value; } } 30 | 31 | [SerializeField] 32 | private InputControlData m_ControlData; 33 | public InputControlData controlData { get { return m_ControlData; } set { m_ControlData = value; } } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /.hgeol: -------------------------------------------------------------------------------- 1 | [repository] 2 | native = LF 3 | [patterns] 4 | **.py = LF 5 | **.pl = LF 6 | **.pm = LF 7 | **.t = LF 8 | **.it = LF 9 | **.h = LF 10 | **.cpp = LF 11 | **.cs = LF 12 | **.c = LF 13 | **.txt = LF 14 | **.bindings = LF 15 | **.sh = LF 16 | **.jam = LF 17 | **.as = LF 18 | **.boo = LF 19 | **.java = LF 20 | **.js = LF 21 | Makefile = LF 22 | **.shader = LF 23 | **.cginc = LF 24 | **.glslinc = LF 25 | **.mm = LF 26 | Repositories.ini = LF 27 | .hgignore = LF 28 | 29 | ## keep CRLF's in sync with .editorconfig 30 | 31 | # vs can handle these as lf, but really wants them as crlf 32 | **.vcproj = CRLF 33 | **.vcxproj = CRLF 34 | **.vcxproj.filters = CRLF 35 | **.csproj = CRLF 36 | **.sln = CRLF 37 | **.sln.template = CRLF 38 | **.bat = CRLF 39 | **.cmd = CRLF 40 | **.xaml = CRLF 41 | # the text templating parser will actually fail on lf, inexplicably setting every #line directive as '1' 42 | **.tt = CRLF 43 | **.t4 = CRLF 44 | **.ttinclude = CRLF 45 | 46 | [eol] 47 | only-consistent = False 48 | -------------------------------------------------------------------------------- /FakePrototypeStuff/KeyboardInputToEvents.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.InputNew; 5 | using Assets.Utilities; 6 | 7 | public class KeyboardInputToEvents 8 | : MonoBehaviour 9 | { 10 | public void Update() 11 | { 12 | int controlCount = EnumHelpers.GetValueCount(); 13 | for (int i = 0; i < controlCount; i++) 14 | HandleKey((KeyCode)i, (KeyCode)i); 15 | } 16 | 17 | void HandleKey(KeyCode keyCode, KeyCode keyControl) 18 | { 19 | if (Input.GetKeyDown(keyCode)) 20 | SendKeyboardEvent(keyControl, true); 21 | if (Input.GetKeyUp(keyCode)) 22 | SendKeyboardEvent(keyControl, false); 23 | } 24 | 25 | void SendKeyboardEvent(KeyCode key, bool isDown) 26 | { 27 | var inputEvent = InputSystem.CreateEvent(); 28 | 29 | inputEvent.deviceType = typeof(Keyboard); 30 | inputEvent.deviceIndex = 0; 31 | inputEvent.key = key; 32 | inputEvent.isDown = isDown; 33 | ////TODO: modifiers 34 | 35 | InputSystem.QueueEvent(inputEvent); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Input/Core/InputControlDescriptor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace UnityEngine.InputNew 5 | { 6 | [Serializable] 7 | public class InputControlDescriptor 8 | { 9 | public int controlIndex; 10 | public SerializableType deviceType; 11 | 12 | public virtual InputControlDescriptor Clone() 13 | { 14 | var clone = (InputControlDescriptor) Activator.CreateInstance(GetType()); 15 | clone.controlIndex = controlIndex; 16 | clone.deviceType = new SerializableType(deviceType); 17 | return clone; 18 | } 19 | 20 | public override string ToString() 21 | { 22 | return string.Format( "(device:{0}, control:{1})", deviceType.Name, controlIndex ); 23 | } 24 | 25 | public void ExtractDeviceTypeAndControlIndex(Dictionary> controlIndicesPerDeviceType) 26 | { 27 | List entries; 28 | if (!controlIndicesPerDeviceType.TryGetValue(deviceType, out entries)) 29 | { 30 | entries = new List(); 31 | controlIndicesPerDeviceType[deviceType] = entries; 32 | } 33 | 34 | entries.Add(controlIndex); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Input/Core/SerializableType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace UnityEngine.InputNew 4 | { 5 | [Serializable] 6 | public class SerializableType 7 | { 8 | [SerializeField] 9 | private string m_TypeName; 10 | 11 | private Type m_CachedType; 12 | 13 | public SerializableType(Type t) 14 | { 15 | value = t; 16 | } 17 | 18 | public Type value 19 | { 20 | get 21 | { 22 | if (m_CachedType == null) 23 | { 24 | if (string.IsNullOrEmpty(m_TypeName)) 25 | return null; 26 | m_CachedType = Type.GetType(m_TypeName); 27 | } 28 | return m_CachedType; 29 | } 30 | set 31 | { 32 | m_CachedType = value; 33 | if (m_CachedType == null) 34 | m_TypeName = string.Empty; 35 | else 36 | m_TypeName = m_CachedType.AssemblyQualifiedName; 37 | } 38 | } 39 | 40 | public string Name { get { return value.Name; } } 41 | 42 | public static implicit operator Type(SerializableType t) 43 | { 44 | return (t == null) ? null : t.value; 45 | } 46 | 47 | public static implicit operator SerializableType(Type t) 48 | { 49 | return new SerializableType(t); 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /Input/Editor/ActionMapSlotDrawer.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.InputNew; 3 | using UnityEditor; 4 | using System.Collections; 5 | 6 | [CustomPropertyDrawer(typeof(ActionMapSlot), true)] 7 | public class ActionMapSlotDrawer : PropertyDrawer 8 | { 9 | const int k_ActiveWidth = 13; 10 | const int k_BlockWidth = 50; 11 | 12 | public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) 13 | { 14 | position = EditorGUI.PrefixLabel(position, label); 15 | 16 | EditorGUIUtility.labelWidth = k_BlockWidth - k_ActiveWidth; 17 | EditorGUI.indentLevel = 0; 18 | 19 | Rect pos = position; 20 | pos.width = k_ActiveWidth; 21 | EditorGUI.PropertyField(pos, property.FindPropertyRelative("active"), GUIContent.none); 22 | 23 | pos = position; 24 | pos.xMin += k_ActiveWidth + 4; 25 | pos.xMax -= k_BlockWidth + 10; 26 | EditorGUI.PropertyField(pos, property.FindPropertyRelative("actionMap"), GUIContent.none); 27 | 28 | pos = position; 29 | pos.xMin = pos.xMax - k_BlockWidth; 30 | EditorGUI.PropertyField(pos, property.FindPropertyRelative("blockSubsequent"), new GUIContent("Block")); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Input/Core/InputDeviceProfile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Assets.Utilities; 4 | using UnityEngine; 5 | 6 | namespace UnityEngine.InputNew 7 | { 8 | public abstract class InputDeviceProfile 9 | { 10 | #region Public Methods 11 | 12 | public abstract void Remap(InputEvent inputEvent); 13 | 14 | public void AddSupportedPlatform(string platform) 15 | { 16 | ArrayHelpers.AppendUnique(ref supportedPlatforms, platform); 17 | } 18 | 19 | public void AddDeviceName(string deviceName) 20 | { 21 | ArrayHelpers.AppendUnique(ref deviceNames, deviceName); 22 | } 23 | 24 | public void AddDeviceRegex(string regex) 25 | { 26 | ArrayHelpers.AppendUnique(ref deviceRegexes, regex); 27 | } 28 | 29 | public virtual string GetControlNameOverride(int controlIndex) 30 | { 31 | return null; 32 | } 33 | 34 | #endregion 35 | 36 | #region Public Properties 37 | 38 | public string[] supportedPlatforms; 39 | public string[] deviceNames; 40 | public string[] deviceRegexes; 41 | public string lastResortDeviceRegex; 42 | public Version minUnityVersion; 43 | public Version maxUnityVersion; 44 | 45 | #endregion 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Input/Core/InputEventQueue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | class InputEventQueue 8 | { 9 | #region Fields 10 | 11 | readonly SortedList m_List = new SortedList(new SortInputEventsByTime()); 12 | 13 | #endregion 14 | 15 | #region Inner Types 16 | 17 | class SortInputEventsByTime 18 | : IComparer 19 | { 20 | public int Compare(float x, float y) 21 | { 22 | if (x < y) 23 | return -1; 24 | // Avoid duplicate keys in sorted list by always treating equality as greater-than. 25 | return 1; 26 | } 27 | } 28 | 29 | #endregion 30 | 31 | #region Public Methods 32 | 33 | public void Queue(InputEvent inputEvent) 34 | { 35 | m_List.Add(inputEvent.time, inputEvent); 36 | } 37 | 38 | public bool Dequeue(float targetTime, out InputEvent inputEvent) 39 | { 40 | if (m_List.Count == 0) 41 | { 42 | inputEvent = null; 43 | return false; 44 | } 45 | 46 | var nextEvent = m_List.Values[0]; 47 | if (nextEvent.time > targetTime) 48 | { 49 | inputEvent = null; 50 | return false; 51 | } 52 | 53 | m_List.RemoveAt(0); 54 | inputEvent = nextEvent; 55 | return true; 56 | } 57 | 58 | #endregion 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Input/Players/PlayerInput.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using UnityEngine.Serialization; 6 | 7 | namespace UnityEngine.InputNew 8 | { 9 | public class PlayerInput : MonoBehaviour 10 | { 11 | // Should this player handle request assignment of an input device as soon as the component awakes? 12 | [FormerlySerializedAs("autoSinglePlayerAssign")] 13 | public bool autoAssignGlobal = true; 14 | 15 | public List actionMaps = new List(); 16 | 17 | public PlayerHandle handle { get; set; } 18 | 19 | void Awake() 20 | { 21 | if (autoAssignGlobal) 22 | { 23 | handle = PlayerHandleManager.GetNewPlayerHandle(); 24 | handle.global = true; 25 | foreach (ActionMapSlot actionMapSlot in actionMaps) 26 | { 27 | ActionMapInput actionMapInput = ActionMapInput.Create(actionMapSlot.actionMap); 28 | actionMapInput.TryInitializeWithDevices(handle.GetApplicableDevices()); 29 | actionMapInput.active = actionMapSlot.active; 30 | actionMapInput.blockSubsequent = actionMapSlot.blockSubsequent; 31 | handle.maps.Add(actionMapInput); 32 | } 33 | } 34 | } 35 | 36 | public T GetActions() where T : ActionMapInput 37 | { 38 | if (handle == null) 39 | return null; 40 | return handle.GetActions(); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /FakePrototypeStuff/TouchInputToEvents.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.InputNew; 5 | using Touch = UnityEngine.Touch; 6 | 7 | public class TouchInputToEvents : MonoBehaviour 8 | { 9 | void Awake() 10 | { 11 | Input.simulateMouseWithTouches = false; 12 | 13 | var touchCount = Input.touchCount; 14 | for (var i = 0; i < m_LastTouches.Length && i < touchCount; ++i) 15 | m_LastTouches[i] = Input.GetTouch(i); 16 | } 17 | 18 | void Update() 19 | { 20 | var touchCount = Input.touchCount; 21 | for (var i = 0; i < m_LastTouches.Length && i < touchCount; ++i) 22 | { 23 | var touch = Input.GetTouch(i); 24 | 25 | if (touch.position == m_LastTouches[i].position 26 | && touch.phase == m_LastTouches[i].phase) 27 | continue; 28 | 29 | var newTouch = new UnityEngine.InputNew.Touch 30 | { 31 | fingerId = touch.fingerId 32 | , position = touch.position 33 | , delta = touch.deltaPosition 34 | , deltaTime = touch.deltaTime 35 | , phase = touch.phase 36 | , time = Time.time 37 | }; 38 | 39 | SendTouchEvent(newTouch); 40 | } 41 | } 42 | 43 | private void SendTouchEvent(UnityEngine.InputNew.Touch touch) 44 | { 45 | var inputEvent = InputSystem.CreateEvent(); 46 | inputEvent.deviceType = typeof(Touchscreen); 47 | inputEvent.deviceIndex = 0; 48 | inputEvent.touch = touch; 49 | 50 | InputSystem.QueueEvent(inputEvent); 51 | } 52 | 53 | private Touch[] m_LastTouches = new Touch[Touchscreen.MaxConcurrentTouches]; 54 | } 55 | -------------------------------------------------------------------------------- /Input/Actions/ControlBinding.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using UnityEngine; 5 | 6 | namespace UnityEngine.InputNew 7 | { 8 | [Serializable] 9 | public class ControlBinding 10 | { 11 | public List sources = new List(); 12 | public float deadZone = 0.3f; 13 | public List buttonAxisSources = new List(); 14 | public float gravity = 1000; 15 | public float sensitivity = 1000; 16 | public bool snap = true; 17 | public bool primaryIsButtonAxis = false; 18 | 19 | public virtual ControlBinding Clone() 20 | { 21 | var clone = (ControlBinding) Activator.CreateInstance(GetType()); 22 | clone.sources = sources.Select(x => x.Clone()).ToList(); 23 | clone.deadZone = deadZone; 24 | clone.buttonAxisSources = buttonAxisSources.Select(x => x.Clone()).ToList(); 25 | clone.gravity = gravity; 26 | clone.sensitivity = sensitivity; 27 | clone.snap = snap; 28 | clone.primaryIsButtonAxis = primaryIsButtonAxis; 29 | return clone; 30 | } 31 | 32 | public void ExtractDeviceTypesAndControlIndices(Dictionary> controlIndicesPerDeviceType) 33 | { 34 | foreach (var control in sources) 35 | { 36 | control.ExtractDeviceTypeAndControlIndex(controlIndicesPerDeviceType); 37 | } 38 | 39 | foreach (var axis in buttonAxisSources) 40 | { 41 | axis.negative.ExtractDeviceTypeAndControlIndex(controlIndicesPerDeviceType); 42 | axis.positive.ExtractDeviceTypeAndControlIndex(controlIndicesPerDeviceType); 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Input/Players/PlayerHandleManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | #if UNITY_EDITOR 5 | using UnityEditor; 6 | #endif 7 | 8 | namespace UnityEngine.InputNew 9 | { 10 | public static class PlayerHandleManager 11 | { 12 | static Dictionary s_Players = null; 13 | static int s_NextPlayerIndex = 0; 14 | 15 | public static IEnumerable players { get { return s_Players.Values; } } 16 | 17 | static PlayerHandleManager() 18 | { 19 | Reset(); 20 | 21 | #if UNITY_EDITOR 22 | EditorApplication.playmodeStateChanged += OnPlaymodeChanged; 23 | #endif 24 | } 25 | 26 | public static PlayerHandle GetNewPlayerHandle() 27 | { 28 | PlayerHandle handle = new PlayerHandle(s_NextPlayerIndex); 29 | s_Players[handle.index] = handle; 30 | s_NextPlayerIndex++; 31 | return handle; 32 | } 33 | 34 | // Gets existing handle for index if available. 35 | public static PlayerHandle GetPlayerHandle(int index) 36 | { 37 | PlayerHandle player = null; 38 | s_Players.TryGetValue(index, out player); 39 | return player; 40 | } 41 | 42 | internal static void RemovePlayerHandle(PlayerHandle handle) 43 | { 44 | s_Players.Remove(handle.index); 45 | } 46 | 47 | #if UNITY_EDITOR 48 | static void OnPlaymodeChanged() 49 | { 50 | if (EditorApplication.isPlayingOrWillChangePlaymode) 51 | return; 52 | Reset(); 53 | } 54 | #endif 55 | 56 | static void Reset() 57 | { 58 | if (s_Players != null) 59 | { 60 | List players = new List(s_Players.Values); 61 | for (int i = 0; i < players.Count; i++) 62 | players[i].Destroy(); 63 | } 64 | 65 | s_Players = new Dictionary(); 66 | s_NextPlayerIndex = 0; 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Input/Core.Extensions/Keyboard.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Assets.Utilities; 5 | using UnityEngine; 6 | 7 | namespace UnityEngine.InputNew 8 | { 9 | public class Keyboard 10 | : InputDevice 11 | { 12 | #region Constructors 13 | 14 | public Keyboard() 15 | : this("Keyboard", null) { } 16 | 17 | public Keyboard(string deviceName, List additionalControls) 18 | { 19 | this.deviceName = deviceName; 20 | var controlCount = EnumHelpers.GetValueCount(); 21 | var controls = Enumerable.Repeat(new InputControlData(), controlCount).ToList(); 22 | 23 | for (var i = 0; i < controlCount; ++ i) 24 | { 25 | InitKey(controls, (KeyCode)i); 26 | } 27 | 28 | if (additionalControls != null) 29 | controls.AddRange(additionalControls); 30 | 31 | SetControls(controls); 32 | } 33 | 34 | #endregion 35 | 36 | #region Non-Public Methods 37 | 38 | static void InitKey(List controls, KeyCode key) 39 | { 40 | controls[(int)key] = new InputControlData 41 | { 42 | name = key.ToString() 43 | , controlType = typeof(ButtonInputControl) 44 | }; 45 | } 46 | 47 | #endregion 48 | 49 | #region Public Methods 50 | 51 | public static Keyboard current { get { return InputSystem.GetMostRecentlyUsedDevice(); } } 52 | 53 | public override bool ProcessEventIntoState(InputEvent inputEvent, InputState intoState) 54 | { 55 | if (base.ProcessEventIntoState(inputEvent, intoState)) 56 | return true; 57 | 58 | var consumed = false; 59 | 60 | var keyEvent = inputEvent as KeyboardEvent; 61 | if (keyEvent != null) 62 | consumed |= intoState.SetCurrentValue((int)keyEvent.key, keyEvent.isDown); 63 | 64 | return consumed; 65 | } 66 | 67 | #endregion 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /DeviceProfiles/Xbox360WinProfile.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine.InputNew; 2 | using System.Collections; 3 | using Assets.Utilities; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | public class Xbox360WinProfile : JoystickProfile 8 | { 9 | public Xbox360WinProfile() 10 | { 11 | var gamepad = new Gamepad(); 12 | 13 | AddDeviceName("Gamepad"); 14 | AddSupportedPlatform("Windows"); 15 | SetMappingsCount(gamepad.controlDataList.Count, gamepad.controlDataList.Count); 16 | 17 | SetMapping(00, gamepad.leftStickX.index, "Left Stick X"); 18 | SetMapping(01, gamepad.leftStickY.index, "Left Stick Y", defaultDeadZones, Range.fullInverse, Range.full); 19 | SetMapping(18, gamepad.leftStickButton.index, "Left Stick Button"); 20 | 21 | SetMapping(03, gamepad.rightStickX.index, "Right Stick X"); 22 | SetMapping(04, gamepad.rightStickY.index, "Right Stick Y", defaultDeadZones, Range.fullInverse, Range.full); 23 | SetMapping(19, gamepad.rightStickButton.index, "Right Stick Button"); 24 | 25 | SetMapping(06, gamepad.dPadUp.index, "DPad Up"); 26 | SetMapping(06, gamepad.dPadDown.index, "DPad Down"); 27 | SetMapping(05, gamepad.dPadLeft.index, "DPad Left"); 28 | SetMapping(05, gamepad.dPadRight.index, "DPad Right"); 29 | 30 | SetMapping(10, gamepad.action1.index, "A"); 31 | SetMapping(11, gamepad.action2.index, "B"); 32 | SetMapping(12, gamepad.action3.index, "X"); 33 | SetMapping(13, gamepad.action4.index, "Y"); 34 | 35 | SetMapping(08, gamepad.leftTrigger.index, "Left Trigger", defaultDeadZones, Range.full, Range.positive); 36 | SetMapping(09, gamepad.rightTrigger.index, "Right Trigger", defaultDeadZones, Range.full, Range.positive); 37 | SetMapping(14, gamepad.leftBumper.index, "Left Bumper"); 38 | SetMapping(15, gamepad.rightBumper.index, "Right Bumper"); 39 | 40 | SetMapping(17, gamepad.start.index, "Start"); 41 | SetMapping(16, gamepad.back.index, "Back"); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /DeviceProfiles/Xbox360MacProfile.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine.InputNew; 2 | using System.Collections; 3 | using Assets.Utilities; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | public class Xbox360MacProfile : JoystickProfile 8 | { 9 | public Xbox360MacProfile() 10 | { 11 | var gamepad = new Gamepad(); 12 | 13 | AddDeviceName("Gamepad"); 14 | AddSupportedPlatform("OS X"); 15 | SetMappingsCount(gamepad.controlCount, gamepad.controlCount); 16 | 17 | SetMapping(00, gamepad.leftStickX.index, "Left Stick X"); 18 | SetMapping(01, gamepad.leftStickY.index, "Left Stick Y", defaultDeadZones, Range.fullInverse, Range.full); 19 | SetMapping(21, gamepad.leftStickButton.index, "Left Stick Button"); 20 | 21 | SetMapping(02, gamepad.rightStickX.index, "Right Stick X"); 22 | SetMapping(03, gamepad.rightStickY.index, "Right Stick Y", defaultDeadZones, Range.fullInverse, Range.full); 23 | SetMapping(22, gamepad.rightStickButton.index, "Right Stick Button"); 24 | 25 | SetMapping(15, gamepad.dPadUp.index, "DPad Up"); 26 | SetMapping(16, gamepad.dPadDown.index, "DPad Down"); 27 | SetMapping(17, gamepad.dPadLeft.index, "DPad Left"); 28 | SetMapping(18, gamepad.dPadRight.index, "DPad Right"); 29 | 30 | SetMapping(26, gamepad.action1.index, "A"); 31 | SetMapping(27, gamepad.action2.index, "B"); 32 | SetMapping(28, gamepad.action3.index, "X"); 33 | SetMapping(29, gamepad.action4.index, "Y"); 34 | 35 | SetMapping(04, gamepad.leftTrigger.index, "Left Trigger", defaultDeadZones, Range.full, Range.positive); 36 | SetMapping(05, gamepad.rightTrigger.index, "Right Trigger", defaultDeadZones, Range.full, Range.positive); 37 | SetMapping(23, gamepad.leftBumper.index, "Left Bumper"); 38 | SetMapping(24, gamepad.rightBumper.index, "Right Bumper"); 39 | 40 | SetMapping(19, gamepad.start.index, "Start"); 41 | SetMapping(20, gamepad.back.index, "Back"); 42 | SetMapping(25, gamepad.system.index, "System"); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Input/Actions/ControlScheme.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using UnityEngine; 5 | using UnityEngine.Serialization; 6 | 7 | namespace UnityEngine.InputNew 8 | { 9 | [Serializable] 10 | public class ControlScheme 11 | { 12 | [SerializeField] 13 | private string m_Name; 14 | public string name { get { return m_Name; } set { m_Name = value; } } 15 | 16 | [SerializeField] 17 | private List m_SerializableDeviceTypes = new List(); 18 | public List serializableDeviceTypes { get { return m_SerializableDeviceTypes; } set { m_SerializableDeviceTypes = value; } } 19 | public IEnumerable deviceTypes { get { return m_SerializableDeviceTypes.Select(e => (Type)e); } } 20 | 21 | [SerializeField] 22 | private ActionMap m_ActionMap; 23 | public ActionMap actionMap { get { return m_ActionMap; } } 24 | 25 | [SerializeField] 26 | private List m_Bindings = new List (); 27 | public List bindings { get { return m_Bindings; } set { m_Bindings = value; } } 28 | 29 | public bool customized { get; internal set; } 30 | 31 | public ControlScheme() 32 | { 33 | } 34 | 35 | public ControlScheme(string name, ActionMap actionMap) 36 | { 37 | m_Name = name; 38 | m_ActionMap = actionMap; 39 | } 40 | 41 | public virtual ControlScheme Clone() 42 | { 43 | var clone = (ControlScheme) Activator.CreateInstance(GetType()); 44 | clone.m_Name = m_Name; 45 | clone.m_SerializableDeviceTypes = m_SerializableDeviceTypes.Select(x => new SerializableType(x)).ToList(); 46 | clone.m_ActionMap = m_ActionMap; 47 | clone.m_Bindings = m_Bindings.Select(x => x.Clone()).ToList(); 48 | // Don't clone customized flag. 49 | return clone; 50 | } 51 | 52 | public void ExtractDeviceTypesAndControlIndices (Dictionary> controlIndicesPerDeviceType) 53 | { 54 | foreach (var binding in bindings) 55 | binding.ExtractDeviceTypesAndControlIndices(controlIndicesPerDeviceType); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /FakePrototypeStuff/JoystickInputToEvents.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.InputNew; 3 | 4 | public class JoystickInputToEvents 5 | : MonoBehaviour 6 | { 7 | #region Public Methods 8 | 9 | public void Update() 10 | { 11 | SendButtonEvents(); 12 | SendAxisEvents(); 13 | } 14 | 15 | #endregion 16 | 17 | #region Non-Public Methods 18 | 19 | // Fake gamepad has 10 axes (index 0 - 9) and 20 buttons (index 10 - 29). 20 | public const int axisCount = 10; 21 | public const int buttonCount = 20; 22 | public const int joystickCount = 10; 23 | private float[,] m_LastValues = new float[joystickCount, axisCount + buttonCount]; 24 | 25 | private void SendAxisEvents() 26 | { 27 | int first = 1; 28 | int last = 10; 29 | for (int device = 0; device < joystickCount; device++) 30 | { 31 | for (int i = 0; i <= last - first; i++) 32 | { 33 | var value = Input.GetAxis("Analog" + (i + first) + "_Joy" + (device + 1)); 34 | SendEvent(device, i, value); 35 | } 36 | } 37 | } 38 | 39 | private void SendButtonEvents() 40 | { 41 | 42 | for (int device = 0; device < joystickCount; device++) 43 | { 44 | int first = (int)KeyCode.Joystick1Button0 + device * 20; 45 | int last = (int)KeyCode.Joystick1Button19 + device * 20; 46 | 47 | for (int i = 0; i <= last - first; i++) 48 | { 49 | if (Input.GetKeyDown((KeyCode)(i + first))) 50 | SendEvent(device, axisCount + i, 1.0f); 51 | if (Input.GetKeyUp((KeyCode)(i + first))) 52 | SendEvent(device, axisCount + i, 0.0f); 53 | } 54 | } 55 | } 56 | 57 | private void SendEvent(int deviceIndex, int controlIndex, float value) 58 | { 59 | if (value == m_LastValues[deviceIndex, controlIndex]) 60 | return; 61 | m_LastValues[deviceIndex, controlIndex] = value; 62 | 63 | var inputEvent = InputSystem.CreateEvent(); 64 | inputEvent.deviceType = typeof(Gamepad); 65 | inputEvent.deviceIndex = deviceIndex; 66 | inputEvent.controlIndex = controlIndex; 67 | inputEvent.value = value; 68 | InputSystem.QueueEvent(inputEvent); 69 | } 70 | 71 | #endregion 72 | } 73 | -------------------------------------------------------------------------------- /Input/Core/InputControlProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | public abstract class InputControlProvider 8 | { 9 | public List controlDataList { get { return m_ControlDataList; } } 10 | public InputState state { get { return m_State; } } 11 | 12 | private List m_ControlDataList; 13 | private List m_Controls; 14 | private InputState m_State; 15 | 16 | protected void SetControls(List controls) 17 | { 18 | m_ControlDataList = controls; 19 | m_State = new InputState(this); 20 | m_Controls = new List(controlCount); 21 | for (int i = 0; i < controlCount; i++) 22 | { 23 | Type type = controls[i].controlType; 24 | if (type == null) 25 | type = typeof(InputControl); 26 | InputControl control = (InputControl)Activator.CreateInstance(type, i, m_State); 27 | m_Controls.Add(control); 28 | } 29 | } 30 | 31 | public virtual bool ProcessEvent(InputEvent inputEvent) 32 | { 33 | lastEventTime = inputEvent.time; 34 | return false; 35 | } 36 | 37 | public InputControlData GetControlData(int index) 38 | { 39 | return controlDataList[index]; 40 | } 41 | 42 | public int controlCount 43 | { 44 | get { return controlDataList.Count; } 45 | } 46 | 47 | public InputControl this[int index] 48 | { 49 | get { return m_Controls[index]; } 50 | } 51 | 52 | public InputControl this[string controlName] 53 | { 54 | get 55 | { 56 | for (var i = 0; i < controlDataList.Count; ++ i) 57 | { 58 | if (controlDataList[i].name == controlName) 59 | return this[i]; 60 | } 61 | 62 | throw new KeyNotFoundException(controlName); 63 | } 64 | } 65 | 66 | public virtual string GetPrimarySourceName(int controlIndex, string buttonAxisFormattingString = "{0} & {1}") 67 | { 68 | return this[controlIndex].name; 69 | } 70 | 71 | protected void SetControlNameOverride(int controlIndex, string nameOverride) 72 | { 73 | InputControlData data = controlDataList[controlIndex]; 74 | data.name = nameOverride; 75 | controlDataList[controlIndex] = data; 76 | } 77 | 78 | public float lastEventTime { get; protected set; } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /FakePrototypeStuff/MouseInputToEvents.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.InputNew; 5 | 6 | public class MouseInputToEvents 7 | : MonoBehaviour 8 | { 9 | bool m_Ignore = false; 10 | private bool m_HaveSentResetEvent; 11 | 12 | public void Update() 13 | { 14 | #if !UNITY_IOS && !UNITY_ANDROID 15 | SendButtonEvents(); 16 | SendMoveEvent(); 17 | #endif 18 | } 19 | 20 | void SendButtonEvents() 21 | { 22 | HandleMouseButton(0, PointerControl.LeftButton); 23 | HandleMouseButton(1, PointerControl.RightButton); 24 | HandleMouseButton(2, PointerControl.MiddleButton); 25 | } 26 | 27 | void HandleMouseButton(int buttonIndex, PointerControl buttonEnumValue) 28 | { 29 | if (Input.GetMouseButtonDown(buttonIndex)) 30 | { 31 | if (UnityEngine.EventSystems.EventSystem.current != null && 32 | UnityEngine.Cursor.lockState != CursorLockMode.Locked && 33 | UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject()) 34 | m_Ignore = true; 35 | else 36 | SendClickEvent(buttonEnumValue, true); 37 | } 38 | if (Input.GetMouseButtonUp(buttonIndex)) 39 | { 40 | if (m_Ignore) 41 | m_Ignore = false; 42 | else 43 | SendClickEvent(buttonEnumValue, false); 44 | } 45 | } 46 | 47 | void SendMoveEvent() 48 | { 49 | if (m_Ignore) 50 | return; 51 | 52 | var deltaX = Input.GetAxis("Mouse X"); 53 | var deltaY = Input.GetAxis("Mouse Y"); 54 | 55 | var deltaZero = (deltaX == 0.0f && deltaY == 0.0f); 56 | if (deltaZero && m_HaveSentResetEvent) 57 | return; 58 | 59 | var inputEvent = InputSystem.CreateEvent(); 60 | inputEvent.deviceType = typeof(Mouse); 61 | inputEvent.deviceIndex = 0; 62 | inputEvent.delta = new Vector3(deltaX, deltaY, 0.0f); 63 | inputEvent.position = Input.mousePosition; 64 | 65 | InputSystem.QueueEvent(inputEvent); 66 | 67 | if (deltaZero) 68 | m_HaveSentResetEvent = true; 69 | else 70 | m_HaveSentResetEvent = false; 71 | } 72 | 73 | void SendClickEvent(PointerControl controlIndex, bool clicked) 74 | { 75 | ////REVIEW: should this be a pointer-specific event type? 76 | var inputEvent = InputSystem.CreateEvent(); 77 | inputEvent.deviceType = typeof(Mouse); 78 | inputEvent.deviceIndex = 0; 79 | inputEvent.controlIndex = (int)controlIndex; 80 | inputEvent.value = clicked ? 1.0f : 0.0f; 81 | InputSystem.QueueEvent(inputEvent); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Input/Core.Extensions/JoystickProfile.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using Assets.Utilities; 3 | 4 | namespace UnityEngine.InputNew 5 | { 6 | public class JoystickProfile 7 | : InputDeviceProfile 8 | { 9 | #region Public Properties 10 | 11 | public JoystickControlMapping[] mappings; 12 | public string[] nameOverrides; 13 | 14 | protected static Range defaultDeadZones = new Range(0.2f, 0.9f); 15 | 16 | #endregion 17 | 18 | #region Public Methods 19 | 20 | public override void Remap(InputEvent inputEvent) 21 | { 22 | var controlEvent = inputEvent as GenericControlEvent; 23 | if (controlEvent != null) 24 | { 25 | var mapping = mappings[controlEvent.controlIndex]; 26 | if (mapping.targetIndex != -1) 27 | { 28 | controlEvent.controlIndex = mapping.targetIndex; 29 | controlEvent.value = Mathf.InverseLerp(mapping.fromRange.min, mapping.fromRange.max, controlEvent.value); 30 | controlEvent.value = Mathf.Lerp(mapping.toRange.min, mapping.toRange.max, controlEvent.value); 31 | Range deadZones = mapping.interDeadZoneRange; 32 | controlEvent.value = Mathf.InverseLerp(deadZones.min, deadZones.max, Mathf.Abs(controlEvent.value)) 33 | * Mathf.Sign(controlEvent.value); 34 | } 35 | } 36 | } 37 | 38 | public void SetMappingsCount(int sourceControlCount, int tarcontrolCount) 39 | { 40 | mappings = new JoystickControlMapping[sourceControlCount]; 41 | nameOverrides = new string[tarcontrolCount]; 42 | } 43 | 44 | public void SetMapping(int sourceControlIndex, int targetControlIndex, string displayName) 45 | { 46 | SetMapping(sourceControlIndex, targetControlIndex, displayName, defaultDeadZones, Range.full, Range.full); 47 | } 48 | 49 | public void SetMapping(int sourceControlIndex, int targetControlIndex, string displayName, Range interDeadZoneRange) 50 | { 51 | SetMapping(sourceControlIndex, targetControlIndex, displayName, interDeadZoneRange, Range.full, Range.full); 52 | } 53 | 54 | public void SetMapping(int sourceControlIndex, int targetControlIndex, string displayName, Range interDeadZoneRange, Range sourceRange, Range targetRange) 55 | { 56 | mappings[sourceControlIndex] = new JoystickControlMapping 57 | { 58 | targetIndex = targetControlIndex, 59 | fromRange = sourceRange, 60 | toRange = targetRange, 61 | interDeadZoneRange = interDeadZoneRange 62 | }; 63 | nameOverrides[targetControlIndex] = displayName; 64 | } 65 | 66 | public override string GetControlNameOverride(int controlIndex) 67 | { 68 | if (controlIndex >= nameOverrides.Length) 69 | return null; 70 | return nameOverrides[controlIndex]; 71 | } 72 | 73 | #endregion 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Input/Core/InputDevice.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | public abstract class InputDevice 8 | : InputControlProvider 9 | { 10 | #region Constructors 11 | 12 | protected InputDevice(string deviceName, List controls) 13 | { 14 | SetControls(controls); 15 | this.deviceName = deviceName; 16 | deviceIndex = InputSystem.GetNewDeviceIndex(this); 17 | } 18 | 19 | protected InputDevice() 20 | { 21 | this.deviceName = "Generic Input Device"; 22 | deviceIndex = InputSystem.GetNewDeviceIndex(this); 23 | } 24 | 25 | #endregion 26 | 27 | #region Public Methods 28 | 29 | ////REVIEW: right now the devices don't check whether the event was really meant for them; they go purely by the 30 | //// type of event they receive. should they check more closely? 31 | 32 | public override sealed bool ProcessEvent(InputEvent inputEvent) 33 | { 34 | // If event was used, set time, but never consume event. 35 | // Devices don't consume events. 36 | if (ProcessEventIntoState(inputEvent, state)) 37 | lastEventTime = inputEvent.time; 38 | return false; 39 | } 40 | 41 | public virtual bool ProcessEventIntoState(InputEvent inputEvent, InputState intoState) 42 | { 43 | GenericControlEvent controlEvent = inputEvent as GenericControlEvent; 44 | if (controlEvent == null) 45 | return false; 46 | 47 | return intoState.SetCurrentValue(controlEvent.controlIndex, controlEvent.value); 48 | } 49 | 50 | public virtual bool RemapEvent(InputEvent inputEvent) 51 | { 52 | if (profile != null) 53 | profile.Remap(inputEvent); 54 | return false; 55 | } 56 | 57 | private void SetNameOverrides() 58 | { 59 | if (profile == null) 60 | return; 61 | 62 | // Assign control override names 63 | for (int i = 0; i < controlCount; i++) { 64 | string nameOverride = profile.GetControlNameOverride(i); 65 | if (nameOverride != null) 66 | SetControlNameOverride(i, nameOverride); 67 | } 68 | } 69 | 70 | #endregion 71 | 72 | #region Public Properties 73 | 74 | public bool connected { get; internal set; } 75 | 76 | public InputDeviceProfile profile 77 | { 78 | get { return m_Profile; } set { m_Profile = value; SetNameOverrides(); } 79 | } 80 | 81 | public string deviceName { get; protected set; } 82 | public int deviceIndex { get; private set; } 83 | 84 | public PlayerDeviceAssignment assignment 85 | { 86 | get 87 | { 88 | return m_Assignment; 89 | } 90 | set 91 | { 92 | m_Assignment = value; 93 | } 94 | } 95 | 96 | public override string ToString () 97 | { 98 | return (deviceName ?? GetType().Name) + " " + deviceIndex; 99 | } 100 | 101 | #endregion 102 | 103 | private InputDeviceProfile m_Profile; 104 | private PlayerDeviceAssignment m_Assignment = null; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /Input/Core/InputEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | // ------------------------------------------------------------------------ 8 | // Events. 9 | // ------------------------------------------------------------------------ 10 | 11 | public abstract class InputEvent 12 | { 13 | #region Public Methods 14 | 15 | public override string ToString() 16 | { 17 | if (deviceType == null) 18 | return base.ToString (); 19 | 20 | return string.Format 21 | ( 22 | "{0} on {1}, {2}, time:{3}" 23 | , GetType().Name 24 | , deviceType.Name 25 | , deviceIndex 26 | , time.ToString("0.00") 27 | ); 28 | } 29 | 30 | #endregion 31 | 32 | internal void Reset() 33 | { 34 | time = 0.0f; 35 | deviceType = null; 36 | deviceIndex = 0; 37 | } 38 | 39 | #region Public Properties 40 | 41 | public float time { get; set; } 42 | public Type deviceType 43 | { 44 | get { return m_DeviceType; } 45 | set { m_DeviceType = value; m_CachedDevice = null; } 46 | } 47 | public int deviceIndex 48 | { 49 | get { return m_DeviceIndex; } 50 | set { m_DeviceIndex = value; m_CachedDevice = null; } 51 | } 52 | 53 | public InputDevice device 54 | { 55 | get 56 | { 57 | if (m_CachedDevice == null && deviceType != null) 58 | m_CachedDevice = InputSystem.LookupDevice(deviceType, deviceIndex); 59 | 60 | return m_CachedDevice; 61 | } 62 | set 63 | { 64 | deviceIndex = value.deviceIndex; 65 | deviceType = value.GetType(); 66 | } 67 | } 68 | 69 | #endregion 70 | 71 | private Type m_DeviceType; 72 | private int m_DeviceIndex; 73 | private InputDevice m_CachedDevice; 74 | } 75 | } 76 | 77 | // -------- from old single file thing 78 | 79 | ////REVIEW: we may want to store actual state for compounds such that we can do postprocessing on them (like normalize vectors, for example) 80 | 81 | // ------------------------------------------------------------------------ 82 | // Devices. 83 | // ------------------------------------------------------------------------ 84 | 85 | ////TODO: how deal with compound devices (e.g. gamepads that also have a touchscreen)? 86 | //// create a true CompoundDevice class that is a collection of InputDevices? 87 | 88 | ////FIXME: currently compounds go in the same array as primitives and thus lead to allocation of state which is useless for them 89 | 90 | ////REVIEW: have a single Pointer class representing the union of all types of pointer devices or have multiple specific subclasses? 91 | //// also: where to keep the state for "the one" pointer 92 | 93 | // ------------------------------------------------------------------------ 94 | // Bindings. 95 | // ------------------------------------------------------------------------ 96 | 97 | // Three different naming approaches: 98 | // 1. ActionMap, ActionMapEntry 99 | // 2. InputActionMap, InputAction 100 | // 3. InputActivityMap, InputActivity 101 | 102 | ////NOTE: this needs to be proper asset stuff; can't be done in script code only 103 | 104 | // ------------------------------------------------------------------------ 105 | // System. 106 | // ------------------------------------------------------------------------ 107 | -------------------------------------------------------------------------------- /Input/Core/InputDeviceUtility.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.InputNew; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using System; 6 | using System.Linq; 7 | 8 | namespace UnityEngine.InputNew 9 | { 10 | public static class InputDeviceUtility 11 | { 12 | static Dictionary s_DeviceInstances = new Dictionary(); 13 | static Dictionary s_DeviceControlNames = new Dictionary(); 14 | 15 | static string[] s_DeviceNames = null; 16 | static Type[] s_DeviceTypes = null; 17 | static Dictionary s_IndicesOfDevices = null; 18 | static string[] s_EmptyList = new string[0]; 19 | 20 | public static InputDevice GetDevice(System.Type type) 21 | { 22 | InputDevice device = null; 23 | if (!s_DeviceInstances.TryGetValue(type, out device)) 24 | { 25 | device = (InputDevice)System.Activator.CreateInstance(type); 26 | s_DeviceInstances[type] = device; 27 | } 28 | return device; 29 | } 30 | 31 | public static string GetDeviceName(InputControlDescriptor source) 32 | { 33 | return (Type)source.deviceType == null ? "No-Device" : source.deviceType.Name; 34 | } 35 | 36 | public static string GetDeviceControlName(InputControlDescriptor source) 37 | { 38 | string[] names = GetDeviceControlNames(source.deviceType); 39 | if (source.controlIndex < 0 || source.controlIndex >= names.Length) 40 | return "None"; 41 | return names[source.controlIndex]; 42 | } 43 | 44 | static string GetDeviceControlName(System.Type type, int controlIndex) 45 | { 46 | return GetDeviceControlNames(type)[controlIndex]; 47 | } 48 | 49 | public static string[] GetDeviceControlNames(System.Type type) 50 | { 51 | if (type == null) 52 | return s_EmptyList; 53 | string[] names = null; 54 | if (!s_DeviceControlNames.TryGetValue(type, out names)) 55 | { 56 | InputDevice device = GetDevice(type); 57 | names = new string[device.controlCount]; 58 | for (int i = 0; i < names.Length; i++) 59 | names[i] = device.GetControlData(i).name; 60 | s_DeviceControlNames[type] = names; 61 | } 62 | return names; 63 | } 64 | 65 | static void InitDevices() 66 | { 67 | if (s_DeviceTypes != null) 68 | return; 69 | 70 | s_DeviceTypes = ( 71 | from domainAssembly in AppDomain.CurrentDomain.GetAssemblies() 72 | from assemblyType in domainAssembly.GetExportedTypes() 73 | where assemblyType.IsSubclassOf(typeof(InputDevice)) 74 | select assemblyType 75 | ).OrderBy(e => GetInheritancePath(e)).ToArray(); 76 | 77 | s_DeviceNames = s_DeviceTypes.Select(e => string.Empty.PadLeft(GetInheritanceDepth(e) * 3) + e.Name).ToArray(); 78 | 79 | s_IndicesOfDevices = new Dictionary(); 80 | for (int i = 0; i < s_DeviceTypes.Length; i++) 81 | s_IndicesOfDevices[s_DeviceTypes[i]] = i; 82 | } 83 | 84 | public static string[] GetDeviceNames() 85 | { 86 | InitDevices(); 87 | return s_DeviceNames; 88 | } 89 | 90 | public static int GetDeviceIndex(Type type) 91 | { 92 | InitDevices(); 93 | return (type == null ? -1 : s_IndicesOfDevices[type]); 94 | } 95 | 96 | public static Type GetDeviceType(int index) 97 | { 98 | InitDevices(); 99 | return s_DeviceTypes[index]; 100 | } 101 | 102 | static string GetInheritancePath(Type type) 103 | { 104 | if (type.BaseType == typeof(InputDevice)) 105 | return type.Name; 106 | return GetInheritancePath(type.BaseType) + "/" + type.Name; 107 | } 108 | 109 | static int GetInheritanceDepth(Type type) 110 | { 111 | if (type.BaseType == typeof(InputDevice)) 112 | return 0; 113 | return GetInheritanceDepth(type.BaseType) + 1; 114 | } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /Input/Core/InputControl.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | public class InputControl 8 | { 9 | protected readonly int m_Index; 10 | protected readonly InputState m_State; 11 | 12 | public InputControl(int index, InputState state) 13 | { 14 | m_Index = index; 15 | m_State = state; 16 | } 17 | 18 | public int index 19 | { 20 | get { return m_Index; } 21 | } 22 | 23 | public InputControlProvider provider 24 | { 25 | get { return m_State.controlProvider; } 26 | } 27 | 28 | public bool isEnabled 29 | { 30 | get { return m_State.IsControlEnabled(m_Index); } 31 | } 32 | 33 | public InputControlData data 34 | { 35 | get { return provider.GetControlData(index); } 36 | } 37 | 38 | public string name 39 | { 40 | get { return data.name; } 41 | } 42 | 43 | public string GetPrimarySourceName(string buttonAxisFormattingString = "{0} & {1}") 44 | { 45 | return m_State.controlProvider.GetPrimarySourceName(index, buttonAxisFormattingString); 46 | } 47 | 48 | public float rawValue 49 | { 50 | get { return m_State.GetCurrentValue(m_Index); } 51 | } 52 | 53 | public virtual string[] sourceControlNames { get { return null; } } 54 | } 55 | 56 | [Serializable] 57 | public class AxisAction : ActionSlot {} 58 | public class AxisInputControl : InputControl 59 | { 60 | public readonly ButtonInputControl negative; 61 | public readonly ButtonInputControl positive; 62 | 63 | public AxisInputControl(int index, InputState state) : base(index, state) 64 | { 65 | negative = new ButtonInputControl(index, state); 66 | negative.SetValueMultiplier(-1); 67 | positive = new ButtonInputControl(index, state); 68 | } 69 | 70 | public float value 71 | { 72 | get { return m_State.GetCurrentValue(m_Index); } 73 | } 74 | } 75 | 76 | [Serializable] 77 | public class ButtonAction : ActionSlot {} 78 | public class ButtonInputControl : InputControl 79 | { 80 | private const float k_ButtonThreshold = 0.5f; 81 | private float m_ValueMultiplier = 1; 82 | 83 | public ButtonInputControl(int index, InputState state) : base(index, state) {} 84 | 85 | public bool isHeld 86 | { 87 | get { return m_State.GetCurrentValue(m_Index) * m_ValueMultiplier > k_ButtonThreshold; } 88 | } 89 | 90 | public bool wasJustPressed 91 | { 92 | get { return isHeld && (m_State.GetPreviousValue(m_Index) * m_ValueMultiplier <= k_ButtonThreshold); } 93 | } 94 | 95 | public bool wasJustReleased 96 | { 97 | get { return !isHeld && (m_State.GetPreviousValue(m_Index) * m_ValueMultiplier > k_ButtonThreshold); } 98 | } 99 | 100 | public void SetValueMultiplier(float multiplier) 101 | { 102 | m_ValueMultiplier = multiplier; 103 | } 104 | } 105 | 106 | [Serializable] 107 | public class Vector2Action : ActionSlot {} 108 | public class Vector2InputControl : InputControl 109 | { 110 | public Vector2InputControl(int index, InputState state) : base(index, state) {} 111 | 112 | public Vector2 vector2 113 | { 114 | get 115 | { 116 | var controlData = m_State.controlProvider.GetControlData(m_Index); 117 | return new Vector2( 118 | m_State.GetCurrentValue(controlData.componentControlIndices[0]), 119 | m_State.GetCurrentValue(controlData.componentControlIndices[1]) 120 | ); 121 | } 122 | } 123 | 124 | public override string[] sourceControlNames { get { return new string[] { "X", "Y" }; } } 125 | } 126 | 127 | [Serializable] 128 | public class Vector3Action : ActionSlot {} 129 | public class Vector3InputControl : InputControl 130 | { 131 | public Vector3InputControl(int index, InputState state) : base(index, state) {} 132 | 133 | public Vector3 vector3 134 | { 135 | get 136 | { 137 | var controlData = m_State.controlProvider.GetControlData(m_Index); 138 | return new Vector3( 139 | m_State.GetCurrentValue(controlData.componentControlIndices[0]), 140 | m_State.GetCurrentValue(controlData.componentControlIndices[1]), 141 | m_State.GetCurrentValue(controlData.componentControlIndices[2]) 142 | ); 143 | } 144 | } 145 | 146 | public override string[] sourceControlNames { get { return new string[] { "X", "Y", "Z" }; } } 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /Input/Core/InputState.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | public class InputState 8 | { 9 | #region Constructors 10 | 11 | public InputState(InputControlProvider controlProvider) 12 | : this(controlProvider, null) { } 13 | 14 | public InputState(InputControlProvider controlProvider, List usedControlIndices) 15 | { 16 | this.controlProvider = controlProvider; 17 | 18 | var controlCount = controlProvider.controlCount; 19 | m_CurrentStates = new float[controlCount]; 20 | m_PreviousStates = new float[controlCount]; 21 | m_Enabled = new bool[controlCount]; 22 | 23 | SetUsedControls(usedControlIndices); 24 | } 25 | 26 | public void SetUsedControls(List usedControlIndices) 27 | { 28 | if (usedControlIndices == null) 29 | { 30 | SetAllControlsEnabled(true); 31 | } 32 | else 33 | { 34 | SetAllControlsEnabled(false); 35 | for (var i = 0; i < usedControlIndices.Count; i++) 36 | m_Enabled[usedControlIndices[i]] = true; 37 | } 38 | } 39 | 40 | #endregion 41 | 42 | #region Public Methods 43 | 44 | public float GetCurrentValue(int index) 45 | { 46 | return m_CurrentStates[index]; 47 | } 48 | 49 | public float GetPreviousValue(int index) 50 | { 51 | return m_PreviousStates[index]; 52 | } 53 | 54 | public bool SetCurrentValue(int index, bool value) 55 | { 56 | return SetCurrentValue(index, value ? 1.0f : 0.0f); 57 | } 58 | 59 | public bool SetCurrentValue(int index, float value) 60 | { 61 | if (index < 0 || index >= m_CurrentStates.Length) 62 | throw new ArgumentOutOfRangeException("index", 63 | string.Format("Control index {0} is out of range; state has {1} entries", index, m_CurrentStates.Length)); 64 | 65 | if (!IsControlEnabled(index)) 66 | return false; 67 | 68 | m_CurrentStates[index] = value; 69 | 70 | return true; 71 | } 72 | 73 | public bool IsControlEnabled(int index) 74 | { 75 | return m_Enabled[index]; 76 | } 77 | 78 | public void SetControlEnabled(int index, bool enabled) 79 | { 80 | m_Enabled[index] = enabled; 81 | } 82 | 83 | public void SetAllControlsEnabled(bool enabled) 84 | { 85 | for (var i = 0; i < m_Enabled.Length; ++ i) 86 | { 87 | m_Enabled[i] = enabled; 88 | } 89 | } 90 | 91 | public void InitToDevice() 92 | { 93 | if (controlProvider.state == this) 94 | return; 95 | 96 | float[] referenceStates = controlProvider.state.m_CurrentStates; 97 | for (int i = 0; i < m_CurrentStates.Length; i++) 98 | { 99 | if (m_Enabled[i]) 100 | { 101 | m_CurrentStates[i] = referenceStates[i]; 102 | m_PreviousStates[i] = m_CurrentStates[i]; 103 | } 104 | else 105 | { 106 | ResetStateForControl(i); 107 | } 108 | } 109 | } 110 | 111 | public void Reset() 112 | { 113 | for (int i = 0; i < m_CurrentStates.Length; i++) 114 | ResetStateForControl(i); 115 | } 116 | 117 | public void ResetStateForControl(int controlIndex) 118 | { 119 | float defaultValue = controlProvider.GetControlData(controlIndex).defaultValue; 120 | m_CurrentStates[controlIndex] = defaultValue; 121 | m_PreviousStates[controlIndex] = defaultValue; 122 | } 123 | 124 | #endregion 125 | 126 | #region Non-Public Methods 127 | 128 | internal void BeginFrame() 129 | { 130 | var stateCount = m_Enabled.Length; 131 | for (var index = 0; index < stateCount; ++index) 132 | { 133 | if (!m_Enabled[index]) 134 | continue; 135 | if (m_PreviousStates[index] == m_CurrentStates[index]) 136 | continue; 137 | 138 | if (InputSystem.listeningForBinding) 139 | { 140 | // TODO: Figure out how to use sensible thresholds for different controls. 141 | if (Mathf.Abs(m_CurrentStates[index]) >= 0.5f && Mathf.Abs(m_PreviousStates[index]) < 0.5f) 142 | InputSystem.RegisterBinding(controlProvider[index]); 143 | } 144 | 145 | m_PreviousStates[index] = m_CurrentStates[index]; 146 | } 147 | } 148 | 149 | #endregion 150 | 151 | #region Public Properties 152 | 153 | public InputControlProvider controlProvider { get; set; } 154 | 155 | public int count 156 | { 157 | get { return m_CurrentStates.Length; } 158 | } 159 | 160 | #endregion 161 | 162 | #region Fields 163 | 164 | readonly float[] m_CurrentStates; 165 | readonly float[] m_PreviousStates; 166 | readonly bool[] m_Enabled; 167 | 168 | #endregion 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /Input/Players/PlayerHandle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | public class PlayerHandle : IInputConsumer 8 | { 9 | public readonly int index; 10 | public List assignments = new List(); 11 | public List maps = new List(); 12 | 13 | private bool m_Global = false; 14 | 15 | public delegate void ChangeEvent(); 16 | public static ChangeEvent onChange; 17 | 18 | InputConsumerNode currentInputConsumer 19 | { 20 | get 21 | { 22 | return m_Global ? InputSystem.globalPlayers : InputSystem.assignedPlayers; 23 | } 24 | } 25 | 26 | internal PlayerHandle(int index) 27 | { 28 | this.index = index; 29 | currentInputConsumer.children.Add(this); 30 | 31 | if (onChange != null) 32 | onChange.Invoke(); 33 | } 34 | 35 | public void Destroy() 36 | { 37 | foreach (var map in maps) 38 | map.active = false; 39 | 40 | for (int i = assignments.Count - 1; i >= 0; i--) 41 | assignments[i].Unassign(); 42 | 43 | currentInputConsumer.children.Remove(this); 44 | 45 | PlayerHandleManager.RemovePlayerHandle(this); 46 | if (onChange != null) 47 | onChange.Invoke(); 48 | } 49 | 50 | public bool global 51 | { 52 | get { return m_Global; } 53 | set 54 | { 55 | if (value == m_Global) 56 | return; 57 | 58 | // Note: value of m_Global changes what currentInputConsumer is. 59 | currentInputConsumer.children.Remove(this); 60 | m_Global = value; 61 | currentInputConsumer.children.Add(this); 62 | 63 | if (onChange != null) 64 | onChange.Invoke(); 65 | } 66 | } 67 | 68 | public T GetActions() where T : ActionMapInput 69 | { 70 | // If already contains ActionMapInput if this type, return that. 71 | for (int i = 0; i < maps.Count; i++) 72 | if (maps[i].GetType() == typeof(T)) 73 | return (T)maps[i]; 74 | return null; 75 | } 76 | 77 | public ActionMapInput GetActions(ActionMap actionMap) 78 | { 79 | // If already contains ActionMapInput based on this ActionMap, return that. 80 | for (int i = 0; i < maps.Count; i++) 81 | if (maps[i].actionMap == actionMap) 82 | return maps[i]; 83 | return null; 84 | } 85 | 86 | public bool AssignDevice(InputDevice device, bool assign) 87 | { 88 | if (assign) 89 | { 90 | if (device.assignment != null) 91 | { 92 | // If already assigned to this player, accept as success. Otherwise, fail. 93 | if (device.assignment.player == this) 94 | return true; 95 | else 96 | return false; 97 | } 98 | 99 | var assignment = new PlayerDeviceAssignment(this, device); 100 | assignment.Assign(); 101 | 102 | return true; 103 | } 104 | else 105 | { 106 | if (device.assignment.player == this) 107 | { 108 | device.assignment.Unassign(); 109 | return true; 110 | } 111 | return false; 112 | } 113 | } 114 | 115 | public bool ProcessEvent(InputEvent inputEvent) 116 | { 117 | if (!global && (inputEvent.device.assignment == null || inputEvent.device.assignment.player != this)) 118 | return false; 119 | 120 | for (int i = 0; i < maps.Count; i++) 121 | { 122 | if (maps[i].active) 123 | { 124 | if (ProcessEventInMap(maps[i], inputEvent) || maps[i].blockSubsequent) 125 | return true; 126 | } 127 | } 128 | 129 | return false; 130 | } 131 | 132 | bool ProcessEventInMap(ActionMapInput map, InputEvent inputEvent) 133 | { 134 | if (map.ProcessEvent(inputEvent)) 135 | return true; 136 | 137 | if (map.CurrentlyUsesDevice(inputEvent.device)) 138 | return false; 139 | 140 | if (!map.TryInitializeWithDevices(GetApplicableDevices())) 141 | return false; 142 | 143 | // When changing control scheme, we do not want to init control scheme to device states 144 | // like we normally want, so do a hard reset here, before processing the new event. 145 | map.Reset(false); 146 | 147 | return map.ProcessEvent(inputEvent); 148 | } 149 | 150 | public IEnumerable GetApplicableDevices() 151 | { 152 | if (global) 153 | return InputSystem.devices.Where(e => e.assignment == null); 154 | else 155 | return assignments.Select(e => e.device); 156 | } 157 | 158 | public void BeginFrame() 159 | { 160 | for (int i = 0; i < maps.Count; i++) 161 | { 162 | if (maps[i].active) 163 | maps[i].BeginFrame(); 164 | } 165 | } 166 | 167 | public void EndFrame() 168 | { 169 | for (int i = 0; i < maps.Count; i++) 170 | { 171 | if (maps[i].active) 172 | maps[i].EndFrame(); 173 | } 174 | } 175 | } 176 | 177 | } 178 | -------------------------------------------------------------------------------- /Input/Actions/ActionMap.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Linq; 5 | using UnityEngine; 6 | using UnityEngine.Serialization; 7 | 8 | #if UNITY_EDITOR 9 | using UnityEditor; 10 | #endif 11 | 12 | namespace UnityEngine.InputNew 13 | { 14 | [CreateAssetMenu()] 15 | #if UNITY_EDITOR 16 | [InitializeOnLoad] 17 | #endif 18 | public class ActionMap : ScriptableObject 19 | { 20 | [FormerlySerializedAs("entries")] 21 | [SerializeField] 22 | private List m_Actions = new List(); 23 | public List actions { get { return m_Actions; } set { m_Actions = value; } } 24 | 25 | [SerializeField] 26 | private List m_ControlSchemes = new List(); 27 | private List m_ControlSchemeCopies; // In players or playmode we always hand out copies and retain the originals. 28 | public List controlSchemes 29 | { 30 | get 31 | { 32 | #if UNITY_EDITOR 33 | if (!s_IsInPlayMode) 34 | { 35 | return m_ControlSchemes; // ActionMapEditor modifies this directly. 36 | } 37 | #endif 38 | if (m_ControlSchemeCopies == null || m_ControlSchemeCopies.Count == 0) 39 | { 40 | m_ControlSchemeCopies = m_ControlSchemes.Select(x => x.Clone()).ToList(); 41 | #if UNITY_EDITOR 42 | s_ActionMapsToCleanUpAfterPlayMode.Add(this); 43 | #endif 44 | } 45 | return m_ControlSchemeCopies; 46 | } 47 | 48 | set 49 | { 50 | m_ControlSchemes = value; 51 | m_ControlSchemeCopies = null; 52 | } 53 | } 54 | 55 | // In the editor, throw away all customizations when exiting playmode. 56 | #if UNITY_EDITOR 57 | private static List s_ActionMapsToCleanUpAfterPlayMode = new List(); 58 | private static bool s_IsInPlayMode; 59 | 60 | static ActionMap() 61 | { 62 | HandlePlayModeCustomizations(); 63 | EditorApplication.playmodeStateChanged += HandlePlayModeCustomizations; 64 | } 65 | 66 | private static void HandlePlayModeCustomizations() 67 | { 68 | // TODO: Fix error. 69 | // get_isPlayingOrWillChangePlaymode is not allowed to be called from a MonoBehaviour constructor, 70 | // call it in Awake or Start instead. Called from script 'ActionMap' on game object 'MenuActions'. 71 | // See "Script Serialization" page in the Unity Manual for further details. 72 | if (EditorApplication.isPlayingOrWillChangePlaymode) 73 | { 74 | s_IsInPlayMode = true; 75 | } 76 | else if (!EditorApplication.isPlaying) 77 | { 78 | s_IsInPlayMode = false; 79 | // Throw away all the copies of ControlSchemes we made in play mode. 80 | foreach (var actionMap in s_ActionMapsToCleanUpAfterPlayMode) 81 | { 82 | actionMap.m_ControlSchemeCopies = null; 83 | } 84 | s_ActionMapsToCleanUpAfterPlayMode.Clear(); 85 | } 86 | } 87 | #endif 88 | 89 | public Type mapType 90 | { 91 | get 92 | { 93 | if ( m_CachedMapType == null ) 94 | { 95 | if (m_MapTypeName == null) 96 | return null; 97 | m_CachedMapType = Type.GetType( m_MapTypeName ); 98 | } 99 | return m_CachedMapType; 100 | } 101 | set 102 | { 103 | m_CachedMapType = value; 104 | m_MapTypeName = m_CachedMapType.AssemblyQualifiedName; 105 | } 106 | } 107 | [SerializeField] 108 | private string m_MapTypeName; 109 | private Type m_CachedMapType; 110 | public void SetMapTypeName(string name) 111 | { 112 | m_MapTypeName = name; 113 | } 114 | 115 | public Type customActionMapType { 116 | get 117 | { 118 | string typeString = string.Format( 119 | "{0}, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", 120 | name); 121 | Type t = null; 122 | try 123 | { 124 | t = Type.GetType(typeString); 125 | } 126 | catch (Exception e) 127 | { 128 | throw new Exception("Failed to create type from string \"" + typeString + "\".", e); 129 | } 130 | 131 | if (t == null) 132 | throw new Exception("Failed to create type from string \"" + typeString + "\"."); 133 | 134 | return t; 135 | } 136 | } 137 | 138 | public string GetCustomizations() 139 | { 140 | var customizedControlSchemes = m_ControlSchemeCopies.Where(x => x.customized).ToList(); 141 | return JsonUtility.ToJson(customizedControlSchemes); 142 | } 143 | 144 | public void RevertCustomizations() 145 | { 146 | m_ControlSchemeCopies = null; 147 | } 148 | 149 | public void RevertCustomizations(ControlScheme controlScheme) 150 | { 151 | if (m_ControlSchemeCopies != null) 152 | { 153 | for (var i = 0; i < m_ControlSchemeCopies.Count; ++i) 154 | { 155 | if (m_ControlSchemeCopies[i] == controlScheme) 156 | { 157 | m_ControlSchemeCopies[i] = m_ControlSchemes[i].Clone(); 158 | break; 159 | } 160 | } 161 | } 162 | } 163 | 164 | public void RestoreCustomizations(string customizations) 165 | { 166 | var customizedControlSchemes = JsonUtility.FromJson>(customizations); 167 | foreach (var customizedScheme in customizedControlSchemes) 168 | { 169 | // See if it replaces an existing scheme. 170 | var replacesExisting = false; 171 | for (var i = 0; i < controlSchemes.Count; ++i) 172 | { 173 | if (String.Compare(controlSchemes[i].name, customizedScheme.name, CultureInfo.InvariantCulture, CompareOptions.IgnoreCase) == 0) 174 | { 175 | // Yes, so get rid of current scheme. 176 | controlSchemes[i] = customizedScheme; 177 | replacesExisting = true; 178 | break; 179 | } 180 | } 181 | 182 | if (!replacesExisting) 183 | { 184 | // No, so add as new scheme. 185 | controlSchemes.Add(customizedScheme); 186 | } 187 | } 188 | } 189 | } 190 | } 191 | -------------------------------------------------------------------------------- /Input/Core.Extensions/Pointer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | /// 8 | /// A device that can point at and click on things. 9 | /// 10 | public class Pointer 11 | : InputDevice 12 | { 13 | #region Constructors 14 | 15 | public Pointer() 16 | : this("Pointer", null) { } 17 | 18 | protected Pointer(string deviceName, List additionalControls) 19 | { 20 | this.deviceName = deviceName; 21 | var controls = new List(); 22 | 23 | controls.Add(item: new InputControlData 24 | { 25 | name = "Position" 26 | , controlType = typeof(Vector3InputControl) 27 | , componentControlIndices = new[] { (int)PointerControl.PositionX, (int)PointerControl.PositionY, (int)PointerControl.PositionZ } 28 | }); 29 | 30 | controls.Add(new InputControlData { name = "Position X", controlType = typeof(AxisInputControl) }); 31 | controls.Add(new InputControlData { name = "Position Y", controlType = typeof(AxisInputControl) }); 32 | controls.Add(new InputControlData { name = "Position Z", controlType = typeof(AxisInputControl) }); 33 | 34 | controls.Add(item: new InputControlData 35 | { 36 | name = "Delta" 37 | , controlType = typeof(Vector3InputControl) 38 | , componentControlIndices = new[] { (int)PointerControl.DeltaX, (int)PointerControl.DeltaY, (int)PointerControl.DeltaZ } 39 | }); 40 | 41 | controls.Add(new InputControlData { name = "Delta X", controlType = typeof(AxisInputControl) }); 42 | controls.Add(new InputControlData { name = "Delta Y", controlType = typeof(AxisInputControl) }); 43 | controls.Add(new InputControlData { name = "Delta Z", controlType = typeof(AxisInputControl) }); 44 | controls.Add(item: new InputControlData 45 | { 46 | name = "Locked Delta" 47 | , controlType = typeof(Vector3InputControl) 48 | , componentControlIndices = new[] { (int)PointerControl.LockedDeltaX, (int)PointerControl.LockedDeltaY, (int)PointerControl.LockedDeltaZ } 49 | }); 50 | controls.Add(new InputControlData { name = "Locked Delta X", controlType = typeof(AxisInputControl) }); 51 | controls.Add(new InputControlData { name = "Locked Delta Y", controlType = typeof(AxisInputControl) }); 52 | controls.Add(new InputControlData { name = "Locked Delta Z", controlType = typeof(AxisInputControl) }); 53 | controls.Add(new InputControlData { name = "Pressure", controlType = typeof(AxisInputControl) }); 54 | controls.Add(new InputControlData { name = "Tilt", controlType = typeof(AxisInputControl) }); 55 | controls.Add(new InputControlData { name = "Rotation", controlType = typeof(AxisInputControl) }); 56 | controls.Add(new InputControlData { name = "Left Button", controlType = typeof(ButtonInputControl) }); 57 | controls.Add(new InputControlData { name = "Right Button", controlType = typeof(ButtonInputControl) }); 58 | controls.Add(new InputControlData { name = "Middle Button", controlType = typeof(ButtonInputControl) }); 59 | 60 | if (additionalControls != null) 61 | controls.AddRange(additionalControls); 62 | 63 | SetControls(controls); 64 | } 65 | 66 | #endregion 67 | 68 | #region Public Methods 69 | 70 | public static Pointer current { get { return InputSystem.GetMostRecentlyUsedDevice(); } } 71 | 72 | public override bool ProcessEventIntoState(InputEvent inputEvent, InputState intoState) 73 | { 74 | if (base.ProcessEventIntoState(inputEvent, intoState)) 75 | return true; 76 | 77 | var consumed = false; 78 | 79 | var moveEvent = inputEvent as PointerMoveEvent; 80 | if (moveEvent != null) 81 | { 82 | consumed |= intoState.SetCurrentValue((int)PointerControl.PositionX, moveEvent.position.x); 83 | consumed |= intoState.SetCurrentValue((int)PointerControl.PositionY, moveEvent.position.y); 84 | consumed |= intoState.SetCurrentValue((int)PointerControl.PositionZ, moveEvent.position.z); 85 | 86 | consumed |= intoState.SetCurrentValue((int)PointerControl.DeltaX, moveEvent.delta.x); 87 | consumed |= intoState.SetCurrentValue((int)PointerControl.DeltaY, moveEvent.delta.y); 88 | consumed |= intoState.SetCurrentValue((int)PointerControl.DeltaZ, moveEvent.delta.z); 89 | 90 | if (cursor == null || cursor.isLocked) 91 | { 92 | consumed |= intoState.SetCurrentValue((int)PointerControl.LockedDeltaX, moveEvent.delta.x); 93 | consumed |= intoState.SetCurrentValue((int)PointerControl.LockedDeltaY, moveEvent.delta.y); 94 | consumed |= intoState.SetCurrentValue((int)PointerControl.LockedDeltaZ, moveEvent.delta.z); 95 | } 96 | else 97 | { 98 | intoState.SetCurrentValue((int)PointerControl.LockedDeltaX, 0.0f); 99 | intoState.SetCurrentValue((int)PointerControl.LockedDeltaY, 0.0f); 100 | intoState.SetCurrentValue((int)PointerControl.LockedDeltaZ, 0.0f); 101 | } 102 | 103 | return consumed; 104 | } 105 | 106 | var clickEvent = inputEvent as GenericControlEvent; 107 | if (clickEvent != null) 108 | { 109 | switch ((PointerControl)clickEvent.controlIndex) 110 | { 111 | case PointerControl.LeftButton: 112 | consumed |= intoState.SetCurrentValue((int)PointerControl.LeftButton, clickEvent.value); 113 | break; 114 | case PointerControl.MiddleButton: 115 | consumed |= intoState.SetCurrentValue((int)PointerControl.MiddleButton, clickEvent.value); 116 | break; 117 | case PointerControl.RightButton: 118 | consumed |= intoState.SetCurrentValue((int)PointerControl.RightButton, clickEvent.value); 119 | break; 120 | } 121 | 122 | return consumed; 123 | } 124 | 125 | return false; 126 | } 127 | 128 | #endregion 129 | 130 | #region Public Properties 131 | 132 | public Vector3 position 133 | { 134 | get { return ((Vector3InputControl)this[(int)PointerControl.Position]).vector3; } 135 | } 136 | 137 | public float pressure 138 | { 139 | get { return ((AxisInputControl)this[(int)PointerControl.Pressure]).value; } 140 | } 141 | 142 | ////REVIEW: okay, maybe the concept of a per-pointer cursor is bogus after all... 143 | public Cursor cursor { get; protected set; } 144 | 145 | #endregion 146 | } 147 | 148 | } 149 | -------------------------------------------------------------------------------- /Input/Core/InputSystem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | //// - solve mapping of device type names from control maps to device types at runtime 6 | 7 | namespace UnityEngine.InputNew 8 | { 9 | public static class InputSystem 10 | { 11 | // For now, initialize prototype stuff here. 12 | // This should not be included here in final code. 13 | static InputSystem() 14 | { 15 | s_Devices = new InputDeviceManager(); 16 | 17 | GameObject go = new GameObject("Input Prototype Controller"); 18 | go.hideFlags = HideFlags.HideAndDontSave; 19 | 20 | go.AddComponent(); 21 | go.AddComponent(); 22 | go.AddComponent(); 23 | go.AddComponent(); 24 | go.AddComponent(); 25 | go.AddComponent(); 26 | go.AddComponent(); 27 | 28 | InputDeviceProfile[] profiles = new InputDeviceProfile[] 29 | { 30 | new Xbox360MacProfile(), 31 | new Xbox360WinProfile() 32 | }; 33 | s_EventQueue = new InputEventQueue(); 34 | s_EventPool = new InputEventPool(); 35 | 36 | foreach (var profile in profiles) 37 | { 38 | RegisterProfile(profile); 39 | } 40 | 41 | s_Devices.InitAfterProfiles(); 42 | 43 | // Set up event tree. 44 | s_EventTree = new InputConsumerNode(); 45 | 46 | s_EventTree.children.Add(new InputConsumerCallback { processEvent = s_Devices.RemapEvent }); 47 | 48 | rewriters = new InputConsumerNode(); 49 | s_EventTree.children.Add(rewriters); 50 | 51 | s_EventTree.children.Add(s_Devices); 52 | 53 | consumers = new InputConsumerNode(); 54 | s_EventTree.children.Add(consumers); 55 | 56 | assignedPlayers = new InputConsumerNode(); 57 | consumers.children.Add(assignedPlayers); 58 | 59 | // Global consumers should be processed last. 60 | globalPlayers = new InputConsumerNode(); 61 | consumers.children.Add(globalPlayers); 62 | 63 | simulateMouseWithTouches = true; 64 | } 65 | 66 | public delegate bool BindingListener(InputControl control); 67 | 68 | #region Public Methods 69 | 70 | public static void RegisterProfile(InputDeviceProfile profile) 71 | { 72 | s_Devices.RegisterProfile(profile); 73 | } 74 | 75 | public static InputDevice LookupDevice(Type deviceType, int deviceIndex) 76 | { 77 | return s_Devices.LookupDevice(deviceType, deviceIndex); 78 | } 79 | 80 | public static void QueueEvent(InputEvent inputEvent) 81 | { 82 | s_EventQueue.Queue(inputEvent); 83 | } 84 | 85 | public static bool ExecuteEvent(InputEvent inputEvent) 86 | { 87 | var wasConsumed = s_EventTree.ProcessEvent(inputEvent); 88 | s_EventPool.Return(inputEvent); 89 | return wasConsumed; 90 | } 91 | 92 | public static TEvent CreateEvent() 93 | where TEvent : InputEvent, new() 94 | { 95 | var newEvent = s_EventPool.ReuseOrCreate(); 96 | newEvent.time = Time.time; 97 | return newEvent; 98 | } 99 | 100 | public static void ListenForBinding (BindingListener listener) 101 | { 102 | s_BindingListeners.Add(listener); 103 | } 104 | 105 | #endregion 106 | 107 | #region Non-Public Methods 108 | 109 | internal static void ExecuteEvents() 110 | { 111 | var currentTime = Time.time; 112 | InputEvent nextEvent; 113 | while (s_EventQueue.Dequeue(currentTime, out nextEvent)) 114 | { 115 | ExecuteEvent(nextEvent); 116 | } 117 | } 118 | 119 | internal static void BeginFrame() 120 | { 121 | s_EventTree.BeginFrame(); 122 | } 123 | 124 | internal static void EndFrame() 125 | { 126 | s_EventTree.EndFrame(); 127 | } 128 | 129 | private static bool SendSimulatedMouseEvents(InputEvent inputEvent) 130 | { 131 | ////FIXME: should take actual touchdevice in inputEvent into account 132 | var touchEvent = inputEvent as TouchEvent; 133 | if (touchEvent != null) 134 | Touchscreen.current.SendSimulatedPointerEvents(touchEvent, UnityEngine.Cursor.lockState == CursorLockMode.Locked); 135 | return false; 136 | } 137 | 138 | internal static void RegisterBinding(InputControl control) 139 | { 140 | for (int i = s_BindingListeners.Count - 1; i >= 0; i--) 141 | { 142 | if (s_BindingListeners[i] == null) 143 | { 144 | s_BindingListeners.RemoveAt(i); 145 | continue; 146 | } 147 | bool used = s_BindingListeners[i](control); 148 | if (used) 149 | { 150 | s_BindingListeners.RemoveAt(i); 151 | break; 152 | } 153 | } 154 | } 155 | 156 | #endregion 157 | 158 | #region Public Properties 159 | 160 | public static IInputConsumer eventTree 161 | { 162 | get { return s_EventTree; } 163 | } 164 | 165 | public static InputConsumerNode consumers { get; private set; } 166 | public static InputConsumerNode globalPlayers { get; private set; } 167 | public static InputConsumerNode assignedPlayers { get; private set; } 168 | public static InputConsumerNode rewriters { get; private set; } 169 | 170 | public static bool listeningForBinding 171 | { 172 | get { return s_BindingListeners.Count > 0; } 173 | } 174 | 175 | public static List devices 176 | { 177 | get { return s_Devices.devices; } 178 | } 179 | 180 | public static TDevice GetMostRecentlyUsedDevice() 181 | where TDevice : InputDevice 182 | { 183 | return s_Devices.GetMostRecentlyUsedDevice(); 184 | } 185 | 186 | internal static int GetNewDeviceIndex(InputDevice device) 187 | { 188 | return s_Devices.GetNewDeviceIndex(device); 189 | } 190 | 191 | public static bool simulateMouseWithTouches 192 | { 193 | get { return s_SimulateMouseWithTouches; } 194 | set 195 | { 196 | if (value == s_SimulateMouseWithTouches) 197 | return; 198 | 199 | if (value) 200 | { 201 | if (s_SimulateMouseWithTouchesProcess == null) 202 | s_SimulateMouseWithTouchesProcess = new InputConsumerCallback 203 | { 204 | processEvent = SendSimulatedMouseEvents 205 | }; 206 | 207 | rewriters.children.Add(s_SimulateMouseWithTouchesProcess); 208 | } 209 | else 210 | { 211 | if (s_SimulateMouseWithTouchesProcess != null) 212 | rewriters.children.Remove(s_SimulateMouseWithTouchesProcess); 213 | } 214 | 215 | s_SimulateMouseWithTouches = value; 216 | } 217 | } 218 | 219 | #endregion 220 | 221 | #region Fields 222 | 223 | static InputDeviceManager s_Devices; 224 | static InputEventQueue s_EventQueue; 225 | static InputEventPool s_EventPool; 226 | static InputConsumerNode s_EventTree; 227 | static bool s_SimulateMouseWithTouches; 228 | static IInputConsumer s_SimulateMouseWithTouchesProcess; 229 | static List s_BindingListeners = new List(); 230 | 231 | #endregion 232 | } 233 | } 234 | -------------------------------------------------------------------------------- /Input/Core.Extensions/VirtualJoystick.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using Assets.Utilities; 5 | using UnityEngine; 6 | 7 | namespace UnityEngine.InputNew 8 | { 9 | public class VirtualJoystick 10 | : Joystick 11 | { 12 | public enum VirtualJoystickControl 13 | { 14 | // Standardized. 15 | 16 | LeftStickX, 17 | LeftStickY, 18 | 19 | RightStickX, 20 | RightStickY, 21 | 22 | Action1, 23 | Action2, 24 | Action3, 25 | Action4, 26 | 27 | // Compound controls. 28 | 29 | LeftStick, 30 | RightStick, 31 | 32 | // Not standardized, but provided for convenience. 33 | 34 | Back, 35 | Start, 36 | Select, 37 | Pause, 38 | Menu, 39 | Share, 40 | View, 41 | Options 42 | } 43 | 44 | #region Constructors 45 | 46 | public VirtualJoystick() 47 | : this("Virtual Joystick", null) { } 48 | 49 | public VirtualJoystick(string deviceName, List additionalControls) 50 | { 51 | this.deviceName = deviceName; 52 | var controlCount = EnumHelpers.GetValueCount(); 53 | var controls = new List(controlCount); 54 | for (int i = 0; i < controlCount; i++) 55 | controls.Add(new InputControlData()); 56 | 57 | // Compounds. 58 | controls[(int)VirtualJoystickControl.LeftStick] = new InputControlData 59 | { 60 | name = "Left Stick" 61 | , controlType = typeof(Vector2InputControl) 62 | , componentControlIndices = new[] { (int)VirtualJoystickControl.LeftStickX, (int)VirtualJoystickControl.LeftStickY } 63 | }; 64 | controls[(int)VirtualJoystickControl.RightStick] = new InputControlData 65 | { 66 | name = "Right Stick" 67 | , controlType = typeof(Vector2InputControl) 68 | , componentControlIndices = new[] { (int)VirtualJoystickControl.RightStickX, (int)VirtualJoystickControl.RightStickY } 69 | }; 70 | 71 | // Axes. 72 | controls[(int)VirtualJoystickControl.LeftStickX] = new InputControlData { name = "Left Stick X", controlType = typeof(AxisInputControl) }; 73 | controls[(int)VirtualJoystickControl.LeftStickY] = new InputControlData { name = "Left Stick Y", controlType = typeof(AxisInputControl) }; 74 | controls[(int)VirtualJoystickControl.RightStickX] = new InputControlData { name = "Right Stick X", controlType = typeof(AxisInputControl) }; 75 | controls[(int)VirtualJoystickControl.RightStickY] = new InputControlData { name = "Right Stick Y", controlType = typeof(AxisInputControl) }; 76 | 77 | // Buttons. 78 | controls[(int)VirtualJoystickControl.Action1] = new InputControlData { name = "Action 1", controlType = typeof(ButtonInputControl) }; 79 | controls[(int)VirtualJoystickControl.Action2] = new InputControlData { name = "Action 2", controlType = typeof(ButtonInputControl) }; 80 | controls[(int)VirtualJoystickControl.Action3] = new InputControlData { name = "Action 3", controlType = typeof(ButtonInputControl) }; 81 | controls[(int)VirtualJoystickControl.Action4] = new InputControlData { name = "Action 4", controlType = typeof(ButtonInputControl) }; 82 | 83 | controls[(int)VirtualJoystickControl.Back] = new InputControlData { name = "Back", controlType = typeof(ButtonInputControl) }; 84 | controls[(int)VirtualJoystickControl.Start] = new InputControlData { name = "Start", controlType = typeof(ButtonInputControl) }; 85 | controls[(int)VirtualJoystickControl.Select] = new InputControlData { name = "Select", controlType = typeof(ButtonInputControl) }; 86 | controls[(int)VirtualJoystickControl.Pause] = new InputControlData { name = "Pause", controlType = typeof(ButtonInputControl) }; 87 | controls[(int)VirtualJoystickControl.Menu] = new InputControlData { name = "Menu", controlType = typeof(ButtonInputControl) }; 88 | controls[(int)VirtualJoystickControl.Share] = new InputControlData { name = "Share", controlType = typeof(ButtonInputControl) }; 89 | controls[(int)VirtualJoystickControl.View] = new InputControlData { name = "View", controlType = typeof(ButtonInputControl) }; 90 | controls[(int)VirtualJoystickControl.Options] = new InputControlData { name = "Options", controlType = typeof(ButtonInputControl) }; 91 | 92 | if (additionalControls != null) 93 | controls.AddRange(additionalControls); 94 | 95 | SetControls(controls); 96 | } 97 | 98 | #endregion 99 | 100 | public static VirtualJoystick current { get { return InputSystem.GetMostRecentlyUsedDevice(); } } 101 | 102 | public void SetAxisValue(int controlIndex, float value) 103 | { 104 | var control = this[controlIndex] as InputControl; 105 | if (control == null) 106 | return; 107 | float currentValue = control.rawValue; 108 | if (value == currentValue) 109 | return; 110 | 111 | var inputEvent = InputSystem.CreateEvent(); 112 | inputEvent.deviceType = typeof(VirtualJoystick); 113 | inputEvent.deviceIndex = 0; // TODO: Use index of device itself, but that's not currently stored on device. 114 | inputEvent.controlIndex = controlIndex; 115 | inputEvent.value = value; 116 | InputSystem.QueueEvent(inputEvent); 117 | } 118 | 119 | public void SetButtonValue(int controlIndex, bool state) 120 | { 121 | SetAxisValue(controlIndex, state ? 1 : 0); 122 | } 123 | 124 | public InputControl leftStickX { get { return this[(int)VirtualJoystickControl.LeftStickX]; } } 125 | public InputControl leftStickY { get { return this[(int)VirtualJoystickControl.LeftStickY]; } } 126 | 127 | public InputControl rightStickX { get { return this[(int)VirtualJoystickControl.RightStickX]; } } 128 | public InputControl rightStickY { get { return this[(int)VirtualJoystickControl.RightStickY]; } } 129 | 130 | public InputControl action1 { get { return this[(int)VirtualJoystickControl.Action1]; } } 131 | public InputControl action2 { get { return this[(int)VirtualJoystickControl.Action2]; } } 132 | public InputControl action3 { get { return this[(int)VirtualJoystickControl.Action3]; } } 133 | public InputControl action4 { get { return this[(int)VirtualJoystickControl.Action4]; } } 134 | 135 | // Compound controls. 136 | 137 | public InputControl leftStick { get { return this[(int)VirtualJoystickControl.LeftStick]; } } 138 | public InputControl rightStick { get { return this[(int)VirtualJoystickControl.RightStick]; } } 139 | 140 | // Not standardized, but provided for convenience. 141 | 142 | public InputControl back { get { return this[(int)VirtualJoystickControl.Back]; } } 143 | public InputControl start { get { return this[(int)VirtualJoystickControl.Start]; } } 144 | public InputControl select { get { return this[(int)VirtualJoystickControl.Select]; } } 145 | public InputControl pause { get { return this[(int)VirtualJoystickControl.Pause]; } } 146 | public InputControl menu { get { return this[(int)VirtualJoystickControl.Menu]; } } 147 | public InputControl share { get { return this[(int)VirtualJoystickControl.Share]; } } 148 | public InputControl view { get { return this[(int)VirtualJoystickControl.View]; } } 149 | public InputControl options { get { return this[(int)VirtualJoystickControl.Options]; } } 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /Input/Core/InputDeviceManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UnityEngine.InputNew 6 | { 7 | class InputDeviceManager : IInputConsumer 8 | { 9 | #region Inner Types 10 | 11 | public delegate void DeviceConnectDisconnectEvent(InputDevice device, bool connected); 12 | 13 | #endregion 14 | 15 | #region Public Events 16 | 17 | public DeviceConnectDisconnectEvent deviceConnectedDisconnected = null; 18 | 19 | #endregion 20 | 21 | #region Constructors 22 | 23 | public InputDeviceManager() 24 | { 25 | } 26 | 27 | public void InitAfterProfiles() 28 | { 29 | // In the prototype, just create a set of default devices. In the real thing, these would be registered 30 | // and configured by the platform layer according to what's really available on the system. 31 | 32 | var mouseDevice = new Mouse(); 33 | RegisterDevice(mouseDevice); 34 | 35 | var touchscreenDevice = new Touchscreen(); 36 | RegisterDevice(touchscreenDevice); // Register after mouse; multiplayer code will pick the first applicable device. It doesn't use MRU. 37 | 38 | var keyboardDevice = new Keyboard(); 39 | RegisterDevice(keyboardDevice); 40 | 41 | var gamepadDevice1 = new Gamepad(); 42 | RegisterDevice(gamepadDevice1); 43 | 44 | var gamepadDevice2 = new Gamepad(); 45 | RegisterDevice(gamepadDevice2); 46 | 47 | var virtualJoystickDevice = new VirtualJoystick(); 48 | RegisterDevice(virtualJoystickDevice); 49 | } 50 | 51 | #endregion 52 | 53 | #region Public Methods 54 | 55 | public void RegisterDevice(InputDevice device) 56 | { 57 | AssignDeviceProfile(device); 58 | RegisterDeviceInternal(device.GetType(), device); 59 | HandleDeviceConnectDisconnect(device, true); 60 | } 61 | 62 | public void RegisterProfile(InputDeviceProfile profile) 63 | { 64 | m_Profiles.Add(profile); 65 | } 66 | 67 | public InputDevice GetMostRecentlyUsedDevice(Type deviceType) 68 | { 69 | InputDevice mostRecentDevice = null; 70 | for (var i = m_Devices.Count - 1; i >= 0; -- i) 71 | { 72 | var device = m_Devices[i]; 73 | if (deviceType.IsInstanceOfType(device) && (mostRecentDevice == null || device.lastEventTime > mostRecentDevice.lastEventTime)) 74 | mostRecentDevice = device; 75 | } 76 | return mostRecentDevice; 77 | } 78 | 79 | public TDevice GetMostRecentlyUsedDevice() 80 | where TDevice : InputDevice 81 | { 82 | return (TDevice)GetMostRecentlyUsedDevice(typeof(TDevice)); 83 | } 84 | 85 | internal int GetNewDeviceIndex(InputDevice device) 86 | { 87 | Type t = device.GetType(); 88 | int count = 0; 89 | for (int i = 0; i < devices.Count; i++) 90 | if (devices[i].GetType() == t) 91 | count++; 92 | return count; 93 | } 94 | 95 | public InputDevice LookupDevice(Type deviceType, int deviceIndex) 96 | { 97 | List list; 98 | if (!m_DevicesByType.TryGetValue(deviceType, out list) || deviceIndex >= list.Count) 99 | return null; 100 | 101 | return list[deviceIndex]; 102 | } 103 | 104 | ////REVIEW: an alternative to these two methods is to hook every single device into the event tree independently; may be better 105 | 106 | public bool ProcessEvent(InputEvent inputEvent) 107 | { 108 | // Look up device. 109 | var device = inputEvent.device; 110 | 111 | // Ignore event on device if device is absent or disconnected. 112 | if (device == null || !device.connected) 113 | return false; 114 | 115 | //fire event 116 | 117 | // Let device process event. 118 | return device.ProcessEvent(inputEvent); 119 | } 120 | 121 | public void BeginFrame() 122 | { 123 | foreach (var device in devices) 124 | device.state.BeginFrame(); 125 | } 126 | 127 | public void EndFrame() 128 | { 129 | 130 | } 131 | 132 | public bool RemapEvent(InputEvent inputEvent) 133 | { 134 | // Look up device. 135 | var device = inputEvent.device; 136 | if (device == null) 137 | return false; 138 | 139 | // Let device remap event. 140 | return device.RemapEvent(inputEvent); 141 | } 142 | 143 | public void DisconnectDevice(InputDevice device) 144 | { 145 | if (!device.connected) 146 | return; 147 | 148 | HandleDeviceConnectDisconnect(device, false); 149 | } 150 | 151 | public void ReconnectDevice(InputDevice device) 152 | { 153 | if (device.connected) 154 | return; 155 | 156 | HandleDeviceConnectDisconnect(device, true); 157 | } 158 | 159 | #endregion 160 | 161 | #region Non-Public Methods 162 | 163 | void AssignDeviceProfile(InputDevice device) 164 | { 165 | device.profile = FindDeviceProfile(device); 166 | } 167 | 168 | InputDeviceProfile FindDeviceProfile(InputDevice device) 169 | { 170 | foreach (var profile in m_Profiles) 171 | { 172 | if (profile.deviceNames != null) 173 | { 174 | foreach (var deviceName in profile.deviceNames) 175 | { 176 | if (string.Compare(deviceName, device.deviceName, StringComparison.InvariantCulture) == 0 && 177 | IsProfileSupportedOnThisPlatform(profile)) 178 | return profile; 179 | } 180 | } 181 | } 182 | return null; 183 | } 184 | 185 | public bool IsProfileSupportedOnThisPlatform(InputDeviceProfile profile) 186 | { 187 | if (profile.supportedPlatforms == null || profile.supportedPlatforms.Length == 0) 188 | return true; 189 | 190 | foreach (var platform in profile.supportedPlatforms) 191 | { 192 | if (m_Platform.Contains(platform.ToUpper())) 193 | return true; 194 | } 195 | 196 | return false; 197 | } 198 | 199 | void RegisterDeviceInternal(Type deviceType, InputDevice device) 200 | { 201 | List list; 202 | if (!m_DevicesByType.TryGetValue(deviceType, out list)) 203 | { 204 | list = new List(); 205 | m_DevicesByType[deviceType] = list; 206 | } 207 | 208 | list.Add(device); 209 | // Called recorsively for base types so remove first to make sure it's only added once. 210 | m_Devices.Remove(device); 211 | m_Devices.Add(device); 212 | 213 | var baseType = deviceType.BaseType; 214 | if (baseType != typeof(InputDevice)) 215 | RegisterDeviceInternal(baseType, device); 216 | } 217 | 218 | void HandleDeviceConnectDisconnect(InputDevice device, bool connected) 219 | { 220 | // Sync state. 221 | device.connected = connected; 222 | 223 | // Fire event. 224 | var handler = deviceConnectedDisconnected; 225 | if (handler != null) 226 | handler(device, connected); 227 | } 228 | 229 | #endregion 230 | 231 | #region Public Properties 232 | 233 | public List devices 234 | { 235 | get { return m_Devices; } 236 | } 237 | 238 | #endregion 239 | 240 | #region Fields 241 | 242 | readonly Dictionary> m_DevicesByType = new Dictionary>(); 243 | readonly List m_Devices = new List(); 244 | readonly List m_Profiles = new List(); 245 | readonly string m_Platform = (SystemInfo.operatingSystem + " " + SystemInfo.deviceModel).ToUpper(); 246 | 247 | #endregion 248 | } 249 | } 250 | -------------------------------------------------------------------------------- /Input/Core.Extensions/Touchscreen.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | ////REVIEW: should there be PointerMoveEvents for touches? 6 | 7 | // So the concept of the button simulation goes like this: 8 | // - If you put down one finger and quickly release it without moving much, it's a left clickl 9 | 10 | namespace UnityEngine.InputNew 11 | { 12 | public class Touchscreen 13 | : Pointer 14 | { 15 | #region Constructors 16 | 17 | public Touchscreen() 18 | : this("Touchscreen", null) { } 19 | 20 | protected Touchscreen(string deviceName, List additionalControls) 21 | : base(deviceName, null) 22 | { 23 | var controls = this.controlDataList; 24 | 25 | for (var i = 0; i < MaxConcurrentTouches; ++i) 26 | AddControlsForTouch(i, controls); 27 | 28 | if (additionalControls != null) 29 | controls.AddRange(additionalControls); 30 | 31 | SetControls(controls); 32 | } 33 | 34 | #endregion 35 | 36 | #region Public Methods 37 | 38 | public new static Touchscreen current { get { return InputSystem.GetMostRecentlyUsedDevice(); } } 39 | 40 | public void SendSimulatedPointerEvents(TouchEvent touchEvent, bool cursorLocked) 41 | { 42 | if (cursorLocked) 43 | SimulateLockedMouseInput(touchEvent); 44 | else 45 | SimulateUnlockedMouseInput(touchEvent); 46 | } 47 | 48 | public override bool ProcessEventIntoState(InputEvent inputEvent, InputState intoState) 49 | { 50 | var consumed = false; 51 | 52 | var touchEvent = inputEvent as TouchEvent; 53 | if (touchEvent != null) 54 | { 55 | consumed |= intoState.SetCurrentValue((int)GetControlForFinger(touchEvent.touch.fingerId, TouchControl.Touch0PositionX), touchEvent.touch.position.x); 56 | consumed |= intoState.SetCurrentValue((int)GetControlForFinger(touchEvent.touch.fingerId, TouchControl.Touch0PositionY), touchEvent.touch.position.y); 57 | consumed |= intoState.SetCurrentValue((int)GetControlForFinger(touchEvent.touch.fingerId, TouchControl.Touch0DeltaX), touchEvent.touch.delta.x); 58 | consumed |= intoState.SetCurrentValue((int)GetControlForFinger(touchEvent.touch.fingerId, TouchControl.Touch0DeltaY), touchEvent.touch.delta.y); 59 | 60 | // Store complete touch state for finger. 61 | var touchIndex = GetTouchIndexForFinger(touchEvent.touch.fingerId); 62 | m_Touches[touchIndex] = touchEvent.touch; 63 | } 64 | 65 | if (consumed) 66 | return true; 67 | 68 | return base.ProcessEventIntoState(inputEvent, intoState); 69 | } 70 | 71 | #endregion 72 | 73 | #region Non-Public Methods 74 | 75 | private static void AddControlsForTouch(int index, List controls) 76 | { 77 | var prefix = "Touch" + index; 78 | 79 | var positionIndex = controls.Count; 80 | controls.Add(new InputControlData 81 | { 82 | name = prefix + "Position" 83 | , componentControlIndices = new[] { positionIndex + 1, positionIndex + 2 } 84 | }); 85 | controls.Add(new InputControlData 86 | { 87 | name = prefix + "PositionX" 88 | , controlType = typeof(AxisInputControl) 89 | }); 90 | controls.Add(new InputControlData 91 | { 92 | name = prefix + "PositionY" 93 | , controlType = typeof(AxisInputControl) 94 | }); 95 | 96 | var deltaIndex = controls.Count; 97 | controls.Add(new InputControlData 98 | { 99 | name = prefix + "Delta" 100 | , componentControlIndices = new[] { deltaIndex + 1, deltaIndex + 2 } 101 | }); 102 | controls.Add(new InputControlData 103 | { 104 | name = prefix + "DeltaX" 105 | , controlType = typeof(AxisInputControl) 106 | }); 107 | controls.Add(new InputControlData 108 | { 109 | name = prefix + "DeltaY" 110 | , controlType = typeof(AxisInputControl) 111 | }); 112 | } 113 | 114 | private static TouchControl GetControlForFinger(int fingerId, TouchControl control) 115 | { 116 | return (int)control - (int)TouchControl.Touch0Position 117 | + (fingerId * TouchControlConstants.ControlsPerTouch) 118 | + TouchControl.Touch0Position; 119 | } 120 | 121 | private int GetTouchIndexForFinger(int fingerId) 122 | { 123 | for (var i = 0; i < m_Touches.Count; ++i) 124 | if (m_Touches[i].fingerId == fingerId) 125 | return i; 126 | 127 | m_Touches.Add(new Touch()); 128 | return m_Touches.Count - 1; 129 | } 130 | 131 | ////TODO: move the entire simulation logic outside of Touchscreen entirely 132 | 133 | private void SimulateUnlockedMouseInput(TouchEvent touchEvent) 134 | { 135 | ////TODO: perform simulation like in SimulateInputEvents.cpp 136 | } 137 | 138 | private void SimulateLockedMouseInput(TouchEvent touchEvent) 139 | { 140 | // If we currently don't have a pointer finger and this is a finger-down event, 141 | // make the finger the current pointer. 142 | if (!m_CurrentPointerTouch.isValid && touchEvent.touch.phase == TouchPhase.Began) 143 | m_CurrentPointerTouch = touchEvent.touch; 144 | 145 | ////TODO: set pointer button state from touches 146 | 147 | // If the finger is the current pointer, update the pointer state. 148 | if (m_CurrentPointerTouch.fingerId == touchEvent.touch.fingerId) 149 | { 150 | SendPointerMoveEvent(touchEvent.touch.position, touchEvent.touch.delta, touchEvent.time); 151 | 152 | // If a pointer touch ends, update our state and detect clicks. 153 | if (touchEvent.touch.phase == TouchPhase.Ended) 154 | { 155 | // If touch hasn't moved significantly while down, it's a click. 156 | // If slow-click, it's a right-click; if fast-click, it's a left-click. 157 | var deltaToFirstTouchPoint = m_CurrentPointerTouch.position - touchEvent.touch.position; 158 | if (Mathf.Abs(deltaToFirstTouchPoint.x) < 2 && ////TODO: this should probably be configurable 159 | Mathf.Abs(deltaToFirstTouchPoint.y) < 2) 160 | { 161 | var clickDuration = touchEvent.time - m_CurrentPointerTouch.time; 162 | if (clickDuration <= 0.9f) ////TODO: should be configurable 163 | { 164 | SendPointerClickEvent(PointerControl.LeftButton, true, m_CurrentPointerTouch.time); 165 | SendPointerClickEvent(PointerControl.LeftButton, false, touchEvent.time); 166 | } 167 | } 168 | 169 | m_CurrentPointerTouch = new Touch(); 170 | } 171 | } 172 | 173 | ////TODO: right button keyed to third finger 174 | 175 | // If pointing with one finger and second finger goes down or up, handle 176 | // left-click. 177 | if (m_CurrentPointerTouch.isValid && !m_FirstClickTouch.isValid) 178 | { 179 | if (touchEvent.touch.phase == TouchPhase.Began) 180 | { 181 | m_FirstClickTouch = touchEvent.touch; 182 | SendPointerClickEvent(PointerControl.LeftButton, true, touchEvent.time); 183 | } 184 | else if (touchEvent.touch.phase == TouchPhase.Ended) 185 | { 186 | SendPointerClickEvent(PointerControl.LeftButton, false, touchEvent.time); 187 | m_FirstClickTouch = new Touch(); 188 | } 189 | } 190 | } 191 | 192 | private void SendPointerMoveEvent(Vector3 position, Vector3 delta, float time) 193 | { 194 | var inputEvent = InputSystem.CreateEvent(); 195 | inputEvent.time = time; 196 | inputEvent.deviceType = typeof(Touchscreen); 197 | inputEvent.deviceIndex = 0; ////FIXME: must be right index for us 198 | inputEvent.position = position; 199 | inputEvent.delta = delta; 200 | InputSystem.QueueEvent(inputEvent); 201 | } 202 | 203 | private void SendPointerClickEvent(PointerControl controlIndex, bool clicked, float time) 204 | { 205 | var inputEvent = InputSystem.CreateEvent(); 206 | inputEvent.time = time; 207 | inputEvent.deviceType = typeof(Touchscreen); 208 | inputEvent.deviceIndex = 0; ////FIXME: must be right index for us 209 | inputEvent.controlIndex = (int)controlIndex; 210 | inputEvent.value = clicked ? 1.0f : 0.0f; 211 | InputSystem.QueueEvent(inputEvent); 212 | } 213 | 214 | #endregion 215 | 216 | #region Public Properties 217 | 218 | ////REVIEW: this needs to be readonly, really 219 | public List touches 220 | { 221 | get { return m_Touches; } 222 | } 223 | 224 | ////REVIEW: this needs to be dynamic in the real thing 225 | public const int MaxConcurrentTouches = 5; 226 | 227 | #endregion 228 | 229 | #region Fields 230 | 231 | private List m_Touches = new List(MaxConcurrentTouches); 232 | private Touch m_CurrentPointerTouch; 233 | private Touch m_FirstClickTouch; 234 | private Touch m_SecondClickTouch; 235 | 236 | #endregion 237 | } 238 | } 239 | -------------------------------------------------------------------------------- /Input/Editor/DeviceAssignmentsWindow.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | 7 | namespace UnityEngine.InputNew 8 | { 9 | public class DeviceAssignmentsWindow : EditorWindow 10 | { 11 | static int s_MaxAssignedDevices; 12 | static int s_MaxMapDevices; 13 | static int s_MaxMaps; 14 | const int kDeviceElementWidth = 150; 15 | static int s_PlayerElementWidth = kDeviceElementWidth * 2 + 4; 16 | 17 | bool showMaps = true; 18 | Vector2 scrollPos; 19 | Dictionary devicePositionTargets = new Dictionary(); 20 | Dictionary devicePositions = new Dictionary(); 21 | 22 | static class Styles { 23 | public static GUIStyle deviceStyle; 24 | public static GUIStyle playerStyle; 25 | public static GUIStyle mapStyle; 26 | public static GUIStyle nodeLabel; 27 | static Styles() 28 | { 29 | deviceStyle = new GUIStyle("flow node 3"); 30 | deviceStyle.margin = new RectOffset(4,4,4,4); 31 | deviceStyle.padding = new RectOffset(4,4,4,4); 32 | deviceStyle.contentOffset = Vector2.zero; 33 | deviceStyle.alignment = TextAnchor.MiddleCenter; 34 | deviceStyle.normal.textColor = EditorGUIUtility.isProSkin ? Color.white : Color.black; 35 | 36 | playerStyle = new GUIStyle("flow node 2"); 37 | playerStyle.margin = new RectOffset(4,4,4,4); 38 | playerStyle.normal.textColor = EditorGUIUtility.isProSkin ? Color.white : Color.black; 39 | 40 | mapStyle = new GUIStyle("flow node 4"); 41 | mapStyle.margin = new RectOffset(4,4,4,4); 42 | mapStyle.normal.textColor = EditorGUIUtility.isProSkin ? Color.white : Color.black; 43 | 44 | nodeLabel = new GUIStyle(EditorStyles.label); 45 | nodeLabel.normal.textColor = EditorGUIUtility.isProSkin ? Color.white : Color.black; 46 | } 47 | } 48 | 49 | [MenuItem ("Window/Players")] 50 | static void Init() 51 | { 52 | // Get existing open window or if none, make a new one: 53 | DeviceAssignmentsWindow window = (DeviceAssignmentsWindow)EditorWindow.GetWindow (typeof (DeviceAssignmentsWindow)); 54 | window.Show(); 55 | window.titleContent = new GUIContent("Players"); 56 | } 57 | 58 | void OnEnable() 59 | { 60 | PlayerHandle.onChange += Repaint; 61 | ActionMapInput.onStatusChange += Repaint; 62 | EditorApplication.playmodeStateChanged += Repaint; 63 | } 64 | 65 | void OnDisable() 66 | { 67 | PlayerHandle.onChange -= Repaint; 68 | ActionMapInput.onStatusChange -= Repaint; 69 | EditorApplication.playmodeStateChanged -= Repaint; 70 | } 71 | 72 | void OnGUI() 73 | { 74 | EditorGUILayout.BeginHorizontal("toolbar"); 75 | showMaps = GUILayout.Toggle(showMaps, "Show Maps", "toolbarbutton"); 76 | GUILayout.FlexibleSpace(); 77 | EditorGUILayout.EndHorizontal(); 78 | 79 | if (showMaps) 80 | s_PlayerElementWidth = kDeviceElementWidth * 2 + 4; 81 | else 82 | s_PlayerElementWidth = kDeviceElementWidth; 83 | 84 | var devices = InputSystem.devices; 85 | var players = PlayerHandleManager.players; 86 | 87 | s_MaxAssignedDevices = 1; 88 | foreach (var player in players) 89 | s_MaxAssignedDevices = Mathf.Max(s_MaxAssignedDevices, player.assignments.Count); 90 | 91 | s_MaxMaps = 1; 92 | foreach (var player in players) 93 | s_MaxMaps = Mathf.Max(s_MaxMaps, player.maps.Count); 94 | 95 | scrollPos = EditorGUILayout.BeginScrollView(scrollPos); 96 | { 97 | ShowUnassignedDevices(devices); 98 | 99 | EditorGUILayout.Space(); 100 | 101 | ShowGlobalPlayerHandles(devices, players); 102 | 103 | EditorGUILayout.Space(); 104 | 105 | ShowPlayerHandles(devices, players); 106 | } 107 | DrawDevices(devices); 108 | EditorGUILayout.EndScrollView(); 109 | } 110 | 111 | void DrawDevices(List devices) 112 | { 113 | bool repaint = false; 114 | foreach (var device in devices) 115 | { 116 | Rect rect = new Rect(); 117 | if (Event.current.type == EventType.Repaint) 118 | { 119 | Rect target = devicePositionTargets[device]; 120 | if (devicePositions.TryGetValue(device, out rect)) 121 | { 122 | devicePositions[device] = rect = new Rect( 123 | Vector2.Lerp(rect.position, target.position, 0.1f), 124 | Vector2.Lerp(rect.size, target.size, 0.1f) 125 | ); 126 | } 127 | else 128 | { 129 | devicePositions[device] = rect = target; 130 | } 131 | if (rect != target) 132 | repaint = true; 133 | } 134 | GUI.Label(rect, device.ToString(), Styles.deviceStyle); 135 | } 136 | if (repaint) 137 | Repaint(); 138 | } 139 | 140 | void ShowUnassignedDevices(IEnumerable devices) 141 | { 142 | GUILayout.Label("Unassigned Devices", EditorStyles.boldLabel); 143 | GUILayout.Label("(In the prototype the available devices are hard-coded so for now presence in this list doesn't mean the devices physically exist and are connected.)"); 144 | 145 | EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(false)); 146 | foreach (var device in devices) 147 | { 148 | if (device.assignment != null) 149 | continue; 150 | Rect rect = GUILayoutUtility.GetRect(new GUIContent(device.ToString()), Styles.deviceStyle, GUILayout.Width(kDeviceElementWidth)); 151 | if (Event.current.type == EventType.Repaint) 152 | devicePositionTargets[device] = rect; 153 | } 154 | EditorGUILayout.EndHorizontal(); 155 | } 156 | 157 | void ShowGlobalPlayerHandles(IEnumerable devices, IEnumerable players) 158 | { 159 | GUILayout.Label("Global Player Handles", EditorStyles.boldLabel); 160 | GUILayout.Label("Listen to all unassigned devices."); 161 | 162 | EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(false)); 163 | foreach (var player in players) 164 | { 165 | if (!player.global) 166 | continue; 167 | DrawPlayerHandle(player); 168 | } 169 | EditorGUILayout.EndHorizontal(); 170 | } 171 | 172 | void ShowPlayerHandles(IEnumerable devices, IEnumerable players) 173 | { 174 | GUILayout.Label("Player Handles", EditorStyles.boldLabel); 175 | GUILayout.Label("Listen to devices they have assigned."); 176 | 177 | EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(false)); 178 | foreach (var player in players) 179 | { 180 | if (player.global) 181 | continue; 182 | DrawPlayerHandle(player); 183 | } 184 | EditorGUILayout.EndHorizontal(); 185 | } 186 | 187 | void DrawPlayerHandle(PlayerHandle player) 188 | { 189 | EditorGUIUtility.labelWidth = 160; 190 | 191 | GUIContent playerContent = new GUIContent("Player " + player.index); 192 | GUILayout.BeginVertical(playerContent, Styles.playerStyle, GUILayout.Width(s_PlayerElementWidth)); 193 | { 194 | GUILayout.Label("Assigned Devices", Styles.nodeLabel); 195 | for (int i = 0; i < s_MaxAssignedDevices; i++) 196 | { 197 | Rect deviceRect = GUILayoutUtility.GetRect(GUIContent.none, Styles.deviceStyle, GUILayout.Width(kDeviceElementWidth)); 198 | if (i >= player.assignments.Count) 199 | continue; 200 | if (Event.current.type == EventType.Repaint) 201 | devicePositionTargets[player.assignments[i].device] = deviceRect; 202 | } 203 | 204 | if (showMaps) 205 | { 206 | GUILayout.Label("Action Map Inputs", Styles.nodeLabel); 207 | for (int i = 0; i < player.maps.Count; i++) 208 | DrawActionMapInput(player.maps[i]); 209 | } 210 | } 211 | EditorGUILayout.EndVertical(); 212 | if (player.global) 213 | { 214 | Rect rect = GUILayoutUtility.GetLastRect(); 215 | GUI.Label(rect, "(Global)"); 216 | } 217 | } 218 | 219 | void DrawActionMapInput(ActionMapInput map) 220 | { 221 | EditorGUI.BeginDisabledGroup(!map.active); 222 | GUIContent mapContent = new GUIContent(map.actionMap.name); 223 | GUILayout.BeginVertical(mapContent, Styles.mapStyle); 224 | { 225 | LabelField("Block Subsequent", map.blockSubsequent.ToString()); 226 | 227 | string schemeString = "-"; 228 | if (map.active && map.controlScheme != null) 229 | schemeString = map.controlScheme.name; 230 | LabelField("Current Control Scheme", schemeString); 231 | 232 | string devicesString = ""; 233 | if (map.active) 234 | devicesString = string.Join(", ", map.GetCurrentlyUsedDevices().Select(e => e.ToString()).ToArray()); 235 | if (string.IsNullOrEmpty(devicesString)) 236 | devicesString = "-"; 237 | LabelField("Currently Used Devices", devicesString); 238 | } 239 | EditorGUILayout.EndVertical(); 240 | EditorGUI.EndDisabledGroup(); 241 | } 242 | 243 | void LabelField(string label1, string label2) 244 | { 245 | Rect rect = EditorGUILayout.GetControlRect(); 246 | Rect rect1 = rect; 247 | Rect rect2 = rect; 248 | rect2.xMin += EditorGUIUtility.labelWidth; 249 | 250 | rect1.xMax = rect2.xMin - 2; 251 | GUI.Label(rect1, label1, Styles.nodeLabel); 252 | GUI.Label(rect2, label2, Styles.nodeLabel); 253 | } 254 | } 255 | } -------------------------------------------------------------------------------- /Input/Core.Extensions/Gamepad.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Assets.Utilities; 5 | using UnityEngine; 6 | 7 | namespace UnityEngine.InputNew 8 | { 9 | public class Gamepad 10 | : Joystick 11 | { 12 | enum GamepadControl 13 | { 14 | // Standardized. 15 | 16 | LeftStickX, 17 | LeftStickY, 18 | LeftStickButton, 19 | 20 | RightStickX, 21 | RightStickY, 22 | RightStickButton, 23 | 24 | DPadLeft, 25 | DPadRight, 26 | DPadUp, 27 | DPadDown, 28 | 29 | Action1, 30 | Action2, 31 | Action3, 32 | Action4, 33 | 34 | LeftTrigger, 35 | RightTrigger, 36 | 37 | LeftBumper, 38 | RightBumper, 39 | 40 | // Compound controls. 41 | 42 | LeftStick, 43 | RightStick, 44 | DPad, 45 | 46 | // Not standardized, but provided for convenience. 47 | 48 | Back, 49 | Start, 50 | Select, 51 | System, 52 | Pause, 53 | Menu, 54 | Share, 55 | View, 56 | Options, 57 | TiltX, 58 | TiltY, 59 | TiltZ, 60 | ScrollWheel, 61 | TouchPadTap, 62 | TouchPadXAxis, 63 | TouchPadYAxis, 64 | 65 | // Not standardized. 66 | 67 | Analog0, 68 | Analog1, 69 | Analog2, 70 | Analog3, 71 | Analog4, 72 | Analog5, 73 | Analog6, 74 | Analog7, 75 | Analog8, 76 | Analog9, 77 | Analog10, 78 | Analog11, 79 | Analog12, 80 | Analog13, 81 | Analog14, 82 | Analog15, 83 | Analog16, 84 | Analog17, 85 | Analog18, 86 | Analog19, 87 | 88 | Button0, 89 | Button1, 90 | Button2, 91 | Button3, 92 | Button4, 93 | Button5, 94 | Button6, 95 | Button7, 96 | Button8, 97 | Button9, 98 | Button10, 99 | Button11, 100 | Button12, 101 | Button13, 102 | Button14, 103 | Button15, 104 | Button16, 105 | Button17, 106 | Button18, 107 | Button19, 108 | } 109 | 110 | #region Constructors 111 | 112 | public Gamepad() 113 | : this("Gamepad", null) {} 114 | 115 | public Gamepad(string deviceName, List additionalControls) 116 | { 117 | this.deviceName = deviceName; 118 | var controlCount = EnumHelpers.GetValueCount(); 119 | var controls = Enumerable.Repeat(new InputControlData(), controlCount).ToList(); 120 | 121 | // Compounds. 122 | controls[(int)GamepadControl.LeftStick] = new InputControlData 123 | { 124 | name = "Left Stick" 125 | , controlType = typeof(Vector2InputControl) 126 | , componentControlIndices = new[] { (int)GamepadControl.LeftStickX, (int)GamepadControl.LeftStickY } 127 | }; 128 | controls[(int)GamepadControl.RightStick] = new InputControlData 129 | { 130 | name = "Right Stick" 131 | , controlType = typeof(Vector2InputControl) 132 | , componentControlIndices = new[] { (int)GamepadControl.RightStickX, (int)GamepadControl.RightStickY } 133 | }; 134 | ////TODO: dpad (more complicated as the source is buttons which need to be translated into a vector) 135 | 136 | // Buttons. 137 | controls[(int)GamepadControl.Action1] = new InputControlData { name = "Action 1", controlType = typeof(ButtonInputControl) }; 138 | controls[(int)GamepadControl.Action2] = new InputControlData { name = "Action 2", controlType = typeof(ButtonInputControl) }; 139 | controls[(int)GamepadControl.Action3] = new InputControlData { name = "Action 3", controlType = typeof(ButtonInputControl) }; 140 | controls[(int)GamepadControl.Action4] = new InputControlData { name = "Action 4", controlType = typeof(ButtonInputControl) }; 141 | controls[(int)GamepadControl.LeftStickButton] = new InputControlData { name = "Left Stick Button", controlType = typeof(ButtonInputControl) }; 142 | controls[(int)GamepadControl.RightStickButton] = new InputControlData { name = "Right Stick Button", controlType = typeof(ButtonInputControl) }; 143 | controls[(int)GamepadControl.DPadUp] = new InputControlData { name = "DPad Up", controlType = typeof(ButtonInputControl) }; 144 | controls[(int)GamepadControl.DPadDown] = new InputControlData { name = "DPad Down", controlType = typeof(ButtonInputControl) }; 145 | controls[(int)GamepadControl.DPadLeft] = new InputControlData { name = "DPad Left", controlType = typeof(ButtonInputControl) }; 146 | controls[(int)GamepadControl.DPadRight] = new InputControlData { name = "DPad Right", controlType = typeof(ButtonInputControl) }; 147 | controls[(int)GamepadControl.LeftBumper] = new InputControlData { name = "Left Bumper", controlType = typeof(ButtonInputControl) }; 148 | controls[(int)GamepadControl.RightBumper] = new InputControlData { name = "Right Bumper", controlType = typeof(ButtonInputControl) }; 149 | 150 | controls[(int)GamepadControl.Start] = new InputControlData { name = "Start", controlType = typeof(ButtonInputControl) }; 151 | controls[(int)GamepadControl.Back] = new InputControlData { name = "Back", controlType = typeof(ButtonInputControl) }; 152 | controls[(int)GamepadControl.Select] = new InputControlData { name = "Select", controlType = typeof(ButtonInputControl) }; 153 | controls[(int)GamepadControl.System] = new InputControlData { name = "System", controlType = typeof(ButtonInputControl) }; 154 | controls[(int)GamepadControl.Pause] = new InputControlData { name = "Pause", controlType = typeof(ButtonInputControl) }; 155 | controls[(int)GamepadControl.Menu] = new InputControlData { name = "Menu", controlType = typeof(ButtonInputControl) }; 156 | controls[(int)GamepadControl.Share] = new InputControlData { name = "Share", controlType = typeof(ButtonInputControl) }; 157 | controls[(int)GamepadControl.View] = new InputControlData { name = "View", controlType = typeof(ButtonInputControl) }; 158 | controls[(int)GamepadControl.Options] = new InputControlData { name = "Options", controlType = typeof(ButtonInputControl) }; 159 | controls[(int)GamepadControl.TiltX] = new InputControlData { name = "TiltX", controlType = typeof(ButtonInputControl) }; 160 | controls[(int)GamepadControl.TiltY] = new InputControlData { name = "TiltY", controlType = typeof(ButtonInputControl) }; 161 | controls[(int)GamepadControl.TiltZ] = new InputControlData { name = "TiltZ", controlType = typeof(ButtonInputControl) }; 162 | controls[(int)GamepadControl.ScrollWheel] = new InputControlData { name = "ScrollWheel", controlType = typeof(ButtonInputControl) }; 163 | controls[(int)GamepadControl.TouchPadTap] = new InputControlData { name = "TouchPadTap", controlType = typeof(ButtonInputControl) }; 164 | controls[(int)GamepadControl.TouchPadXAxis] = new InputControlData { name = "TouchPadXAxis", controlType = typeof(ButtonInputControl) }; 165 | controls[(int)GamepadControl.TouchPadYAxis] = new InputControlData { name = "TouchPadYAxis", controlType = typeof(ButtonInputControl) }; 166 | 167 | // Axes. 168 | controls[(int)GamepadControl.LeftStickX] = new InputControlData { name = "Left Stick X", controlType = typeof(AxisInputControl) }; 169 | controls[(int)GamepadControl.LeftStickY] = new InputControlData { name = "Left Stick Y", controlType = typeof(AxisInputControl) }; 170 | controls[(int)GamepadControl.RightStickX] = new InputControlData { name = "Right Stick X", controlType = typeof(AxisInputControl) }; 171 | controls[(int)GamepadControl.RightStickY] = new InputControlData { name = "Right Stick Y", controlType = typeof(AxisInputControl) }; 172 | controls[(int)GamepadControl.LeftTrigger] = new InputControlData { name = "Left Trigger", controlType = typeof(AxisInputControl) }; 173 | controls[(int)GamepadControl.RightTrigger] = new InputControlData { name = "Right Trigger", controlType = typeof(AxisInputControl) }; 174 | 175 | if (additionalControls != null) 176 | controls.AddRange(additionalControls); 177 | 178 | SetControls(controls); 179 | } 180 | 181 | #endregion 182 | 183 | public AxisInputControl leftStickX { get { return (AxisInputControl)this[(int)GamepadControl.LeftStickX]; } } 184 | public AxisInputControl leftStickY { get { return (AxisInputControl)this[(int)GamepadControl.LeftStickY]; } } 185 | public ButtonInputControl leftStickButton { get { return (ButtonInputControl)this[(int)GamepadControl.LeftStickButton]; } } 186 | 187 | public AxisInputControl rightStickX { get { return (AxisInputControl)this[(int)GamepadControl.RightStickX]; } } 188 | public AxisInputControl rightStickY { get { return (AxisInputControl)this[(int)GamepadControl.RightStickY]; } } 189 | public ButtonInputControl rightStickButton { get { return (ButtonInputControl)this[(int)GamepadControl.RightStickButton]; } } 190 | 191 | public ButtonInputControl dPadLeft { get { return (ButtonInputControl)this[(int)GamepadControl.DPadLeft]; } } 192 | public ButtonInputControl dPadRight { get { return (ButtonInputControl)this[(int)GamepadControl.DPadRight]; } } 193 | public ButtonInputControl dPadUp { get { return (ButtonInputControl)this[(int)GamepadControl.DPadUp]; } } 194 | public ButtonInputControl dPadDown { get { return (ButtonInputControl)this[(int)GamepadControl.DPadDown]; } } 195 | 196 | public ButtonInputControl action1 { get { return (ButtonInputControl)this[(int)GamepadControl.Action1]; } } 197 | public ButtonInputControl action2 { get { return (ButtonInputControl)this[(int)GamepadControl.Action2]; } } 198 | public ButtonInputControl action3 { get { return (ButtonInputControl)this[(int)GamepadControl.Action3]; } } 199 | public ButtonInputControl action4 { get { return (ButtonInputControl)this[(int)GamepadControl.Action4]; } } 200 | 201 | public AxisInputControl leftTrigger { get { return (AxisInputControl)this[(int)GamepadControl.LeftTrigger]; } } 202 | public AxisInputControl rightTrigger { get { return (AxisInputControl)this[(int)GamepadControl.RightTrigger]; } } 203 | 204 | public ButtonInputControl leftBumper { get { return (ButtonInputControl)this[(int)GamepadControl.LeftBumper]; } } 205 | public ButtonInputControl rightBumper { get { return (ButtonInputControl)this[(int)GamepadControl.RightBumper]; } } 206 | 207 | // Compound controls. 208 | 209 | public Vector2InputControl leftStick { get { return (Vector2InputControl)this[(int)GamepadControl.LeftStick]; } } 210 | public Vector2InputControl rightStick { get { return (Vector2InputControl)this[(int)GamepadControl.RightStick]; } } 211 | public Vector2InputControl dPad { get { return (Vector2InputControl)this[(int)GamepadControl.DPad]; } } 212 | 213 | // Not standardized, but provided for convenience. 214 | 215 | public ButtonInputControl back { get { return (ButtonInputControl)this[(int)GamepadControl.Back]; } } 216 | public ButtonInputControl start { get { return (ButtonInputControl)this[(int)GamepadControl.Start]; } } 217 | public ButtonInputControl select { get { return (ButtonInputControl)this[(int)GamepadControl.Select]; } } 218 | public ButtonInputControl system { get { return (ButtonInputControl)this[(int)GamepadControl.System]; } } 219 | public ButtonInputControl pause { get { return (ButtonInputControl)this[(int)GamepadControl.Pause]; } } 220 | public ButtonInputControl menu { get { return (ButtonInputControl)this[(int)GamepadControl.Menu]; } } 221 | public ButtonInputControl share { get { return (ButtonInputControl)this[(int)GamepadControl.Share]; } } 222 | public ButtonInputControl view { get { return (ButtonInputControl)this[(int)GamepadControl.View]; } } 223 | public ButtonInputControl options { get { return (ButtonInputControl)this[(int)GamepadControl.Options]; } } 224 | public AxisInputControl tiltX { get { return (AxisInputControl)this[(int)GamepadControl.TiltX]; } } 225 | public AxisInputControl tiltY { get { return (AxisInputControl)this[(int)GamepadControl.TiltY]; } } 226 | public AxisInputControl tiltZ { get { return (AxisInputControl)this[(int)GamepadControl.TiltZ]; } } 227 | public AxisInputControl scrollWheel { get { return (AxisInputControl)this[(int)GamepadControl.ScrollWheel]; } } 228 | public ButtonInputControl touchPadTap { get { return (ButtonInputControl)this[(int)GamepadControl.TouchPadTap]; } } 229 | public AxisInputControl touchPadXAxis { get { return (AxisInputControl)this[(int)GamepadControl.TouchPadXAxis]; } } 230 | public AxisInputControl touchPadYAxis { get { return (AxisInputControl)this[(int)GamepadControl.TouchPadYAxis]; } } 231 | } 232 | } 233 | -------------------------------------------------------------------------------- /Input/Actions/ActionMapInput.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | 6 | namespace UnityEngine.InputNew 7 | { 8 | /* 9 | Things to test for action map / control schemes. 10 | 11 | - When pressing e.g. mouse button or gamepad trigger in one action map creates a new action map 12 | based on the same device, the new action map should not immediately have wasJustPressed be true. 13 | Hence the state in the newly created control scheme should be initialized to the state 14 | of the devices it's based on. 15 | 16 | - When pressing e.g. mouse button or gamepad trigger and it causes a switch in control scheme 17 | within an existing action map, the new control scheme *should* immediately have wasJustPressed be true. 18 | Hence the state in the newly created control scheme should not be initialized to the state 19 | of the devices it's based on. 20 | 21 | */ 22 | public class ActionMapInput : InputControlProvider 23 | { 24 | private ActionMap m_ActionMap; 25 | public ActionMap actionMap { get { return m_ActionMap; } } 26 | 27 | private ControlScheme m_ControlScheme; 28 | public ControlScheme controlScheme { get { return m_ControlScheme; } } 29 | 30 | private List m_DeviceStates = new List(); 31 | private List deviceStates { get { return m_DeviceStates; } } 32 | 33 | bool m_Active; 34 | public bool active { 35 | get { 36 | return m_Active; 37 | } 38 | set { 39 | if (m_Active == value) 40 | return; 41 | 42 | ResetControlsForCurrentReceivers(); 43 | 44 | m_Active = value; 45 | Reset(value); 46 | 47 | if (onStatusChange != null) 48 | onStatusChange.Invoke(); 49 | } 50 | } 51 | 52 | public bool blockSubsequent { get; set; } 53 | 54 | public delegate void ChangeEvent(); 55 | public static ChangeEvent onStatusChange; 56 | 57 | public static ActionMapInput Create(ActionMap actionMap) 58 | { 59 | ActionMapInput map = 60 | (ActionMapInput)Activator.CreateInstance(actionMap.customActionMapType, new object[] { actionMap }); 61 | return map; 62 | } 63 | 64 | protected ActionMapInput(ActionMap actionMap) 65 | { 66 | m_ActionMap = actionMap; 67 | 68 | // Create list of controls from ActionMap. 69 | ////REVIEW: doesn't handle compounds 70 | var controls = new List(); 71 | foreach (var entry in actionMap.actions) 72 | controls.Add(entry.controlData); 73 | SetControls(controls); 74 | } 75 | 76 | public bool TryInitializeWithDevices(IEnumerable availableDevices) 77 | { 78 | int bestScheme = -1; 79 | List bestFoundDevices = null; 80 | float mostRecentTime = -1; 81 | 82 | List foundDevices = new List(); 83 | for (int scheme = 0; scheme < actionMap.controlSchemes.Count; scheme++) 84 | { 85 | float timeForScheme = -1; 86 | foundDevices.Clear(); 87 | var types = actionMap.controlSchemes[scheme].deviceTypes; 88 | bool matchesAll = true; 89 | foreach (var type in types) 90 | { 91 | InputDevice foundDevice = null; 92 | float foundDeviceTime = -1; 93 | foreach (var device in availableDevices) 94 | { 95 | if (type.IsInstanceOfType(device) && device.lastEventTime > foundDeviceTime) 96 | { 97 | foundDevice = device; 98 | foundDeviceTime = device.lastEventTime; 99 | } 100 | } 101 | if (foundDevice != null) 102 | { 103 | foundDevices.Add(foundDevice); 104 | timeForScheme = Mathf.Max(timeForScheme, foundDeviceTime); 105 | } 106 | else 107 | { 108 | matchesAll = false; 109 | break; 110 | } 111 | } 112 | if (!matchesAll) 113 | continue; 114 | 115 | // If we reach this point we know that control scheme both matches required and matches all. 116 | if (timeForScheme > mostRecentTime) 117 | { 118 | bestScheme = scheme; 119 | bestFoundDevices = new List(foundDevices); 120 | mostRecentTime = timeForScheme; 121 | } 122 | } 123 | 124 | if (bestScheme == -1) 125 | return false; 126 | 127 | ControlScheme matchingControlScheme = actionMap.controlSchemes[bestScheme]; 128 | Assign(matchingControlScheme, bestFoundDevices); 129 | return true; 130 | } 131 | 132 | private void Assign(ControlScheme controlScheme, List devices) 133 | { 134 | m_ControlScheme = controlScheme; 135 | 136 | // Create state for every device. 137 | var deviceStates = new List(); 138 | foreach (var device in devices) 139 | deviceStates.Add(new InputState(device)); 140 | m_DeviceStates = deviceStates; 141 | RefreshBindings(); 142 | 143 | ResetControlsForCurrentReceivers(); 144 | 145 | Reset(); 146 | 147 | if (onStatusChange != null) 148 | onStatusChange.Invoke(); 149 | } 150 | 151 | private void ResetControlsForCurrentReceivers() 152 | { 153 | // Set state to inactive temporarily, so subsequent ActionMaps receive the reset events. 154 | bool oldActiveState = m_Active; 155 | m_Active = false; 156 | 157 | for (int i = 0; i < m_DeviceStates.Count; i++) 158 | { 159 | var state = m_DeviceStates[i]; 160 | for (int j = 0; j < state.count; j++) 161 | { 162 | if (blockSubsequent || state.IsControlEnabled(j)) 163 | { 164 | GenericControlEvent evt = new GenericControlEvent() 165 | { 166 | device = state.controlProvider as InputDevice, 167 | controlIndex = j, 168 | value = state.controlProvider.GetControlData(j).defaultValue, 169 | time = Time.time 170 | }; 171 | InputSystem.consumers.ProcessEvent(evt); 172 | } 173 | } 174 | } 175 | 176 | m_Active = oldActiveState; 177 | } 178 | 179 | public bool CurrentlyUsesDevice(InputDevice device) 180 | { 181 | foreach (var deviceState in deviceStates) 182 | if (deviceState.controlProvider == device) 183 | return true; 184 | return false; 185 | } 186 | 187 | public override bool ProcessEvent/*ForScheme*/(InputEvent inputEvent) 188 | { 189 | var consumed = false; 190 | 191 | // Update device state (if event actually goes to one of the devices we talk to). 192 | foreach (var deviceState in deviceStates) 193 | { 194 | ////FIXME: should refer to proper type 195 | var device = (InputDevice)deviceState.controlProvider; 196 | 197 | // Skip state if event is not meant for device associated with it. 198 | if (device != inputEvent.device) 199 | continue; 200 | 201 | // Give device a stab at converting the event into state. 202 | if (device.ProcessEventIntoState(inputEvent, deviceState)) 203 | { 204 | consumed = true; 205 | break; 206 | } 207 | } 208 | 209 | if (!consumed) 210 | return false; 211 | 212 | return true; 213 | } 214 | 215 | public void Reset(bool initToDeviceState = true) 216 | { 217 | if (initToDeviceState) 218 | { 219 | foreach (var deviceState in deviceStates) 220 | deviceState.InitToDevice(); 221 | 222 | ExtractCurrentValuesFromSources(); 223 | 224 | // Copy current values into prev values. 225 | state.BeginFrame(); 226 | } 227 | else 228 | { 229 | foreach (var deviceState in deviceStates) 230 | deviceState.Reset(); 231 | state.Reset(); 232 | } 233 | } 234 | 235 | public List GetCurrentlyUsedDevices() 236 | { 237 | List list = new List(); 238 | for (int i = 0; i < deviceStates.Count; i++) 239 | list.Add(deviceStates[i].controlProvider as InputDevice); 240 | return list; 241 | } 242 | 243 | private InputState GetDeviceStateForDeviceType(Type deviceType) 244 | { 245 | foreach (var deviceState in deviceStates) 246 | { 247 | if (deviceType.IsInstanceOfType(deviceState.controlProvider)) 248 | return deviceState; 249 | } 250 | throw new ArgumentException("deviceType"); 251 | } 252 | 253 | public void BeginFrame() 254 | { 255 | state.BeginFrame(); 256 | foreach (var deviceState in deviceStates) 257 | deviceState.BeginFrame(); 258 | } 259 | 260 | public void EndFrame() 261 | { 262 | ExtractCurrentValuesFromSources(); 263 | } 264 | 265 | private void ExtractCurrentValuesFromSources() 266 | { 267 | for (var entryIndex = 0; entryIndex < actionMap.actions.Count; ++ entryIndex) 268 | { 269 | var binding = controlScheme.bindings[entryIndex]; 270 | 271 | var controlValue = 0.0f; 272 | foreach (var source in binding.sources) 273 | { 274 | var value = GetSourceValue(source); 275 | if (Mathf.Abs(value) > Mathf.Abs(controlValue)) 276 | controlValue = value; 277 | } 278 | 279 | foreach (var axis in binding.buttonAxisSources) 280 | { 281 | var negativeValue = GetSourceValue(axis.negative); 282 | var positiveValue = GetSourceValue(axis.positive); 283 | var value = positiveValue - negativeValue; 284 | if (Mathf.Abs(value) > Mathf.Abs(controlValue)) 285 | controlValue = value; 286 | } 287 | 288 | state.SetCurrentValue(entryIndex, controlValue); 289 | } 290 | } 291 | 292 | private float GetSourceValue(InputControlDescriptor source) 293 | { 294 | var deviceState = GetDeviceStateForDeviceType(source.deviceType); 295 | return deviceState.GetCurrentValue(source.controlIndex); 296 | } 297 | 298 | public override string GetPrimarySourceName(int controlIndex, string buttonAxisFormattingString = "{0} & {1}") 299 | { 300 | var binding = controlScheme.bindings[controlIndex]; 301 | 302 | if (binding.primaryIsButtonAxis && binding.buttonAxisSources != null && binding.buttonAxisSources.Count > 0) 303 | { 304 | return string.Format(buttonAxisFormattingString, 305 | GetSourceName(binding.buttonAxisSources[0].negative), 306 | GetSourceName(binding.buttonAxisSources[0].positive)); 307 | } 308 | else if (binding.sources != null && binding.sources.Count > 0) 309 | { 310 | return GetSourceName(binding.sources[0]); 311 | } 312 | return string.Empty; 313 | } 314 | 315 | private string GetSourceName(InputControlDescriptor source) 316 | { 317 | var deviceState = GetDeviceStateForDeviceType(source.deviceType); 318 | return deviceState.controlProvider.GetControlData(source.controlIndex).name; 319 | } 320 | 321 | ////REVIEW: the descriptor may come from anywhere; method assumes we get passed some state we actually own 322 | ////REVIEW: this mutates the state of the current instance but also mutates the shared ActionMap; that's bad 323 | public bool BindControl(InputControlDescriptor descriptor, InputControl control, bool restrictToExistingDevices) 324 | { 325 | bool existingDevice = false; 326 | for (int i = 0; i < m_DeviceStates.Count; i++) 327 | { 328 | if (control.provider == m_DeviceStates[i].controlProvider) 329 | { 330 | existingDevice = true; 331 | break; 332 | } 333 | } 334 | 335 | if (!existingDevice) 336 | { 337 | if (restrictToExistingDevices) 338 | return false; 339 | 340 | deviceStates.Add(new InputState(control.provider, new List() { control.index })); 341 | } 342 | 343 | descriptor.controlIndex = control.index; 344 | descriptor.deviceType = control.provider.GetType(); 345 | 346 | m_ControlScheme.customized = true; 347 | 348 | RefreshBindings(); 349 | 350 | return true; 351 | } 352 | 353 | 354 | public void RevertCustomizations() 355 | { 356 | ////FIXME: doesn't properly reset control scheme 357 | m_ActionMap.RevertCustomizations(); 358 | RefreshBindings(); 359 | } 360 | 361 | private void RefreshBindings() 362 | { 363 | // Gather a mapping of device types to list of bindings that use the given type. 364 | var perDeviceTypeUsedControlIndices = new Dictionary>(); 365 | controlScheme.ExtractDeviceTypesAndControlIndices(perDeviceTypeUsedControlIndices); 366 | 367 | foreach (var deviceType in controlScheme.deviceTypes) 368 | { 369 | InputState state = GetDeviceStateForDeviceType(deviceType); 370 | List indices; 371 | if (perDeviceTypeUsedControlIndices.TryGetValue(deviceType, out indices)) 372 | state.SetUsedControls(indices); 373 | else 374 | state.SetAllControlsEnabled(false); 375 | } 376 | } 377 | } 378 | 379 | [Serializable] 380 | public class ActionMapSlot 381 | { 382 | public ActionMap actionMap; 383 | public bool active = true; 384 | public bool blockSubsequent; 385 | } 386 | } 387 | -------------------------------------------------------------------------------- /FakePrototypeStuff/Editor/InputManagerAssetGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text.RegularExpressions; 4 | using UnityEditor; 5 | using UnityEngine; 6 | 7 | [InitializeOnLoad] 8 | internal class InputManagerAssetGenerator 9 | { 10 | static List axisPresets = new List(); 11 | 12 | static InputManagerAssetGenerator() 13 | { 14 | if (!CheckAxisPresets()) 15 | { 16 | if (EditorUtility.DisplayDialog( 17 | "Setup InputManager", 18 | "The input system prototype needs to patch the InputManager settings.", 19 | "Apply", "Cancel") 20 | ) 21 | ApplyAxisPresets(); 22 | } 23 | } 24 | 25 | static bool CheckAxisPresets() 26 | { 27 | SetupAxisPresets(); 28 | 29 | var axisArray = GetInputManagerAxisArray(); 30 | 31 | if (axisArray.arraySize != axisPresets.Count) 32 | return false; 33 | 34 | for (int i = 0; i < axisPresets.Count; i++) 35 | { 36 | var axisEntry = axisArray.GetArrayElementAtIndex(i); 37 | if (!axisPresets[i].EqualTo(axisEntry)) 38 | return false; 39 | } 40 | 41 | return true; 42 | } 43 | 44 | 45 | static void ApplyAxisPresets() 46 | { 47 | SetupAxisPresets(); 48 | 49 | var inputManagerAsset = AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0]; 50 | var serializedObject = new SerializedObject(inputManagerAsset); 51 | var axisArray = serializedObject.FindProperty("m_Axes"); 52 | 53 | axisArray.arraySize = axisPresets.Count; 54 | serializedObject.ApplyModifiedProperties(); 55 | 56 | for (int i = 0; i < axisPresets.Count; i++) 57 | { 58 | var axisEntry = axisArray.GetArrayElementAtIndex(i); 59 | axisPresets[i].ApplyTo(ref axisEntry); 60 | } 61 | 62 | serializedObject.ApplyModifiedProperties(); 63 | 64 | AssetDatabase.Refresh(); 65 | } 66 | 67 | 68 | static void SetupAxisPresets() 69 | { 70 | axisPresets.Clear(); 71 | CreateRequiredAxisPresets(); 72 | ImportExistingAxisPresets(); 73 | CreateCompatibilityAxisPresets(); 74 | } 75 | 76 | 77 | static void CreateRequiredAxisPresets() 78 | { 79 | for (int device = 1; device <= JoystickInputToEvents.joystickCount; device++) 80 | { 81 | for (int analog = 1; analog <= JoystickInputToEvents.axisCount; analog++) 82 | { 83 | axisPresets.Add(new AxisPreset(device, analog)); 84 | } 85 | } 86 | 87 | axisPresets.Add(new AxisPreset("Mouse X", 1, 0, 1.0f)); 88 | axisPresets.Add(new AxisPreset("Mouse Y", 1, 1, 1.0f)); 89 | axisPresets.Add(new AxisPreset("Mouse Z", 1, 2, 1.0f)); 90 | } 91 | 92 | 93 | static void ImportExistingAxisPresets() 94 | { 95 | var axisArray = GetInputManagerAxisArray(); 96 | for (int i = 0; i < axisArray.arraySize; i++) 97 | { 98 | var axisEntry = axisArray.GetArrayElementAtIndex(i); 99 | var axisPreset = new AxisPreset(axisEntry); 100 | if (!axisPreset.ReservedName) 101 | { 102 | axisPresets.Add(axisPreset); 103 | } 104 | } 105 | } 106 | 107 | 108 | static void CreateCompatibilityAxisPresets() 109 | { 110 | if (!HasAxisPreset("Mouse ScrollWheel")) 111 | { 112 | axisPresets.Add(new AxisPreset("Mouse ScrollWheel", 1, 2, 0.1f)); 113 | } 114 | 115 | if (!HasAxisPreset("Horizontal")) 116 | { 117 | axisPresets.Add(new AxisPreset() 118 | { 119 | name = "Horizontal", 120 | negativeButton = "left", 121 | positiveButton = "right", 122 | altNegativeButton = "a", 123 | altPositiveButton = "d", 124 | gravity = 3.0f, 125 | deadZone = 0.001f, 126 | sensitivity = 3.0f, 127 | snap = true, 128 | type = 0, 129 | axis = 0, 130 | joyNum = 0 131 | }); 132 | 133 | axisPresets.Add(new AxisPreset() 134 | { 135 | name = "Horizontal", 136 | gravity = 0.0f, 137 | deadZone = 0.19f, 138 | sensitivity = 1.0f, 139 | type = 2, 140 | axis = 0, 141 | joyNum = 0 142 | }); 143 | } 144 | 145 | if (!HasAxisPreset("Vertical")) 146 | { 147 | axisPresets.Add(new AxisPreset() 148 | { 149 | name = "Vertical", 150 | negativeButton = "down", 151 | positiveButton = "up", 152 | altNegativeButton = "s", 153 | altPositiveButton = "w", 154 | gravity = 3.0f, 155 | deadZone = 0.001f, 156 | sensitivity = 3.0f, 157 | snap = true, 158 | type = 0, 159 | axis = 0, 160 | joyNum = 0 161 | }); 162 | 163 | axisPresets.Add(new AxisPreset() 164 | { 165 | name = "Vertical", 166 | gravity = 0.0f, 167 | deadZone = 0.19f, 168 | sensitivity = 1.0f, 169 | type = 2, 170 | axis = 0, 171 | invert = true, 172 | joyNum = 0 173 | }); 174 | } 175 | 176 | if (!HasAxisPreset("Submit")) 177 | { 178 | axisPresets.Add(new AxisPreset() 179 | { 180 | name = "Submit", 181 | positiveButton = "return", 182 | altPositiveButton = "joystick button 0", 183 | gravity = 1000.0f, 184 | deadZone = 0.001f, 185 | sensitivity = 1000.0f, 186 | type = 0, 187 | axis = 0, 188 | joyNum = 0 189 | }); 190 | 191 | axisPresets.Add(new AxisPreset() 192 | { 193 | name = "Submit", 194 | positiveButton = "enter", 195 | altPositiveButton = "space", 196 | gravity = 1000.0f, 197 | deadZone = 0.001f, 198 | sensitivity = 1000.0f, 199 | type = 0, 200 | axis = 0, 201 | joyNum = 0 202 | }); 203 | } 204 | 205 | if (!HasAxisPreset("Cancel")) 206 | { 207 | axisPresets.Add(new AxisPreset() 208 | { 209 | name = "Cancel", 210 | positiveButton = "escape", 211 | altPositiveButton = "joystick button 1", 212 | gravity = 1000.0f, 213 | deadZone = 0.001f, 214 | sensitivity = 1000.0f, 215 | type = 0, 216 | axis = 0, 217 | joyNum = 0 218 | }); 219 | } 220 | } 221 | 222 | 223 | static bool HasAxisPreset(string name) 224 | { 225 | for (int i = 0; i < axisPresets.Count; i++) 226 | { 227 | if (axisPresets[i].name == name) 228 | { 229 | return true; 230 | } 231 | } 232 | 233 | return false; 234 | } 235 | 236 | 237 | static SerializedProperty GetInputManagerAxisArray() 238 | { 239 | var inputManagerAsset = AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0]; 240 | var serializedObject = new SerializedObject(inputManagerAsset); 241 | return serializedObject.FindProperty("m_Axes"); 242 | } 243 | 244 | 245 | static SerializedProperty GetChildProperty(SerializedProperty parent, string name) 246 | { 247 | SerializedProperty child = parent.Copy(); 248 | child.Next(true); 249 | 250 | do 251 | { 252 | if (child.name == name) 253 | { 254 | return child; 255 | } 256 | } while (child.Next(false)); 257 | 258 | return null; 259 | } 260 | 261 | 262 | internal class AxisPreset 263 | { 264 | public string name; 265 | public string descriptiveName; 266 | public string descriptiveNegativeName; 267 | public string negativeButton; 268 | public string positiveButton; 269 | public string altNegativeButton; 270 | public string altPositiveButton; 271 | public float gravity; 272 | public float deadZone = 0.001f; 273 | public float sensitivity = 1.0f; 274 | public bool snap; 275 | public bool invert; 276 | public int type; 277 | public int axis; 278 | public int joyNum; 279 | 280 | 281 | public AxisPreset() 282 | { 283 | } 284 | 285 | 286 | public AxisPreset(SerializedProperty axisPreset) 287 | { 288 | this.name = GetChildProperty(axisPreset, "m_Name").stringValue; 289 | this.descriptiveName = GetChildProperty(axisPreset, "descriptiveName").stringValue; 290 | this.descriptiveNegativeName = GetChildProperty(axisPreset, "descriptiveNegativeName").stringValue; 291 | this.negativeButton = GetChildProperty(axisPreset, "negativeButton").stringValue; 292 | this.positiveButton = GetChildProperty(axisPreset, "positiveButton").stringValue; 293 | this.altNegativeButton = GetChildProperty(axisPreset, "altNegativeButton").stringValue; 294 | this.altPositiveButton = GetChildProperty(axisPreset, "altPositiveButton").stringValue; 295 | this.gravity = GetChildProperty(axisPreset, "gravity").floatValue; 296 | this.deadZone = GetChildProperty(axisPreset, "dead").floatValue; 297 | this.sensitivity = GetChildProperty(axisPreset, "sensitivity").floatValue; 298 | this.snap = GetChildProperty(axisPreset, "snap").boolValue; 299 | this.invert = GetChildProperty(axisPreset, "invert").boolValue; 300 | this.type = GetChildProperty(axisPreset, "type").intValue; 301 | this.axis = GetChildProperty(axisPreset, "axis").intValue; 302 | this.joyNum = GetChildProperty(axisPreset, "joyNum").intValue; 303 | } 304 | 305 | 306 | public AxisPreset(string name, int type, int axis, float sensitivity) 307 | { 308 | this.name = name; 309 | this.descriptiveName = ""; 310 | this.descriptiveNegativeName = ""; 311 | this.negativeButton = ""; 312 | this.positiveButton = ""; 313 | this.altNegativeButton = ""; 314 | this.altPositiveButton = ""; 315 | this.gravity = 0.0f; 316 | this.deadZone = 0.001f; 317 | this.sensitivity = sensitivity; 318 | this.snap = false; 319 | this.invert = false; 320 | this.type = type; 321 | this.axis = axis; 322 | this.joyNum = 0; 323 | } 324 | 325 | 326 | public AxisPreset(int device, int analog) 327 | { 328 | this.name = string.Format( "Analog{0}_Joy{1}", analog, device); 329 | this.descriptiveName = ""; 330 | this.descriptiveNegativeName = ""; 331 | this.negativeButton = ""; 332 | this.positiveButton = ""; 333 | this.altNegativeButton = ""; 334 | this.altPositiveButton = ""; 335 | this.gravity = 0.0f; 336 | this.deadZone = 0.001f; 337 | this.sensitivity = 1.0f; 338 | this.snap = false; 339 | this.invert = false; 340 | this.type = 2; 341 | this.axis = analog - 1; 342 | this.joyNum = device; 343 | } 344 | 345 | 346 | public bool ReservedName 347 | { 348 | get 349 | { 350 | if (Regex.Match(name, @"^Analog\d+_Joy\d+$").Success || 351 | Regex.Match(name, @"^Mouse (X|Y|Z)$").Success) 352 | { 353 | return true; 354 | } 355 | return false; 356 | } 357 | } 358 | 359 | 360 | public void ApplyTo(ref SerializedProperty axisPreset) 361 | { 362 | GetChildProperty(axisPreset, "m_Name").stringValue = name; 363 | GetChildProperty(axisPreset, "descriptiveName").stringValue = descriptiveName; 364 | GetChildProperty(axisPreset, "descriptiveNegativeName").stringValue = descriptiveNegativeName; 365 | GetChildProperty(axisPreset, "negativeButton").stringValue = negativeButton; 366 | GetChildProperty(axisPreset, "positiveButton").stringValue = positiveButton; 367 | GetChildProperty(axisPreset, "altNegativeButton").stringValue = altNegativeButton; 368 | GetChildProperty(axisPreset, "altPositiveButton").stringValue = altPositiveButton; 369 | GetChildProperty(axisPreset, "gravity").floatValue = gravity; 370 | GetChildProperty(axisPreset, "dead").floatValue = deadZone; 371 | GetChildProperty(axisPreset, "sensitivity").floatValue = sensitivity; 372 | GetChildProperty(axisPreset, "snap").boolValue = snap; 373 | GetChildProperty(axisPreset, "invert").boolValue = invert; 374 | GetChildProperty(axisPreset, "type").intValue = type; 375 | GetChildProperty(axisPreset, "axis").intValue = axis; 376 | GetChildProperty(axisPreset, "joyNum").intValue = joyNum; 377 | } 378 | 379 | 380 | public bool EqualTo(SerializedProperty axisPreset) 381 | { 382 | if (GetChildProperty(axisPreset, "m_Name").stringValue != name) 383 | return false; 384 | if (GetChildProperty(axisPreset, "descriptiveName").stringValue != descriptiveName) 385 | return false; 386 | if (GetChildProperty(axisPreset, "descriptiveNegativeName").stringValue != descriptiveNegativeName) 387 | return false; 388 | if (GetChildProperty(axisPreset, "negativeButton").stringValue != negativeButton) 389 | return false; 390 | if (GetChildProperty(axisPreset, "positiveButton").stringValue != positiveButton) 391 | return false; 392 | if (GetChildProperty(axisPreset, "altNegativeButton").stringValue != altNegativeButton) 393 | return false; 394 | if (GetChildProperty(axisPreset, "altPositiveButton").stringValue != altPositiveButton) 395 | return false; 396 | if (!Mathf.Approximately(GetChildProperty(axisPreset, "gravity").floatValue, gravity)) 397 | return false; 398 | if (!Mathf.Approximately(GetChildProperty(axisPreset, "dead").floatValue, deadZone)) 399 | return false; 400 | if (!Mathf.Approximately(GetChildProperty(axisPreset, "sensitivity").floatValue, this.sensitivity)) 401 | return false; 402 | if (GetChildProperty(axisPreset, "snap").boolValue != snap) 403 | return false; 404 | if (GetChildProperty(axisPreset, "invert").boolValue != invert) 405 | return false; 406 | if (GetChildProperty(axisPreset, "type").intValue != type) 407 | return false; 408 | if (GetChildProperty(axisPreset, "axis").intValue != axis) 409 | return false; 410 | if (GetChildProperty(axisPreset, "joyNum").intValue != joyNum) 411 | return false; 412 | 413 | return true; 414 | } 415 | } 416 | } 417 | --------------------------------------------------------------------------------