浏览代码

Added interaction events and updated interaction manager

/main
Amel 4 年前
当前提交
582ea351
共有 8 个文件被更改,包括 64 次插入60 次删除
  1. 17
      UOP1_Project/Assets/Prefabs/Characters/Pig/Interaction.prefab
  2. 26
      UOP1_Project/Assets/Prefabs/Characters/PigChef.prefab
  3. 4
      UOP1_Project/Assets/ScriptableObjects/Interaction/StartTalking.asset
  4. 2
      UOP1_Project/Assets/ScriptableObjects/Interaction/StartTalking.asset.meta
  5. 41
      UOP1_Project/Assets/Scripts/Interaction/InteractionManager.cs
  6. 12
      UOP1_Project/Assets/Scripts/Interaction/InteractionManager.cs.meta
  7. 14
      UOP1_Project/Assets/ScriptableObjects/Interaction/ToggleInteractUI.asset
  8. 8
      UOP1_Project/Assets/ScriptableObjects/Interaction/ToggleInteractUI.asset.meta

17
UOP1_Project/Assets/Prefabs/Characters/Pig/Interaction.prefab


m_IsTrigger: 1
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 0.3, y: 0.3, z: 1}
m_Center: {x: 0, y: 0.3, z: 0}
m_Size: {x: 0.3, y: 1, z: 1}
m_Center: {x: 0, y: 0.5, z: 0.8}
--- !u!114 &3466124848074566184
MonoBehaviour:
m_ObjectHideFlags: 0

m_Script: {fileID: 11500000, guid: a40d14d4203a8e14e9cc748b46975252, type: 3}
m_Name:
m_EditorClassIdentifier:
currentInteraction: 0
_onObjectPickUp: {fileID: 0}
_onCookingStart: {fileID: 0}
_startTalking: {fileID: 0}
_toggleInteractionUI: {fileID: 0}
_onInteractionEnded: {fileID: 0}
_onObjectPickUp: {fileID: 11400000, guid: f3027c4528b8e794f940a4696506f0c3, type: 2}
_onCookingStart: {fileID: 11400000, guid: 146c579dca5c2f248a607ef66a36d765, type: 2}
_startTalking: {fileID: 11400000, guid: bff3df361fa61684386f84b5b062875a, type: 2}
_toggleInteractionUI: {fileID: 11400000, guid: 818cc55cb05226248bdb15ace58eab84,
type: 2}
_onInteractionEnded: {fileID: 11400000, guid: c499d87f35465124f8fb2751b150430d,
type: 2}
--- !u!54 &1260543021480651504
Rigidbody:
m_ObjectHideFlags: 0

26
UOP1_Project/Assets/Prefabs/Characters/PigChef.prefab


propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3466124848074566184, guid: f8b7770f18df7614e90765b366548764,
type: 3}
propertyPath: _onObjectPickUp
value:
objectReference: {fileID: 11400000, guid: f3027c4528b8e794f940a4696506f0c3,
type: 2}
- target: {fileID: 3804461155661285315, guid: f8b7770f18df7614e90765b366548764,
type: 3}
propertyPath: m_Size.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3804461155661285315, guid: f8b7770f18df7614e90765b366548764,
type: 3}
propertyPath: m_Center.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 3804461155661285315, guid: f8b7770f18df7614e90765b366548764,
type: 3}
propertyPath: m_Center.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3804461155661285315, guid: f8b7770f18df7614e90765b366548764,
type: 3}
propertyPath: m_Center.z
value: 0.8
objectReference: {fileID: 0}
- target: {fileID: 7947030310713933739, guid: f8b7770f18df7614e90765b366548764,
type: 3}
propertyPath: m_Name

4
UOP1_Project/Assets/ScriptableObjects/Interaction/StartTalking.asset


m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1524e823eb557994daaaafcde7f7f309, type: 3}
m_Name: StartTalking
m_Script: {fileID: 11500000, guid: 72b8faf3c652eb74786b6fd69e28e7f3, type: 3}
m_Name: Start
m_EditorClassIdentifier:

2
UOP1_Project/Assets/ScriptableObjects/Interaction/StartTalking.asset.meta


fileFormatVersion: 2
guid: d8d3ba93cf20837469afd166e511c258
guid: bff3df361fa61684386f84b5b062875a
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0

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


