1. Unity Input System
1.1 The input detection unity of the virtual axis defines 15 Virtual Axes by default. You can open inputmanager through edit-> Project Settings-> input to view some attributes after the defined virtual axis (1) attribute size, such as horizontal and vertical. As the name suggests, this is the definition of the horizontal direction and the front and back direction (for the axial direction on the X axis ). Click the triangle next to horizontal to see a lot of content defined in it. For example, name indicates the name of the Virtual Axis,
Negative buttonIndicates the button (to the left) in the negative direction of the horizontal position ),
Positive buttonIndicates the button (to the right) in the Upper positive direction of the horizontal position ). The following two options with ALT are optional. Gravity indicates the speed at which the button is restored to the normal value. The larger the value, the faster it is. Dead indicates that the button has been reset when the value of the corresponding button is smaller than the value defined here. The Axis item defines the direction of the virtual axis, which can be the axis of the X axis or other multi-digit controls. (2) Call the input. getaxis method to obtain the current state value of the Virtual Axis. The range of values between-1 and 1 in the negative and positive directions of the Virtual Axis is. For example, getaxis ("horizontal"); at this time, if you press and hold the left button, this function returns-1, and restores it to 0 after it is released. If you press the right button, the function returns 1. Therefore, we can assume that the value between-1 and 0 is in the negative direction of the Virtual Axis. When the value is 0, nothing is pressed, between 0 and 1 is the positive direction of the Virtual Axis. Therefore, this value can be used as the value of transform or rotation to control the movement and rotation direction of an object, or to control the movement speed of an object as the intensity of keys. 1.2 mouse input detection for mouse detection. Mainly in the input class
Getmousebutton/
Getmousebuttondown/
GetmousebuttonupThe input parameter is 0/1/2, corresponding to the left mouse button/right-click/middle keyboard. The return value is bool, indicating whether the key is in this status. For example, when the left mouse button is pressed, the return value of getmousebuttondown (0) is true. Getmousebuttondown () is executed only once when the mouse is pressed. Getmousebutton () is always executed when the mouse stays on time. Getmousebuttonup () is executed only once when you release the mouse. 1.3 keyboard input detection keyboard detection, mainly for the input class
Getbuttondown/getbutton/getbuttonupAnd
Getkeydown/
Getkey/
GetkeyupTwo groups. The parameter of the getbutton group method is the name of the virtual axis, and the return value is of the bool type. You can detect the key state defined by the Virtual Axis, for example, the lef/right/A/D key is defined in the Virtual Axis "horizontal". When these keys are pressed, getbutton ("horizontal ") return the parameter of the truegetkey group method to be string or the enumeration type keycode defined by unity. For example, when primary key A is pressed, getkey (keycode. a) and the getkey ("A") return values are both true 1.4. The touch detection unity defines the enumeration type touchphasetouch. gettouch (0 ). phase returns the touch status of the last frame. Input. touchecount: the number of consecutive frames in a touch. Touch. deltaposition the last hop value. Only the XY coordinate is returned, which is generally received by vector2. 2. xgame input management system 2.1 inputmanagerinputmanager is responsible for detecting input from underlying devices and dispatching input events. (1) Defining the enumeration type inputstate indicates the current input (2) Enumeration type etouchphase indicates the input state of the previous frame (3) Enumeration type gestureevent indicates the identified input event (4) the inputevent class represents an input event and contains a gestureevent member. The specific subclass also defines its own data fields, such as touchevent defines the coordinates of touch points. (5) inputmanager defines a series of proxy types and defines the corresponding events. In the update () method of inputmanager, call gettouchphase to obtain the touch state (etouchphase) of the previous frame ), based on the current inputstate, determine and modify the input state, determine the input effect (gestureevent), obtain the corresponding data information, fill inputevent, and call raiseevent to dispatch events, the implementation of raiseevent is to execute different proxy methods based on the gestureevent enumeration value of the parameter. 2.2 inputdelegateinputdelegate manages the current input mode and registers various inputevent callback methods in the current mode with inputmanager based on the input mode. (1) define enumeration inputmodule to indicate the input mode in different game states (2) define the method subscribehandlersandevents to register the input mode to register the corresponding callback method (3) Corresponding unsubscribehandlersandevents logout callback
[Unity] Input System