浏览代码

updated interaction manager

/main
Amel 4 年前
当前提交
17dfe054
共有 5 个文件被更改,包括 108 次插入97 次删除
  1. 8
      UOP1_Project/Assets/Scripts/Interaction.meta
  2. 100
      UOP1_Project/Assets/Scripts/Interaction/InteractionManager.cs
  3. 97
      UOP1_Project/Assets/Scripts/InteractionManager.cs
  4. 0
      /UOP1_Project/Assets/Scripts/Interaction/InteractionManager.cs.meta

8
UOP1_Project/Assets/Scripts/Interaction.meta


fileFormatVersion: 2
guid: dd26117d5ec1dfe4eb1ee3f5905db64c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

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


using UnityEngine;
public enum Interaction { None = 0, PickUp, Cook, Talk };
public class InteractionManager : MonoBehaviour
{
public Interaction _interaction;
public InputReader inputReader;
//To store the object we are currently interacting with
GameObject currentInteractableObject;
//Or do we want to have stg specific for every type of interaction like:
//Item for pickup?
//Character (or other relevant type) for talk?
//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;
//UI event
[SerializeField] private InteractionUIEventChannelSO _ToggleInteractionUI = default;
private void OnEnable()
{
inputReader.interactEvent += OnInteractionButtonPress;
}
private void OnDisable()
{
inputReader.interactEvent -= OnInteractionButtonPress;
}
void OnInteractionButtonPress()
{
switch (_interaction)
{
case Interaction.None:
return;
case Interaction.PickUp:
//Maybe better add check if gb not null here?
//pass the item SO to the UI
//destroy the GO
//Change the action map
_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"))
{
_interaction = Interaction.PickUp;
currentInteractableObject = other.gameObject;
Debug.Log("I triggered a pickable object!");
//Raise event to display UI
_ToggleInteractionUI.RaiseEvent(true, _interaction);
}
else if (other.CompareTag("CookingPot"))
{
_interaction = Interaction.Cook;
//Raise event to display UI or have a ref de display it from here
Debug.Log("I triggered a cooking pot!");
}
else if (other.CompareTag("NPC"))
{
_interaction = Interaction.Talk;
currentInteractableObject = other.gameObject;
//Raise event to display UI or have a ref de display it from here
Debug.Log("I triggered an NPC!");
}
}
private void OnTriggerExit(Collider other)
{
ResetInteraction();
}
private void ResetInteraction()
{
_interaction = Interaction.None;
currentInteractableObject = null;
}
}

97
UOP1_Project/Assets/Scripts/InteractionManager.cs


using UnityEngine;
//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;
//Or do we want to have stg specefic for every type of interaction like:
//Item for pickup?
//Character (or other relevant type) for talk?
//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:
//Maybe better add check if gb not null here?
_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;
Debug.Log("I triggered a pickable object!");
//Raise event to display UI or have a ref de display it from here
}
else if (other.CompareTag("CookingPot"))
{
_interactionType = Interaction.Cook;
//Raise event to display UI or have a ref de display it from here
Debug.Log("I triggered a cooking pot!");
}
else if (other.CompareTag("NPC"))
{
_interactionType = Interaction.Talk;
currentInteractableObject = other.gameObject;
//Raise event to display UI or have a ref de display it from here
Debug.Log("I triggered an NPC!");
}
}
private void OnTriggerExit(Collider other)
{
ResetInteraction();
}
private void ResetInteraction()
{
_interactionType = Interaction.None;
currentInteractableObject = null;
}
}

/UOP1_Project/Assets/Scripts/InteractionManager.cs.meta → /UOP1_Project/Assets/Scripts/Interaction/InteractionManager.cs.meta

正在加载...
取消
保存