浏览代码

Fixed event for interaction pick up

/main
Amel 4 年前
当前提交
525d3f4e
共有 4 个文件被更改,包括 21 次插入16 次删除
  1. 2
      UOP1_Project/Assets/Scripts/Events/ScriptableObjects/ItemEventChannelSo.cs
  2. 20
      UOP1_Project/Assets/Scripts/Events/ScriptableObjects/UI/ItemTypeEvent.cs
  3. 10
      UOP1_Project/Assets/Scripts/Interaction/InteractionManager.cs
  4. 5
      UOP1_Project/Assets/Scripts/Inventory/CollectibleItem.cs

2
UOP1_Project/Assets/Scripts/Events/ScriptableObjects/ItemEventChannelSo.cs


/// Example: Pick up an item passed as paramater
/// </summary>
[CreateAssetMenu(menuName = "Events/Dialogue Event Channel")]
[CreateAssetMenu(menuName = "Events/UI/Item Event Channel")]
public class ItemEventChannelSo : ScriptableObject
{
public UnityAction<Item> OnEventRaised;

20
UOP1_Project/Assets/Scripts/Events/ScriptableObjects/UI/ItemTypeEvent.cs


using UnityEngine;
using UnityEngine.Events;
[CreateAssetMenu(fileName = "itemTypeEvent", menuName = "UI Event/itemTypeEvent")]
public class ItemTypeEvent : ScriptableObject
{
//[CreateAssetMenu(fileName = "itemTypeEvent", menuName = "UI Event/itemTypeEvent")]
//public class ItemTypeEvent : ScriptableObject
//{
public UnityAction<ItemType> eventRaised;
public void Raise(ItemType itemType)
{
if (eventRaised != null)
eventRaised.Invoke(itemType);
}
// public UnityAction<ItemType> eventRaised;
// public void Raise(ItemType itemType)
// {
// if (eventRaised != null)
// eventRaised.Invoke(itemType);
// }
}
//}

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


//Events for the different interaction types
[Header("Broadcasting on")]
[SerializeField] private GameObjectEventChannelSO _onObjectPickUp = default;
[SerializeField] private ItemEventChannelSo _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 DialogueEventChannelSo _startTalking = default;

if (_currentInteractableObject != null)
{
//raise an event with an item as parameter (to add object to inventory)
//Item currentItem = currentInteractableObject.GetComponent<Pickable>.item;
//_onObjectPickUp.RaiseEvent(currentItem);
Item currentItem = _currentInteractableObject.GetComponent<CollectibleItem>().GetItem();
_onObjectPickUp.RaiseEvent(currentItem);
Debug.Log("PickUp event raised");
//set current interaction for state machine
currentInteraction = Interaction.PickUp;

if (_currentInteractableObject != null)
{
//raise an event with an actor as parameter
//Item currentItem = currentInteractableObject.GetComponent<Dialogue>.Actor;
//_startTalking.RaiseEvent(currentItem);
//Actor currentActor = currentInteractableObject.GetComponent<Dialogue>().GetActor();
//_startTalking.RaiseEvent(currentActor);
Debug.Log("talk event raised");
//Change the action map
_inputReader.EnableDialogueInput();

5
UOP1_Project/Assets/Scripts/Inventory/CollectibleItem.cs


}
public Item GetItem()
{
return currentItem;
}
//this function is only for testing
public void SetItem()
{

正在加载...
取消
保存