You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
1.1 KiB
GDScript
28 lines
1.1 KiB
GDScript
extends Node3D
|
|
|
|
func _input(event) -> void:
|
|
if !event.is_action_type(): return
|
|
if event is InputEventKey:
|
|
if not Global.controller_type == Enum.EControllerType.Keyboard:
|
|
Global.controller_type = Enum.EControllerType.Keyboard
|
|
SignalManager.input_device_change.emit()
|
|
elif event is InputEventJoypadButton or event is InputEventJoypadMotion:
|
|
if not Global.controller_type == Enum.EControllerType.Joypad:
|
|
Global.controller_type = Enum.EControllerType.Joypad
|
|
SignalManager.input_device_change.emit()
|
|
else:
|
|
return
|
|
|
|
for action_name in InputMap.get_actions():
|
|
if event.is_action_pressed(action_name):
|
|
SignalManager.input_action_pressed.emit(action_name)
|
|
elif event.is_action_released(action_name):
|
|
SignalManager.input_action_released.emit(action_name)
|
|
var input_dir: Vector2 = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
|
# 限定为8方向
|
|
if input_dir.length() > 0:
|
|
# 计算角度并将其限制为45度的倍数
|
|
var angle = input_dir.angle()
|
|
var snapped_angle = round(angle / (PI / 4)) * (PI / 4)
|
|
input_dir = Vector2(cos(snapped_angle), sin(snapped_angle))
|
|
SignalManager.input_action_move.emit(input_dir) |