• Stars
    star
    157
  • Rank 237,618 (Top 5 %)
  • Language
    C#
  • License
    MIT License
  • Created about 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An improvement over Unity's legacy Input system that allows you to use custom input providers like on-screen joysticks, UI buttons and d-pads

Simple Input for Unity 3D

screenshot

Available on Asset Store: https://assetstore.unity.com/packages/tools/input-management/simple-input-system-113033

Forum Thread: https://forum.unity.com/threads/simple-input-use-custom-input-providers-like-joysticks-ui-buttons-and-d-pads-open-source.520504/

Discord: https://discord.gg/UJJt549AaV

WebGL Demo: http://yasirkula.net/SimpleInputDemo/

GitHub Sponsors โ˜•

SimpleInput is an improvement over Unity's standard Input system that allows you to use custom input providers like on-screen joysticks, UI buttons and d-pads. In other words, it lets you simulate e.g. Input.GetAxis when a button is pressed or a virtual joystick is dragged. It also supports using custom axes and buttons that don't necessarily exist in Edit-Project Settings-Input.

Please note that Unity's new Input System is not supported.

INSTALLATION

There are 5 ways to install this plugin:

  • import SimpleInput.unitypackage via Assets-Import Package
  • clone/download this repository and move the Plugins folder to your Unity project's Assets folder
  • import it from Asset Store
  • (via Package Manager) add the following line to Packages/manifest.json:
    • "com.yasirkula.simpleinput": "https://github.com/yasirkula/UnitySimpleInput.git",
  • (via OpenUPM) after installing openupm-cli, run the following command:
    • openupm add com.yasirkula.simpleinput

HOW TO

To use the SimpleInput system, simply replace Input with SimpleInput in your scripts; i.e:

  • Input.GetAxis -> SimpleInput.GetAxis
  • Input.GetAxisRaw -> SimpleInput.GetAxisRaw
  • Input.GetButtonDown -> SimpleInput.GetButtonDown
  • Input.GetButton -> SimpleInput.GetButton
  • Input.GetButtonUp -> SimpleInput.GetButtonUp
  • Input.GetMouseButtonDown -> SimpleInput.GetMouseButtonDown
  • Input.GetMouseButton -> SimpleInput.GetMouseButton
  • Input.GetMouseButtonUp -> SimpleInput.GetMouseButtonUp
  • Input.GetKeyDown -> SimpleInput.GetKeyDown
  • Input.GetKey -> SimpleInput.GetKey
  • Input.GetKeyUp -> SimpleInput.GetKeyUp

Note that there is no replacement for Input.GetKey(string) function. You have to convert the string to the corresponding KeyCode to benefit from SimpleInput.GetKey(KeyCode) function.

By default, SimpleInput receives input from Unity's Input system, as well. That's why your code keeps working as is after changing Input to SimpleInput. If you want, you can disable this behaviour so that SimpleInput receives input from custom input providers only. Simply calling SimpleInput.TrackUnityInput = false; will do the trick. It is possible to let a subset of the standard Unity inputs continue providing input to SimpleInput via the UnityInputProvider component.

SimpleInput works almost identically to standard Input system; only the lerping of Input.GetAxis might differ slightly. Lerp modifier can be configured via SimpleInput.GetAxisSensitivity.

BUILT-IN INPUT COMPONENTS

