浏览代码

Added interaction manager script

/main
Amel Negra 4 年前
当前提交
71caefa9
共有 2 个文件被更改,包括 100 次插入0 次删除
  1. 89
      UOP1_Project/Assets/InteractionManager.cs
  2. 11
      UOP1_Project/Assets/InteractionManager.cs.meta

89
UOP1_Project/Assets/InteractionManager.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
//Enum of the possible Interaction types, we can add later if needed
//None is the default value as its value is '0'
enum Interaction { None = 0,PickUp, Cook, Talk};
public class InteractionManager : MonoBehaviour
{
public InputReader inputReader;
private Interaction _interactionType;
//To store the object we are currently interacting with
GameObject currentInteractableObject;
//Events for the different interaction types
[Header("Broadcasting on")]
[SerializeField] private GameObjectEventChannelSO _OnObjectPickUp = default;
//double check with the action name we will show on the UI (because we will not really starting cooking but showing the UI?)
[SerializeField] private VoidEventChannelSO _OnCookingStart = default;
[SerializeField] private GameObjectEventChannelSO _StartTalking = default;
private void OnEnable()
{
inputReader.interactEvent += OnInteractionButtonPress;
}
private void OnDisable()
{
inputReader.interactEvent -= OnInteractionButtonPress;
}
void OnInteractionButtonPress()
{
switch (_interactionType)
{
case Interaction.None:
return;
case Interaction.PickUp:
_OnObjectPickUp.RaiseEvent(currentInteractableObject);
Debug.Log("PickUp event raised");
break;
case Interaction.Cook:
_OnCookingStart.RaiseEvent();
Debug.Log("Cooking event raised");
break;
case Interaction.Talk:
_StartTalking.RaiseEvent(currentInteractableObject);
Debug.Log("talk event raised");
break;
default:
break;
}
ResetInteraction();
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Pickable "))
{
_interactionType = Interaction.PickUp;
currentInteractableObject = other.gameObject;
}
else if (other.CompareTag("CookingPot"))
{
_interactionType = Interaction.Cook;
}
else if (other.CompareTag("NPC"))
{
_interactionType = Interaction.Talk;
currentInteractableObject = other.gameObject;
}
}
private void OnTriggerExit(Collider other)
{
ResetInteraction();
}
private void ResetInteraction()
{
_interactionType = Interaction.None;
currentInteractableObject = null;
}
}

11
UOP1_Project/Assets/InteractionManager.cs.meta


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