|
|
|
|
|
|
|
|
|
|
public class InteractionManager : MonoBehaviour |
|
|
|
{ |
|
|
|
public Interaction _interaction; |
|
|
|
public InputReader inputReader; |
|
|
|
private Interaction _interaction; |
|
|
|
[SerializeField] private InputReader _inputReader = default; |
|
|
|
GameObject currentInteractableObject = null; |
|
|
|
private GameObject _currentInteractableObject = null; |
|
|
|
//Or do we want to have stg specific for every type of interaction like:
|
|
|
|
//Item for pickup?
|
|
|
|
//Character (or other relevant type) for talk?
|
|
|
|
|
|
|
[Header("Broadcasting on")] |
|
|
|
[SerializeField] private GameObjectEventChannelSO _OnObjectPickUp = default; |
|
|
|
[SerializeField] private GameObjectEventChannelSO _onObjectPickUp = default; |
|
|
|
[SerializeField] private VoidEventChannelSO _OnCookingStart = default; |
|
|
|
[SerializeField] private GameObjectEventChannelSO _StartTalking = default; |
|
|
|
[SerializeField] private VoidEventChannelSO _onCookingStart = default; |
|
|
|
[SerializeField] private GameObjectEventChannelSO _startTalking = default; |
|
|
|
[SerializeField] private InteractionUIEventChannelSO _ToggleInteractionUI = default; |
|
|
|
//Check if the interaction ended
|
|
|
|
[SerializeField] private VoidEventChannelSO _InteractionEnded = default; |
|
|
|
[SerializeField] private InteractionUIEventChannelSO _toggleInteractionUI = default; |
|
|
|
[Header("Listening to")] |
|
|
|
//Check if the interaction ended
|
|
|
|
[SerializeField] private VoidEventChannelSO _onInteractionEnded = default; |
|
|
|
inputReader.interactEvent += OnInteractionButtonPress; |
|
|
|
_InteractionEnded.OnEventRaised += OnInteractionEnd; |
|
|
|
_inputReader.interactEvent += OnInteractionButtonPress; |
|
|
|
_onInteractionEnded.OnEventRaised += OnInteractionEnd; |
|
|
|
inputReader.interactEvent -= OnInteractionButtonPress; |
|
|
|
_InteractionEnded.OnEventRaised -= OnInteractionEnd; |
|
|
|
_inputReader.interactEvent -= OnInteractionButtonPress; |
|
|
|
_onInteractionEnded.OnEventRaised -= OnInteractionEnd; |
|
|
|
inputReader.EnableGameplayInput(); |
|
|
|
_inputReader.EnableGameplayInput(); |
|
|
|
//We don't show the interaction UI when we already picked up the object
|
|
|
|
case Interaction.None: |
|
|
|
case Interaction.PickUp: |
|
|
|
return; |
|
|
|
_ToggleInteractionUI.RaiseEvent(true, _interaction); |
|
|
|
_toggleInteractionUI.RaiseEvent(true, _interaction); |
|
|
|
Debug.Log("Display interaction UI"); |
|
|
|
break; |
|
|
|
default: |
|
|
|
|
|
|
case Interaction.None: |
|
|
|
return; |
|
|
|
case Interaction.PickUp: |
|
|
|
if(currentInteractableObject != null) |
|
|
|
if(_currentInteractableObject != null) |
|
|
|
//pass the item SO to the UI?
|
|
|
|
_OnObjectPickUp.RaiseEvent(currentInteractableObject); |
|
|
|
//pass the item SO to the UI? we do it once we merge with inventory stuff
|
|
|
|
//Item currentItem = currentInteractableObject.GetComponent<Pickable>.item;
|
|
|
|
_onObjectPickUp.RaiseEvent(_currentInteractableObject); |
|
|
|
//bool for SM
|
|
|
|
|
|
|
|
Destroy(_currentInteractableObject); |
|
|
|
_OnCookingStart.RaiseEvent(); |
|
|
|
_onCookingStart.RaiseEvent(); |
|
|
|
//inputReader.EnableUIInput();
|
|
|
|
_inputReader.EnableUIInput(); |
|
|
|
if (currentInteractableObject != null) |
|
|
|
if (_currentInteractableObject != null) |
|
|
|
_StartTalking.RaiseEvent(currentInteractableObject); |
|
|
|
//raise an event with an actor: DialogueEventChannelSo
|
|
|
|
_startTalking.RaiseEvent(_currentInteractableObject); |
|
|
|
inputReader.EnableDialogueInput(); |
|
|
|
_inputReader.EnableDialogueInput(); |
|
|
|
} |
|
|
|
break; |
|
|
|
default: |
|
|
|
|
|
|
Debug.Log("I triggered an NPC!"); |
|
|
|
DisplayInteractionUI(); |
|
|
|
} |
|
|
|
currentInteractableObject = other.gameObject; |
|
|
|
_currentInteractableObject = other.gameObject; |
|
|
|
_ToggleInteractionUI.RaiseEvent(true, _interaction); |
|
|
|
_toggleInteractionUI.RaiseEvent(true, _interaction); |
|
|
|
} |
|
|
|
|
|
|
|
private void OnTriggerExit(Collider other) |
|
|
|
|
|
|
private void ResetInteraction() |
|
|
|
{ |
|
|
|
_interaction = Interaction.None; |
|
|
|
currentInteractableObject = null; |
|
|
|
_currentInteractableObject = null; |
|
|
|
|
|
|
|
|
|
|
|
//Do we need to detect the button press first of the trigger first
|
|
|
|
//If we detect trigger first, to destroy the object later we need to keep a ref
|
|
|
|
|
|
|
|
|
|
|
|
//I think the dialogue and UI should switch the action maps? for now I do here but maybe to change later
|