using EasyTalk.Controller;
using System.Collections;
using UnityEngine;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif
namespace EasyTalk.Demo
{
///
/// Handles player controls for going into a dialogue with a character.
///
public class DialogueControls : MonoBehaviour
{
#if ENABLE_INPUT_SYSTEM
///
/// The Input Action Asset to use for player input controls.
///
[SerializeField]
private InputActionAsset inputActions;
#endif
///
/// Whether the controls are ready to call PlayDialogue() on a controller.
///
private bool isReady = false;
///
/// The Dialogue Controller to call PlayDialogue() on when the player presses the right input control button.
///
private DialogueController controller;
private void Awake()
{
#if ENABLE_INPUT_SYSTEM
InputAction startDialogueAction = inputActions["EnterDialogue"];
if (startDialogueAction != null)
{
startDialogueAction.performed += delegate
{
Play();
};
}
#endif
}
// Update is called once per frame
void Update()
{
#if !ENABLE_INPUT_SYSTEM
if(Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.Return) || Input.GetButtonDown("Submit"))
{
Play();
}
#endif
}
///
/// Calls PlayDialogue() on the set Dialogue Controller.
///
private void Play()
{
if (isReady && controller != null)
{
isReady = false;
controller.PlayDialogue();
}
}
///
/// Prepares the controls to call PlayDialogue() on the specified Dialogue Controller.
///
/// The Dialogue Controller to get ready to play.
public void ReadyController(DialogueController controller)
{
isReady = true;
this.controller = controller;
}
///
/// Sets the controls not to trigger any controller.
///
public void UnreadyController()
{
isReady = false;
this.controller = null;
}
}
}