Ciro Continisio
4 年前
当前提交
b8b709a6
共有 9 个文件被更改,包括 543 次插入 和 78 次删除
-
188Assets/Scenes/CharController.unity
-
29Assets/Scripts/Protagonist.cs
-
130Assets/Settings/Input/GameInput.cs
-
120Assets/Settings/Input/GameInput.inputactions
-
2ProjectSettings/QualitySettings.asset
-
2Assets/Scripts/InputReader.cs.meta
-
88Assets/Scripts/InputReader.cs
-
62Assets/Tests/Input/InputTesting.cs
-
0/Assets/Scripts/InputReader.cs.meta
|
|||
using System.Collections; |
|||
using System; |
|||
using System.Collections; |
|||
|
|||
public InputReader inputReader; |
|||
|
|||
//Adds listeners for events being triggered in the InputReader script
|
|||
private void OnEnable() |
|||
{ |
|||
inputReader.jumpEvent += OnJump; |
|||
inputReader.moveEvent += OnMove; |
|||
//...
|
|||
} |
|||
|
|||
//Removes all listeners to the events coming from the InputReader script
|
|||
private void OnDisable() |
|||
{ |
|||
//...
|
|||
} |
|||
|
|||
private void OnMove(Vector2 movement) |
|||
{ |
|||
Debug.Log("Move " + movement); |
|||
} |
|||
|
|||
private void OnJump() |
|||
{ |
|||
Debug.Log("JUMP"); |
|||
} |
|||
} |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEngine.InputSystem; |
|||
using UnityEngine.Events; |
|||
|
|||
public class InputReader : MonoBehaviour, GameInput.IGameplayActions |
|||
{ |
|||
public UnityAction jumpEvent; |
|||
public UnityAction attackEvent; |
|||
public UnityAction interactEvent; |
|||
public UnityAction extraActionEvent; |
|||
public UnityAction pauseEvent; |
|||
public UnityAction<Vector2> moveEvent; |
|||
public UnityAction<Vector2> cameraMoveEvent; |
|||
|
|||
GameInput gameInput; |
|||
|
|||
private void OnEnable() |
|||
{ |
|||
if(gameInput == null) |
|||
{ |
|||
gameInput = new GameInput(); |
|||
gameInput.Gameplay.SetCallbacks(this); |
|||
} |
|||
gameInput.Gameplay.Enable(); |
|||
|
|||
//Debug.Log("I'm enabled");
|
|||
} |
|||
|
|||
private void OnDisable() |
|||
{ |
|||
gameInput.Gameplay.Disable(); |
|||
} |
|||
|
|||
public void OnAttack(InputAction.CallbackContext context) |
|||
{ |
|||
if(attackEvent != null |
|||
&& context.phase == InputActionPhase.Started) |
|||
attackEvent.Invoke(); |
|||
} |
|||
|
|||
public void OnExtraAction(InputAction.CallbackContext context) |
|||
{ |
|||
if(extraActionEvent != null |
|||
&& context.phase == InputActionPhase.Started) |
|||
extraActionEvent.Invoke(); |
|||
} |
|||
|
|||
public void OnInteract(InputAction.CallbackContext context) |
|||
{ |
|||
if(interactEvent != null |
|||
&& context.phase == InputActionPhase.Started) |
|||
interactEvent.Invoke(); |
|||
} |
|||
|
|||
public void OnJump(InputAction.CallbackContext context) |
|||
{ |
|||
if(jumpEvent != null |
|||
&& context.phase == InputActionPhase.Started) |
|||
jumpEvent.Invoke(); |
|||
} |
|||
|
|||
public void OnMove(InputAction.CallbackContext context) |
|||
{ |
|||
if(moveEvent != null |
|||
&& context.phase == InputActionPhase.Performed) |
|||
{ |
|||
moveEvent.Invoke(context.ReadValue<Vector2>()); |
|||
} |
|||
} |
|||
|
|||
public void OnPause(InputAction.CallbackContext context) |
|||
{ |
|||
if(pauseEvent != null |
|||
&& context.phase == InputActionPhase.Started) |
|||
pauseEvent.Invoke(); |
|||
} |
|||
|
|||
public void OnRotateCamera(InputAction.CallbackContext context) |
|||
{ |
|||
if(cameraMoveEvent != null |
|||
&& context.phase == InputActionPhase.Performed) |
|||
{ |
|||
cameraMoveEvent.Invoke(context.ReadValue<Vector2>()); |
|||
} |
|||
} |
|||
} |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEngine.InputSystem; |
|||
|
|||
public class InputTesting : MonoBehaviour, GameInput.IGameplayActions |
|||
{ |
|||
GameInput gameInput; |
|||
|
|||
private void OnEnable() |
|||
{ |
|||
if(gameInput == null) |
|||
{ |
|||
gameInput = new GameInput(); |
|||
gameInput.Gameplay.SetCallbacks(this); |
|||
} |
|||
gameInput.Gameplay.Enable(); |
|||
|
|||
Debug.Log("I'm enabled"); |
|||
} |
|||
|
|||
private void OnDisable() |
|||
{ |
|||
gameInput.Gameplay.Disable(); |
|||
} |
|||
|
|||
public void OnAttack(InputAction.CallbackContext context) |
|||
{ |
|||
if(context.phase == InputActionPhase.Started) |
|||
Debug.Log("Attack"); |
|||
} |
|||
|
|||
public void OnExtraAction(InputAction.CallbackContext context) |
|||
{ |
|||
if(context.phase == InputActionPhase.Started) |
|||
Debug.Log("ExtraAction"); |
|||
} |
|||
|
|||
public void OnInteract(InputAction.CallbackContext context) |
|||
{ |
|||
if(context.phase == InputActionPhase.Started) |
|||
Debug.Log("Interact"); |
|||
} |
|||
|
|||
public void OnJump(InputAction.CallbackContext context) |
|||
{ |
|||
if(context.phase == InputActionPhase.Started) |
|||
Debug.Log("Jump"); |
|||
} |
|||
|
|||
public void OnMove(InputAction.CallbackContext context) |
|||
{ |
|||
if(context.phase == InputActionPhase.Performed) |
|||
Debug.Log("Move " + context.ReadValue<Vector2>()); |
|||
} |
|||
|
|||
public void OnPause(InputAction.CallbackContext context) |
|||
{ |
|||
if(context.phase == InputActionPhase.Started) |
|||
Debug.Log("Pause"); |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue