浏览代码

Dialogue system event fix (#162)

* changed input phase check to match best practices

* refactored system to go through input reader.  properly unsubscribing from events in dialogue system

* Nitpick on the naming

Co-authored-by: Ciro Continisio <ciro@unity3d.com>
/main
GitHub 4 年前
当前提交
e7a3f51c
共有 3 个文件被更改,包括 59 次插入30 次删除
  1. 30
      UOP1_Project/Assets/Scripts/Cutscenes/CutsceneManager.cs
  2. 2
      UOP1_Project/Assets/Scripts/Dialogues/DialogueManager.cs
  3. 57
      UOP1_Project/Assets/Scripts/Input/InputReader.cs

30
UOP1_Project/Assets/Scripts/Cutscenes/CutsceneManager.cs


using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Playables;
public class CutsceneManager : MonoBehaviour

private void OnEnable()
{
_inputReader.gameInput.Dialogues.AdvanceDialogue.performed += ctx => OnAdvance();
_inputReader.advanceDialogueEvent += OnAdvance;
_inputReader.gameInput.Dialogues.AdvanceDialogue.performed -= ctx => OnAdvance();
_inputReader.advanceDialogueEvent -= OnAdvance;
_inputReader.EnableDialogueInput();
_activePlayableDirector.stopped += ctx => CutsceneEnded();
EnableDialogueInput();
_activePlayableDirector.stopped += HandleDirectorStopped;
EnableGameplayInput();
if (_activePlayableDirector != null)
_activePlayableDirector.stopped -= HandleDirectorStopped;
_inputReader.EnableGameplayInput();
private void HandleDirectorStopped(PlayableDirector director) => CutsceneEnded();
public void PlayDialogueFromClip(DialogueLineSO dialogueLine)
{

{
_isPaused = false;
_activePlayableDirector.playableGraph.GetRootPlayable(0).SetSpeed(1);
}
private void EnableDialogueInput()
{
_inputReader.gameInput.Dialogues.Enable();
_inputReader.gameInput.Gameplay.Disable();
}
private void EnableGameplayInput()
{
_inputReader.gameInput.Gameplay.Enable();
_inputReader.gameInput.Dialogues.Disable();
}
}

2
UOP1_Project/Assets/Scripts/Dialogues/DialogueManager.cs


/// <param name="firstLine"></param>
public void BeginDialogue(DialogueLineSO firstLine)
{
_inputReader.gameInput.Dialogues.Enable();
_inputReader.EnableDialogueInput();
DisplayDialogueLine(firstLine);
}

57
UOP1_Project/Assets/Scripts/Input/InputReader.cs


using UnityEngine.Events;
[CreateAssetMenu(fileName = "InputReader", menuName = "Game/Input Reader")]
public class InputReader : ScriptableObject, GameInput.IGameplayActions
public class InputReader : ScriptableObject, GameInput.IGameplayActions, GameInput.IDialoguesActions
// gameplay
public event UnityAction jumpEvent;
public event UnityAction jumpCanceledEvent;
public event UnityAction attackEvent;

public event UnityAction enableMouseControlCameraEvent;
public event UnityAction disableMouseControlCameraEvent;
public GameInput gameInput;
// Dialogue
public event UnityAction advanceDialogueEvent = delegate { };
public event UnityAction onMoveSelectionEvent = delegate { };
private GameInput gameInput;
private void OnEnable()
{

gameInput.Gameplay.SetCallbacks(this);
gameInput.Dialogues.SetCallbacks(this);
gameInput.Gameplay.Enable();
EnableGameplayInput();
gameInput.Gameplay.Disable();
DisableAllInput();
&& context.phase == InputActionPhase.Performed)
&& context.phase == InputActionPhase.Performed)
attackEvent.Invoke();
}

&& context.phase == InputActionPhase.Performed)
&& context.phase == InputActionPhase.Performed)
extraActionEvent.Invoke();
}

&& context.phase == InputActionPhase.Performed)
&& context.phase == InputActionPhase.Performed)
interactEvent.Invoke();
}

&& context.phase == InputActionPhase.Performed)
&& context.phase == InputActionPhase.Performed)
&& context.phase == InputActionPhase.Canceled)
&& context.phase == InputActionPhase.Canceled)
jumpCanceledEvent.Invoke();
}

public void OnPause(InputAction.CallbackContext context)
{
if (pauseEvent != null
&& context.phase == InputActionPhase.Performed)
&& context.phase == InputActionPhase.Performed)
pauseEvent.Invoke();
}

if (context.phase == InputActionPhase.Canceled)
disableMouseControlCameraEvent?.Invoke();
}
private bool IsDeviceMouse(InputAction.CallbackContext context) => context.control.device.name == "Mouse";
public void OnMoveSelection(InputAction.CallbackContext context)
{
if (context.phase == InputActionPhase.Performed)
onMoveSelectionEvent();
private bool IsDeviceMouse(InputAction.CallbackContext context) => context.control.device.name == "Mouse";
public void OnAdvanceDialogue(InputAction.CallbackContext context)
{
if (context.phase == InputActionPhase.Performed)
advanceDialogueEvent();
}
public void EnableDialogueInput()
{
gameInput.Dialogues.Enable();
gameInput.Gameplay.Disable();
}
public void EnableGameplayInput()
{
gameInput.Gameplay.Enable();
gameInput.Dialogues.Disable();
}
public void DisableAllInput()
{
gameInput.Gameplay.Disable();
gameInput.Dialogues.Disable();
}
}
正在加载...
取消
保存