SimpleInput.GetAxis Inputs

  • AxisInputKeyboard: provides axis input while specified key is held down
  • AxisInputMouse: redirects "Mouse X" and "Mouse Y" inputs to two other axes on standalone platforms. Normally, on mobile platforms, dragging your finger on touchscreen provides "Mouse X" and "Mouse Y" inputs. However, you may want to simulate these two axes only with certain input method(s) on mobile platforms, e.g. a joystick. In this case, use this component to redirect mouse input to some other custom axes (like "MouseNew X", "MouseNew Y") and use these axes with SimpleInput in your scripts. Other input method(s) e.g. joystick should also use these axes instead of "Mouse X" and "Mouse Y"
  • AxisInputUI: provides axis input while attached UI Element (anything that extends UnityEngine.UI.Graphic) is held down
  • AxisInputUIArrows: provides 2-directional (left-right or up-down) or 4-directional axis input while attached UI Element is held down (see ArrowsAllDirections, ArrowsHorizontal and ArrowsVertical prefabs). UI Element's RectTransform must have a Pivot value of (0.5, 0.5)
  • AxisInputMoveGesture: provides axis input while move gesture (two pointers moving in the same direction) is performed on a RectTransform
  • AxisInputPinchGesture: provides axis input while pinch gesture (two pointers moving in opposite directions) is performed on a RectTransform
  • AxisInputRotateGesture: provides axis input while rotate gesture (two pointers rotating around a center point) is performed on a RectTransform
  • AxisInputSwipeGesture: provides axis input while a pointer is swiped by a specified amount on a RectTransform
  • Dpad: provides -1, 0 or 1 as axis input for x and y axes while the Dpad is held down; works similar to joystick Dpads. Dpad's RectTransform must have a Pivot value of (0.5, 0.5)
  • Joystick: a standard on-screen joystick input. If Is Dynamic Joystick is selected, joystick only appears while a pointer touches the screen. Dynamic Joystick Movement Area specifies the zone that the dynamic joystick can appear in (leave blank to use the whole canvas). If Can Follow Pointer is selected, joystick will follow the cursor when cursor's distance to the joystick is greater than the radius
  • SteeringWheel: provides axis input while the wheel is rotated (by far, the most fun input method to play with =') ). Steering wheel's RectTransform must have a Pivot value of (0.5, 0.5)
  • Touchpad: provides axis input while a pointer is dragged on a RectTransform

SimpleInput.GetButton Inputs

  • ButtonInputKeyboard: provides button input while specified key is held down
  • ButtonInputUI: provides button input while attached UI Element is held down
  • ButtonInputSwipeGesture: provides button input while a pointer is swiped by a specified amount on a RectTransform

SimpleInput.GetMouseButton Inputs

  • MouseButtonInputKeyboard: provides mouse button input while specified key is held down
  • MouseButtonInputUI: provides mouse button input while attached UI Element is held down
  • MouseButtonInputSwipeGesture: provides mouse button input while a pointer is swiped by a specified amount on a RectTransform

SimpleInput.GetKey Inputs

  • KeyInputKeyboard: provides key input while specified real key is held down
  • KeyInputUI: provides key input while attached UI Element is held down
  • KeyInputSwipeGesture: provides key input while a pointer is swiped by a specified amount on a RectTransform

To send an input while a mouse button is held down, you can use the XInputKeyboard component and set the key to the desired mouse button: KeyCode.Mouse0, KeyCode.Mouse1, etc.

Prefabs folder contains some plug 'n' play prefabs. Drag & drop them to your canvas and you are good to go! You can also customize them using the sprites provided in the Sprites folder (or using your own sprites, obviously). For more resources, open ExtraResources.unitypackage.

REBINDING INPUTS

It is possible to rebind the axes, buttons, mouse buttons and/or keys in your components during gameplay. For example, if you want to change the axes of your joystick from "Horizontal" and "Vertical" to "Horizontal2" and "Vertical2", use the following code:

void ChangeBindingsOfJoystick( Joystick joystick )
{
	joystick.xAxis.Key = "Horizontal2";
	joystick.yAxis.Key = "Vertical2";
}

Rebinding inputs from the Inspector is currently not possible during gameplay.

WRITING CUSTOM INPUT PROVIDERS

Simply create a SimpleInput.AxisInput, SimpleInput.ButtonInput, SimpleInput.MouseButtonInput or SimpleInput.KeyInput object and call its StartTracking() function to start sending inputs to SimpleInput. Make sure to call the StopTracking() function before the object is destroyed or disabled. To change the value of the input, change its value field. See AxisInputKeyboard.cs and AxisInputUI.cs for reference.

If you need to update your input's value in Update function, you can register to SimpleInput.OnUpdate event instead of using Unity's Update function as SimpleInput.OnUpdate is called before other Update functions (Script Execution Order).

To easily simulate a button click, mouse button click or key click from your scripts, you can use the SimpleInputHelper.TriggerButtonClick, SimpleInputHelper.TriggerMouseButtonClick and SimpleInputHelper.TriggerKeyClick functions.

More Repositories

1

UnityIngameDebugConsole

A uGUI based console to see debug messages and execute commands during gameplay in Unity
C#
2,117
star
2

UnityAssetUsageDetector

Find usages of the selected asset(s) and/or Object(s) in your Unity project, i.e. list the objects that refer to them
C#
1,693
star
3

UnityRuntimeInspector

Runtime Inspector and Hierarchy solution for Unity for debugging and runtime editing purposes
C#
1,676
star
4

UnityNativeGallery

A native Unity plugin to interact with Gallery/Photos on Android & iOS (save and/or load images/videos)
Objective-C++
1,396
star
5

UnityBezierSolution

A bezier spline solution for Unity 3D with some utility functions (like travelling the spline with constant speed/time)
C#
1,153
star
6

UnityNativeShare

A Unity plugin to natively share files (images, videos, documents, etc.) and/or plain text on Android & iOS
C#
905
star
7

UnitySimpleFileBrowser

A uGUI based runtime file browser for Unity 3D (draggable and resizable)
C#
844
star
8

UnityDynamicPanels

Draggable, resizable, dockable and stackable UI panel solution for Unity 3D
C#
735
star
9

UnityNativeCamera

A native Unity plugin to take pictures/record videos with device camera on Android & iOS
C#
605
star
10

UnityRuntimePreviewGenerator

Generate preview textures (thumbnails) for your GameObject's or materials on the fly in Unity
C#
304
star
11

UnityNativeFilePicker

A native Unity plugin to import/export files from/to various document providers on Android & iOS
C#
277
star
12

UnityInspectPlus

Speeding up your Inspector workflow in Unity 3D
C#
254
star
13

UnityImageCropper

A uGUI based image cropping solution for Unity 3D
C#
207
star
14

UnityAndroidRuntimePermissions

A native Unity plugin to handle runtime permissions on Android M+
C#
194
star
15

UnityRuntimeSceneGizmo

Interactable runtime scene gizmo for uGUI
C#
175
star
16

UnitySimplePatchTool

Unity port of SimplePatchTool library to add patching support to standalone Unity applications
C#
163
star
17

UnityAdjustPivot

Adjust pivot point of an object in Unity without creating an empty parent object
C#
149
star
18

Unity360ScreenshotCapture

A simple script to capture 360ยฐ screenshots in-game with Unity
C#
142
star
19

SimplePatchTool

C# library for patching standalone applications with binary diff and self patching support
C#
132
star
20

UnityTextToTextMeshProUpgradeTool

Upgrade Text, InputField, Dropdown and TextMesh objects to their TextMesh Pro variants in Unity
C#
113
star
21

DownloadLinkGeneratorForGoogleDrive

Create list of files and their download links in a Google Driveโ„ข folder
HTML
109
star
22

UnityIonicIntegration

A guide to integrating Unity 3D content into an Ionic app and sending messages between them (for Android & iOS)(tested with Vuforia plugin)
Objective-C++
104
star
23

UnityMobileLocalizedAppTitle

Localize your Unity app's name and/or icon on Android & iOS
C#
102
star
24

UnityGridFramework

Open source Grid Framework for creating grid-based levels easily in Unity 3D
C#
94
star
25

UnitySimpleGDPRConsent

A Unity plugin to present GDPR consent dialogs to the users
C#
93
star
26

UnityTextureOps

A basic image processing plugin for Unity
C#
87
star
27

UnityChoiceOfGamesSaveManager

Save manager for 'Choice of Games' on Steam - Created with Unity 3D
C#
76
star
28

UnitySpeechToText

A native Unity plugin to convert speech to text on Android & iOS
C#
70
star
29

UnityRuntimeTexture

An abstraction layer on top of Texture2D.LoadImage to create Texture2D objects at runtime from raw PNG/JPEG data in Unity
C#
62
star
30

UnityDashedSpriteShape

Creating dashed (dotted) 2D Sprite Shapes in Unity
ShaderLab
62
star
31

UnityMobileRemoteControl

Control your Windows device from your phone
C#
59
star
32

UnityEditorGoogleDriveIntegration

Access your Google Driveโ„ข files from within Unity editor
C#
48
star
33

UnityHexicGame

Hexic puzzle game made with Unity 3D
ShaderLab
36
star
34

UnityGenericPool

A simple generic pooling script for Unity3D with a helper class
C#
36
star
35

UnitySpinningLoadingBars

3 different spinning loading bar prefabs for Unity's UI system
28
star
36

UnityFlatColorPalettes

A number of flat color palettes for Unity 3D
26
star
37

UnityEveryplaySaveToLocal

A helper script to save captured Everyplay videos to local file system on Android & iOS
Objective-C++
15
star
38

UnityOrderedUpdate

Receive Update callback(s) from anywhere and in any order in Unity!
C#
15
star
39

UnityAndroidStreamingAssets

A helper script to extract StreamingAssets to local file system on Unity Android
C#
10
star
40

DownloadLinkGeneratorForDropbox

Create list of files and their download links in a Dropbox folder
HTML
6
star
41

SecondHand

Global Game Jam entry
C#
5
star
42

GeometricSketchpadProject

Bilkent CS102 Course Project
Java
4
star
43

GreenHellMods

A number of mods created via ModAPI for Green Hell game
C#
4
star
44

.github

Default GitHub community health files for all my repositories
2
star
45

BubblesProject

Bilkent CS319 Course Project
Java
2
star