|
|
|
|
|
|
public Interaction _interaction; |
|
|
|
public InputReader inputReader; |
|
|
|
//To store the object we are currently interacting with
|
|
|
|
GameObject currentInteractableObject; |
|
|
|
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?
|
|
|
|
|
|
|
[SerializeField] private GameObjectEventChannelSO _StartTalking = default; |
|
|
|
//UI event
|
|
|
|
[SerializeField] private InteractionUIEventChannelSO _ToggleInteractionUI = default; |
|
|
|
|
|
|
|
//Check if the interaction ended
|
|
|
|
[SerializeField] private VoidEventChannelSO _InteractionEnded = default; |
|
|
|
_InteractionEnded.OnEventRaised += OnInteractionEnd; |
|
|
|
_InteractionEnded.OnEventRaised -= OnInteractionEnd; |
|
|
|
} |
|
|
|
|
|
|
|
//When the interaction ends, we still want to display the interaction UI if we are still in the trigger zone
|
|
|
|
void OnInteractionEnd() |
|
|
|
{ |
|
|
|
inputReader.EnableGameplayInput(); |
|
|
|
switch (_interaction) |
|
|
|
{ |
|
|
|
//We don't show the interaction UI when we already picked up the object
|
|
|
|
case Interaction.None: |
|
|
|
case Interaction.PickUp: |
|
|
|
return; |
|
|
|
//we show it after cooking or talking, in case player want to interact again
|
|
|
|
case Interaction.Cook: |
|
|
|
case Interaction.Talk: |
|
|
|
_ToggleInteractionUI.RaiseEvent(true, _interaction); |
|
|
|
Debug.Log("Display interaction UI"); |
|
|
|
break; |
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void OnInteractionButtonPress() |
|
|
|
|
|
|
case Interaction.None: |
|
|
|
return; |
|
|
|
case Interaction.PickUp: |
|
|
|
//Maybe better add check if gb not null here?
|
|
|
|
//pass the item SO to the UI
|
|
|
|
if(currentInteractableObject != null) |
|
|
|
{ |
|
|
|
//pass the item SO to the UI?
|
|
|
|
_OnObjectPickUp.RaiseEvent(currentInteractableObject); |
|
|
|
Debug.Log("PickUp event raised"); |
|
|
|
} |
|
|
|
|
|
|
|
//Change the action map
|
|
|
|
_OnObjectPickUp.RaiseEvent(currentInteractableObject); |
|
|
|
Debug.Log("PickUp event raised"); |
|
|
|
//Change the action map
|
|
|
|
//inputReader.EnableUIInput();
|
|
|
|
_StartTalking.RaiseEvent(currentInteractableObject); |
|
|
|
Debug.Log("talk event raised"); |
|
|
|
if (currentInteractableObject != null) |
|
|
|
{ |
|
|
|
_StartTalking.RaiseEvent(currentInteractableObject); |
|
|
|
Debug.Log("talk event raised"); |
|
|
|
//Change the action map
|
|
|
|
inputReader.EnableDialogueInput(); |
|
|
|
} |
|
|
|
//ResetInteraction();
|
|
|
|
|
|
|
|
|
|
|
|
private void OnTriggerEnter(Collider other) |
|
|
|
{ |
|
|
|
|
|
|
currentInteractableObject = other.gameObject; |
|
|
|
//Raise event to display UI
|
|
|
|
_ToggleInteractionUI.RaiseEvent(true, _interaction); |
|
|
|
DisplayInteractionUI(); |
|
|
|
//Raise event to display UI or have a ref de display it from here
|
|
|
|
DisplayInteractionUI(); |
|
|
|
currentInteractableObject = other.gameObject; |
|
|
|
//Raise event to display UI or have a ref de display it from here
|
|
|
|
DisplayInteractionUI(); |
|
|
|
currentInteractableObject = other.gameObject; |
|
|
|
} |
|
|
|
|
|
|
|
private void DisplayInteractionUI () |
|
|
|
{ |
|
|
|
//Raise event to display UI
|
|
|
|
_ToggleInteractionUI.RaiseEvent(true, _interaction); |
|
|
|
} |
|
|
|
|
|
|
|
private void OnTriggerExit(Collider other) |
|
|
|
|
|
|
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
|