|
|
|
|
|
|
using UnityEngine; |
|
|
|
using System.Collections.Generic; |
|
|
|
private InteractionType _potentialInteraction; |
|
|
|
private GameObject _currentInteractableObject = null; |
|
|
|
private LinkedList<Interaction> _ongoingInteractions = new LinkedList<Interaction>(); |
|
|
|
|
|
|
|
//Events for the different interaction types
|
|
|
|
[Header("Broadcasting on")] |
|
|
|
|
|
|
void OnInteractionEnd() |
|
|
|
{ |
|
|
|
_inputReader.EnableGameplayInput(); |
|
|
|
switch (_potentialInteraction) |
|
|
|
Interaction onGoingInteraction = _ongoingInteractions.First.Value; |
|
|
|
switch (onGoingInteraction.Type) |
|
|
|
_toggleInteractionUI.RaiseEvent(true, _potentialInteraction); |
|
|
|
_toggleInteractionUI.RaiseEvent(true, onGoingInteraction.Type); |
|
|
|
Debug.Log("Display interaction UI"); |
|
|
|
break; |
|
|
|
default: |
|
|
|
|
|
|
|
|
|
|
void OnInteractionButtonPress() |
|
|
|
{ |
|
|
|
//remove interaction after press
|
|
|
|
_toggleInteractionUI.RaiseEvent(false, _potentialInteraction); |
|
|
|
|
|
|
|
switch (_potentialInteraction) |
|
|
|
//remove interaction after press
|
|
|
|
Interaction onGoingInteraction = _ongoingInteractions.Count > 0 ? |
|
|
|
_ongoingInteractions.First.Value : Interaction.NONE; |
|
|
|
_toggleInteractionUI.RaiseEvent(false, onGoingInteraction.Type); |
|
|
|
switch (onGoingInteraction.Type) |
|
|
|
if (_currentInteractableObject != null) |
|
|
|
GameObject itemObject = onGoingInteraction.InteractableObject; |
|
|
|
_ongoingInteractions.RemoveFirst(); |
|
|
|
if (_onObjectPickUp != null) |
|
|
|
if (_onObjectPickUp != null) |
|
|
|
{ |
|
|
|
//raise an event with an item as parameter (to add object to inventory)
|
|
|
|
Item currentItem = _currentInteractableObject.GetComponent<CollectibleItem>().GetItem(); |
|
|
|
_onObjectPickUp.RaiseEvent(currentItem); |
|
|
|
Debug.Log("PickUp event raised"); |
|
|
|
//set current interaction for state machine
|
|
|
|
currentInteraction = InteractionType.PickUp; |
|
|
|
} |
|
|
|
//raise an event with an item as parameter (to add object to inventory)
|
|
|
|
Item currentItem = itemObject.GetComponent<CollectibleItem>().GetItem(); |
|
|
|
_onObjectPickUp.RaiseEvent(currentItem); |
|
|
|
//Debug.Log("PickUp event raised");
|
|
|
|
//set current interaction for state machine
|
|
|
|
currentInteraction = InteractionType.PickUp; |
|
|
|
Destroy(_currentInteractableObject); |
|
|
|
Destroy(itemObject); |
|
|
|
Debug.Log("Cooking event raised"); |
|
|
|
//Debug.Log("Cooking event raised");
|
|
|
|
//Change the action map
|
|
|
|
_inputReader.EnableMenuInput(); |
|
|
|
//set current interaction for state machine
|
|
|
|
|
|
|
case InteractionType.Talk: |
|
|
|
if (_currentInteractableObject != null) |
|
|
|
if (_onCookingStart != null) |
|
|
|
if (_onCookingStart != null) |
|
|
|
{ |
|
|
|
//raise an event with an actor as parameter
|
|
|
|
//Actor currentActor = currentInteractableObject.GetComponent<Dialogue>().GetActor();
|
|
|
|
//_startTalking.RaiseEvent(currentActor);
|
|
|
|
Debug.Log("talk event raised"); |
|
|
|
//Change the action map
|
|
|
|
_inputReader.EnableDialogueInput(); |
|
|
|
//set current interaction for state machine
|
|
|
|
currentInteraction = InteractionType.Talk; |
|
|
|
} |
|
|
|
//raise an event with an actor as parameter
|
|
|
|
//Actor currentActor = currentInteractableObject.GetComponent<Dialogue>().GetActor();
|
|
|
|
//_startTalking.RaiseEvent(currentActor);
|
|
|
|
//Debug.Log("talk event raised");
|
|
|
|
//Change the action map
|
|
|
|
_inputReader.EnableDialogueInput(); |
|
|
|
//set current interaction for state machine
|
|
|
|
currentInteraction = InteractionType.Talk; |
|
|
|
} |
|
|
|
break; |
|
|
|
default: |
|
|
|
|
|
|
|
|
|
|
private void OnTriggerEnter(Collider other) |
|
|
|
{ |
|
|
|
InteractionType ongoingInteractionType = InteractionType.None; |
|
|
|
|
|
|
|
_potentialInteraction = InteractionType.PickUp; |
|
|
|
ongoingInteractionType = InteractionType.PickUp; |
|
|
|
DisplayInteractionUI(); |
|
|
|
_potentialInteraction = InteractionType.Cook; |
|
|
|
ongoingInteractionType = InteractionType.Cook; |
|
|
|
DisplayInteractionUI(); |
|
|
|
_potentialInteraction = InteractionType.Talk; |
|
|
|
ongoingInteractionType = InteractionType.Talk; |
|
|
|
} |
|
|
|
if (ongoingInteractionType != InteractionType.None) |
|
|
|
{ |
|
|
|
_ongoingInteractions.AddFirst(new Interaction(ongoingInteractionType, other.gameObject)); |
|
|
|
_currentInteractableObject = other.gameObject; |
|
|
|
_toggleInteractionUI.RaiseEvent(true, _potentialInteraction); |
|
|
|
Interaction onGoingInteraction = _ongoingInteractions.First.Value; |
|
|
|
_toggleInteractionUI.RaiseEvent(true, onGoingInteraction.Type); |
|
|
|
ResetInteraction(); |
|
|
|
ResetInteraction(other.gameObject); |
|
|
|
private void ResetInteraction() |
|
|
|
private void ResetInteraction(GameObject obj) |
|
|
|
_potentialInteraction = InteractionType.None; |
|
|
|
_currentInteractableObject = null; |
|
|
|
LinkedListNode<Interaction> currentNode = _ongoingInteractions.First; |
|
|
|
while (currentNode != null) |
|
|
|
{ |
|
|
|
if (currentNode.Value.InteractableObject == obj) |
|
|
|
{ |
|
|
|
_ongoingInteractions.Remove(currentNode); |
|
|
|
break; |
|
|
|
} |
|
|
|
currentNode = currentNode.Next; |
|
|
|
} |
|
|
|
if (_toggleInteractionUI != null) |
|
|
|
_toggleInteractionUI.RaiseEvent(false, _potentialInteraction); |
|
|
|
if (_ongoingInteractions.Count > 0) |
|
|
|
{ |
|
|
|
_toggleInteractionUI.RaiseEvent(true, _ongoingInteractions.First.Value.Type); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
_toggleInteractionUI.RaiseEvent(false, InteractionType.None); |
|
|
|
} |
|
|
|
} |
|
|
|
} |