public class InteractionManager : MonoBehaviour
{
private Interaction _interaction;
private Interaction _potentialInteraction;
[HideInInspector] public Interaction currentInteraction;
[SerializeField] private InputReader _inputReader = default;
//To store the object we are currently interacting with
private GameObject _currentInteractableObject = null;

[SerializeField] private GameObjectEventChannelSO _startTalking = default;
[SerializeField] private DialogueEventChannelSo _startTalking = default;
//UI event
[SerializeField] private InteractionUIEventChannelSO _toggleInteractionUI = default;
[Header("Listening to")]

void OnInteractionEnd()
{
_inputReader.EnableGameplayInput();
switch (_interaction)
switch (_potentialInteraction)
_toggleInteractionUI.RaiseEvent(true, _interaction);
_toggleInteractionUI.RaiseEvent(true, _potentialInteraction);
Debug.Log("Display interaction UI");
break;
default:

void OnInteractionButtonPress()
{
switch (_interaction)
switch (_potentialInteraction)
{
case Interaction.None:
return;

//pass the item SO to the UI? we do it once we merge with inventory stuff
//raise an event with an item as parameter (to add object to inventory)
_onObjectPickUp.RaiseEvent(_currentInteractableObject);
//_onObjectPickUp.RaiseEvent(currentItem);
//bool for SM
//set current interaction for state machine
currentInteraction = Interaction.PickUp;
}
//destroy the GO
Destroy(_currentInteractableObject);

Debug.Log("Cooking event raised");
//Change the action map
_inputReader.EnableUIInput();
//set current interaction for state machine
currentInteraction = Interaction.Cook;
//raise an event with an actor: DialogueEventChannelSo
_startTalking.RaiseEvent(_currentInteractableObject);
//raise an event with an actor as parameter
//Item currentItem = currentInteractableObject.GetComponent<Dialogue>.Actor;
//_startTalking.RaiseEvent(currentItem);
//set current interaction for state machine
currentInteraction = Interaction.Talk;
}
break;
default:

{
if (other.CompareTag("Pickable"))
{
_interaction = Interaction.PickUp;
_potentialInteraction = Interaction.PickUp;
_interaction = Interaction.Cook;
_potentialInteraction = Interaction.Cook;
_interaction = Interaction.Talk;
_potentialInteraction = Interaction.Talk;
Debug.Log("I triggered an NPC!");
DisplayInteractionUI();
}

private void DisplayInteractionUI ()
{
//Raise event to display UI
_toggleInteractionUI.RaiseEvent(true, _interaction);
_toggleInteractionUI.RaiseEvent(true, _potentialInteraction);
}
private void OnTriggerExit(Collider other)

private void ResetInteraction()
{
_interaction = Interaction.None;
_potentialInteraction = Interaction.None;
//I think the dialogue and UI should switch the action maps? for now I do here but maybe to change later

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


serializedVersion: 2
defaultReferences:
- _inputReader: {fileID: 11400000, guid: 945ec0365077176418488737deed54be, type: 2}
- _onObjectPickUp: {instanceID: 0}
- _onCookingStart: {instanceID: 0}
- _startTalking: {instanceID: 0}
- _toggleInteractionUI: {instanceID: 0}
- _onInteractionEnded: {instanceID: 0}
- _onObjectPickUp: {fileID: 11400000, guid: f3027c4528b8e794f940a4696506f0c3, type: 2}
- _onCookingStart: {fileID: 11400000, guid: 146c579dca5c2f248a607ef66a36d765, type: 2}
- _startTalking: {fileID: 11400000, guid: bff3df361fa61684386f84b5b062875a, type: 2}
- _toggleInteractionUI: {fileID: 11400000, guid: 818cc55cb05226248bdb15ace58eab84,
type: 2}
- _onInteractionEnded: {fileID: 11400000, guid: c499d87f35465124f8fb2751b150430d,
type: 2}
executionOrder: 0
icon: {instanceID: 0}
userData:

14
UOP1_Project/Assets/ScriptableObjects/Interaction/ToggleInteractUI.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 93b84f4bc4b345044ab04e6870e694ec, type: 3}
m_Name: ToggleInteractUI
m_EditorClassIdentifier:

8
UOP1_Project/Assets/ScriptableObjects/Interaction/ToggleInteractUI.asset.meta


fileFormatVersion: 2
guid: 818cc55cb05226248bdb15ace58eab84
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存