浏览代码

Added support to multiple overlapping interactions (#301)

* Added support to multiple overlapping interactions

* Changed Stack for LinkedList
/devlogs-3-input
GitHub 4 年前
当前提交
f29b25de
共有 3 个文件被更改,包括 87 次插入45 次删除
  1. 106
      UOP1_Project/Assets/Scripts/Interaction/InteractionManager.cs
  2. 15
      UOP1_Project/Assets/Scripts/Interaction/Interaction.cs
  3. 11
      UOP1_Project/Assets/Scripts/Interaction/Interaction.cs.meta

106
UOP1_Project/Assets/Scripts/Interaction/InteractionManager.cs


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);
}
}
}

15
UOP1_Project/Assets/Scripts/Interaction/Interaction.cs


using UnityEngine;
public class Interaction
{
public static Interaction NONE = new Interaction(InteractionType.None, null);
public InteractionType Type;
public GameObject InteractableObject;
public Interaction(InteractionType type, GameObject obj)
{
this.Type = type;
this.InteractableObject = obj;
}
}

11
UOP1_Project/Assets/Scripts/Interaction/Interaction.cs.meta


fileFormatVersion: 2
guid: 56bf9afc5c235484787b6bad85a5bbf8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存