new generic quest trigger, translation testring, new debug langage switch options
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -108,18 +108,11 @@ namespace PixelCrushers.QuestMachine
|
||||
|
||||
public static void EditorGUILayoutEndGroup()
|
||||
{
|
||||
try
|
||||
{
|
||||
GUILayout.Space(3);
|
||||
GUILayout.EndVertical();
|
||||
EditorGUILayout.EndHorizontal();
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.Space(3);
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
// If Unity opens a popup bwindow such as a color picker, it raises an exception.
|
||||
}
|
||||
GUILayout.Space(3);
|
||||
GUILayout.EndVertical();
|
||||
EditorGUILayout.EndHorizontal();
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.Space(3);
|
||||
}
|
||||
|
||||
public static void EditorGUILayoutBeginIndent()
|
||||
|
||||
@@ -1994,6 +1994,8 @@ GameObject:
|
||||
- component: {fileID: 392914047}
|
||||
- component: {fileID: 392914046}
|
||||
- component: {fileID: 392914045}
|
||||
- component: {fileID: 392914051}
|
||||
- component: {fileID: 392914052}
|
||||
m_Layer: 0
|
||||
m_Name: TestTrigger
|
||||
m_TagString: Untagged
|
||||
@@ -2015,7 +2017,7 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
openCloseEvents: 0
|
||||
openCloseWindow: 0
|
||||
selectedToolbar: 0
|
||||
selectedToolbar: 4
|
||||
inputType: 0
|
||||
actionInput:
|
||||
useInput: 1
|
||||
@@ -2161,20 +2163,7 @@ MonoBehaviour:
|
||||
onPressActionDelay: 0
|
||||
OnPressActionInput:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 392914046}
|
||||
m_TargetAssemblyTypeName: PixelCrushers.DialogueSystem.Wrappers.DialogueSystemTrigger,
|
||||
Assembly-CSharp-firstpass
|
||||
m_MethodName: OnUse
|
||||
m_Mode: 1
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
|
||||
m_IntArgument: 0
|
||||
m_FloatArgument: 0
|
||||
m_StringArgument:
|
||||
m_BoolArgument: 0
|
||||
m_CallState: 2
|
||||
m_Calls: []
|
||||
onPressActionInputWithTarget:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
@@ -2408,6 +2397,200 @@ Transform:
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &392914051
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 392914044}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: b8f03affff5684e10b83ead8d3506a03, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
invectorTrigger: {fileID: 392914045}
|
||||
actions:
|
||||
- triggerEvent: 4
|
||||
actionType: 1
|
||||
condition:
|
||||
luaConditions: []
|
||||
questConditions: []
|
||||
acceptedTags: []
|
||||
acceptedGameObjects: []
|
||||
luaWizardIndex: 0
|
||||
lastEvaluationValue: 0
|
||||
conversation:
|
||||
conversant: {fileID: 0}
|
||||
luaCode: 'Variable["testCondition"] = not (Variable["testCondition"]) '
|
||||
questMachineMessage:
|
||||
questID:
|
||||
questState: 0
|
||||
questNodeID:
|
||||
questNodeState: 0
|
||||
onExecute:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
- triggerEvent: 4
|
||||
actionType: 4
|
||||
condition:
|
||||
luaConditions:
|
||||
- 'CurrentQuestState("CH02WitchHouse") == "active" '
|
||||
questConditions: []
|
||||
acceptedTags: []
|
||||
acceptedGameObjects: []
|
||||
luaWizardIndex: -1
|
||||
lastEvaluationValue: 0
|
||||
conversation:
|
||||
conversant: {fileID: 0}
|
||||
luaCode:
|
||||
questMachineMessage:
|
||||
questID: CH02WitchHouse
|
||||
questState: 0
|
||||
questNodeID: Examine the crystal
|
||||
questNodeState: 2
|
||||
onExecute:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
- triggerEvent: 4
|
||||
actionType: 5
|
||||
condition:
|
||||
luaConditions: []
|
||||
questConditions: []
|
||||
acceptedTags: []
|
||||
acceptedGameObjects: []
|
||||
luaWizardIndex: -1
|
||||
lastEvaluationValue: 0
|
||||
conversation:
|
||||
conversant: {fileID: 0}
|
||||
luaCode:
|
||||
questMachineMessage:
|
||||
questID:
|
||||
questState: 0
|
||||
questNodeID:
|
||||
questNodeState: 0
|
||||
onExecute:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 434772660}
|
||||
m_TargetAssemblyTypeName: Beyond.ConditionalEventTrigger, Assembly-CSharp
|
||||
m_MethodName: CheckConditionAndExecute
|
||||
m_Mode: 1
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
|
||||
m_IntArgument: 0
|
||||
m_FloatArgument: 0
|
||||
m_StringArgument:
|
||||
m_BoolArgument: 0
|
||||
m_CallState: 2
|
||||
- triggerEvent: 4
|
||||
actionType: 5
|
||||
condition:
|
||||
luaConditions:
|
||||
- 'CurrentQuestState("CH02WitchHouse") ~= "active" '
|
||||
questConditions: []
|
||||
acceptedTags: []
|
||||
acceptedGameObjects: []
|
||||
luaWizardIndex: -1
|
||||
lastEvaluationValue: 0
|
||||
conversation: TestDialogue
|
||||
conversant: {fileID: 0}
|
||||
luaCode:
|
||||
questMachineMessage:
|
||||
questID: CH02WitchHouse
|
||||
questState: 1
|
||||
questNodeID:
|
||||
questNodeState: 0
|
||||
onExecute:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 392914052}
|
||||
m_TargetAssemblyTypeName: PixelCrushers.QuestMachine.Wrappers.QuestGiver,
|
||||
Assembly-CSharp-firstpass
|
||||
m_MethodName: GiveAllQuestsToQuester
|
||||
m_Mode: 2
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 1447701206}
|
||||
m_ObjectArgumentAssemblyTypeName: UnityEngine.GameObject, UnityEngine
|
||||
m_IntArgument: 0
|
||||
m_FloatArgument: 0
|
||||
m_StringArgument:
|
||||
m_BoolArgument: 0
|
||||
m_CallState: 2
|
||||
--- !u!114 &392914052
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 392914044}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 2185d538298c73f418ba252c3e3e01ff, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_key:
|
||||
m_appendSaverTypeToKey: 0
|
||||
m_saveAcrossSceneChanges: 1
|
||||
m_restoreStateOnStart: 0
|
||||
m_forwardEventsToListeners: 0
|
||||
m_includeInSavedGameData: 1
|
||||
m_addNewQuestsSinceSavedGame: 0
|
||||
m_questList:
|
||||
- {fileID: 11400000, guid: b7097c4b7bc544de2b329f98e16c72e4, type: 2}
|
||||
m_deletedStaticQuests: []
|
||||
m_id:
|
||||
m_text:
|
||||
m_stringAsset: {fileID: 0}
|
||||
m_textTable: {fileID: 0}
|
||||
m_textTableFieldID: 0
|
||||
m_displayName:
|
||||
m_text:
|
||||
m_stringAsset: {fileID: 0}
|
||||
m_textTable: {fileID: 0}
|
||||
m_textTableFieldID: 0
|
||||
m_image: {fileID: 0}
|
||||
m_textTable: {fileID: 0}
|
||||
m_noQuestsUIContents:
|
||||
m_icon: {fileID: 0}
|
||||
m_headingText:
|
||||
m_text:
|
||||
m_stringAsset: {fileID: 0}
|
||||
m_textTable: {fileID: 0}
|
||||
m_textTableFieldID: 0
|
||||
m_bodyText:
|
||||
m_text:
|
||||
m_stringAsset: {fileID: 0}
|
||||
m_textTable: {fileID: 0}
|
||||
m_textTableFieldID: 0
|
||||
m_offerableQuestsUIContents:
|
||||
m_icon: {fileID: 0}
|
||||
m_headingText:
|
||||
m_text:
|
||||
m_stringAsset: {fileID: 0}
|
||||
m_textTable: {fileID: 0}
|
||||
m_textTableFieldID: 0
|
||||
m_bodyText:
|
||||
m_text:
|
||||
m_stringAsset: {fileID: 0}
|
||||
m_textTable: {fileID: 0}
|
||||
m_textTableFieldID: 0
|
||||
m_activeQuestsUIContents:
|
||||
m_icon: {fileID: 0}
|
||||
m_headingText:
|
||||
m_text:
|
||||
m_stringAsset: {fileID: 0}
|
||||
m_textTable: {fileID: 0}
|
||||
m_textTableFieldID: 0
|
||||
m_bodyText:
|
||||
m_text:
|
||||
m_stringAsset: {fileID: 0}
|
||||
m_textTable: {fileID: 0}
|
||||
m_textTableFieldID: 0
|
||||
m_completedQuestDialogueMode: 0
|
||||
m_questDialogueUI: {fileID: 0}
|
||||
m_cooldownCheckFrequency: 0
|
||||
--- !u!1 &402038938
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -2681,6 +2864,7 @@ MonoBehaviour:
|
||||
m_BoolArgument: 1
|
||||
m_CallState: 2
|
||||
selectedDatabase: {fileID: 0}
|
||||
CheckInterval: 1
|
||||
--- !u!1 &437438685
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -12437,6 +12621,11 @@ PrefabInstance:
|
||||
serializedVersion: 3
|
||||
m_TransformParent: {fileID: 878574876}
|
||||
m_Modifications:
|
||||
- target: {fileID: 1267280949225758405, guid: dc99ca8ee3c2b0143a009d17e13de983,
|
||||
type: 3}
|
||||
propertyPath: displaySettings.localizationSettings.language
|
||||
value: pl
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1267280949225758409, guid: dc99ca8ee3c2b0143a009d17e13de983,
|
||||
type: 3}
|
||||
propertyPath: m_BlockingMask.m_Bits
|
||||
@@ -13676,42 +13865,42 @@ PrefabInstance:
|
||||
- target: {fileID: 564995907207171390, guid: 851e8e61247888340bdec90fc8aa37f5,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMax.y
|
||||
value: 1
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 564995907207171390, guid: 851e8e61247888340bdec90fc8aa37f5,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMin.y
|
||||
value: 1
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 564995907207171390, guid: 851e8e61247888340bdec90fc8aa37f5,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.x
|
||||
value: 210
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 564995907207171390, guid: 851e8e61247888340bdec90fc8aa37f5,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.y
|
||||
value: -135
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 616128472424357225, guid: 851e8e61247888340bdec90fc8aa37f5,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMax.y
|
||||
value: 1
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 616128472424357225, guid: 851e8e61247888340bdec90fc8aa37f5,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMin.y
|
||||
value: 1
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 616128472424357225, guid: 851e8e61247888340bdec90fc8aa37f5,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.x
|
||||
value: 210.00003
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 616128472424357225, guid: 851e8e61247888340bdec90fc8aa37f5,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.y
|
||||
value: -45
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 763034042805173548, guid: 851e8e61247888340bdec90fc8aa37f5,
|
||||
type: 3}
|
||||
@@ -14552,22 +14741,22 @@ PrefabInstance:
|
||||
- target: {fileID: 4202610206940879906, guid: 851e8e61247888340bdec90fc8aa37f5,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMax.y
|
||||
value: 1
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 4202610206940879906, guid: 851e8e61247888340bdec90fc8aa37f5,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMin.y
|
||||
value: 1
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 4202610206940879906, guid: 851e8e61247888340bdec90fc8aa37f5,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.x
|
||||
value: 210
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 4202610206940879906, guid: 851e8e61247888340bdec90fc8aa37f5,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.y
|
||||
value: -225
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 4310148345887150382, guid: 851e8e61247888340bdec90fc8aa37f5,
|
||||
type: 3}
|
||||
@@ -14732,22 +14921,22 @@ PrefabInstance:
|
||||
- target: {fileID: 4796023216948086302, guid: 851e8e61247888340bdec90fc8aa37f5,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMax.y
|
||||
value: 1
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 4796023216948086302, guid: 851e8e61247888340bdec90fc8aa37f5,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMin.y
|
||||
value: 1
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 4796023216948086302, guid: 851e8e61247888340bdec90fc8aa37f5,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.x
|
||||
value: 210
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 4796023216948086302, guid: 851e8e61247888340bdec90fc8aa37f5,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.y
|
||||
value: -315
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 4907318199456855652, guid: 851e8e61247888340bdec90fc8aa37f5,
|
||||
type: 3}
|
||||
@@ -16097,22 +16286,22 @@ PrefabInstance:
|
||||
- target: {fileID: 7465903852046106667, guid: 851e8e61247888340bdec90fc8aa37f5,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMax.y
|
||||
value: 1
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7465903852046106667, guid: 851e8e61247888340bdec90fc8aa37f5,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMin.y
|
||||
value: 1
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7465903852046106667, guid: 851e8e61247888340bdec90fc8aa37f5,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.x
|
||||
value: 210
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7465903852046106667, guid: 851e8e61247888340bdec90fc8aa37f5,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.y
|
||||
value: -405
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7534046934194550914, guid: 851e8e61247888340bdec90fc8aa37f5,
|
||||
type: 3}
|
||||
@@ -17385,6 +17574,11 @@ PrefabInstance:
|
||||
serializedVersion: 3
|
||||
m_TransformParent: {fileID: 0}
|
||||
m_Modifications:
|
||||
- target: {fileID: 1203476819518978270, guid: cd8f9cb3aae974fbc9aedcaba4d732ef,
|
||||
type: 3}
|
||||
propertyPath: fireOnce
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 4356717714091686263, guid: cd8f9cb3aae974fbc9aedcaba4d732ef,
|
||||
type: 3}
|
||||
propertyPath: m_Name
|
||||
|
||||
@@ -4,6 +4,7 @@ using Beyond;
|
||||
using Invector.vCharacterController;
|
||||
using Invector.vMelee;
|
||||
using PixelCrushers;
|
||||
using PixelCrushers.DialogueSystem;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using PixelCrushers.QuestMachine;
|
||||
@@ -197,13 +198,13 @@ public partial class SROptions
|
||||
{
|
||||
var journal = QuestMachine.GetQuestJournal();
|
||||
|
||||
if (!m_currentQuest || m_currentQuest.GetState() == QuestState.Successful)
|
||||
if (!m_currentQuest || m_currentQuest.GetState() == PixelCrushers.QuestMachine.QuestState.Successful)
|
||||
{
|
||||
for (int i = 0; i < journal.questList.Count; i++)
|
||||
{
|
||||
var quest = journal.questList[i];
|
||||
|
||||
if (!quest.isTrackable || quest.GetState() == QuestState.Successful)
|
||||
if (!quest.isTrackable || quest.GetState() == PixelCrushers.QuestMachine.QuestState.Successful)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -270,4 +271,17 @@ public partial class SROptions
|
||||
{
|
||||
QuestMachine.GiveQuestToQuester(GuiltId, "Bascileus");
|
||||
}
|
||||
|
||||
[Category("Language")]
|
||||
public void SetEnglish()
|
||||
{
|
||||
DialogueManager.instance.SetLanguage("en");
|
||||
}
|
||||
|
||||
[Category("Language")]
|
||||
public void SetPolish()
|
||||
{
|
||||
DialogueManager.instance.SetLanguage("pl");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
260
Assets/Scripts/Triggers/GenericQuestTrigger.cs
Normal file
260
Assets/Scripts/Triggers/GenericQuestTrigger.cs
Normal file
@@ -0,0 +1,260 @@
|
||||
// --- THIS SCRIPT CAN BE PLACED ANYWHERE IN YOUR ASSETS FOLDER ---
|
||||
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using Sirenix.OdinInspector;
|
||||
using PixelCrushers.DialogueSystem; // Required for [ConversationPopup] attribute
|
||||
using PixelCrushers.QuestMachine;
|
||||
using Invector.vCharacterController.vActions; // Required for the vTriggerGenericAction reference
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace Beyond
|
||||
{
|
||||
[AddComponentMenu("Beyond/Quests/Generic Quest Trigger")]
|
||||
[RequireComponent(typeof(vTriggerGenericAction))] // IMPORTANT: Ensures the Invector trigger is always on the same GameObject
|
||||
public class GenericQuestTrigger : MonoBehaviour
|
||||
{
|
||||
#region --- ODIN-POWERED INSPECTOR ---
|
||||
|
||||
[Title("Invector Trigger Link")]
|
||||
[InfoBox("This component links into the vTriggerGenericAction below and adds quest/dialogue functionality to its events.")]
|
||||
[Required("A vTriggerGenericAction component is required on this GameObject.")]
|
||||
[OnInspectorInit("FindTriggerReference")] // Odin attribute to auto-fill the reference on first view
|
||||
public vTriggerGenericAction invectorTrigger;
|
||||
|
||||
[Title("Quest and Dialogue Actions")]
|
||||
[ListDrawerSettings(Expanded = true, DraggableItems = true, NumberOfItemsPerPage = 10)]
|
||||
public List<TriggeredAction> actions = new List<TriggeredAction>();
|
||||
|
||||
#endregion
|
||||
|
||||
private GameObject _lastInteractor;
|
||||
|
||||
// This is a helper method for the Odin attribute [OnInspectorInit]
|
||||
private void FindTriggerReference()
|
||||
{
|
||||
if (invectorTrigger == null)
|
||||
{
|
||||
invectorTrigger = GetComponent<vTriggerGenericAction>();
|
||||
}
|
||||
}
|
||||
|
||||
#region --- CORE LOGIC (Lifecycle & Event Handlers) ---
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (invectorTrigger == null)
|
||||
{
|
||||
Debug.LogError("GenericQuestTrigger requires a vTriggerGenericAction component, but none was found. Disabling component.", this);
|
||||
this.enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Subscribe our methods to the events on the Invector component
|
||||
invectorTrigger.OnPressActionInput.AddListener(() => HandleEvent(TriggerEventType.OnPressActionInput, _lastInteractor));
|
||||
invectorTrigger.OnStartAnimation.AddListener(() => HandleEvent(TriggerEventType.OnStartAnimation, _lastInteractor));
|
||||
invectorTrigger.OnEndAnimation.AddListener(() => HandleEvent(TriggerEventType.OnEndAnimation, _lastInteractor));
|
||||
|
||||
invectorTrigger.OnPlayerEnter.AddListener(HandlePlayerEnter);
|
||||
invectorTrigger.OnPlayerExit.AddListener(HandlePlayerExit);
|
||||
invectorTrigger.OnValidate.AddListener((interactor) => HandleEvent(TriggerEventType.OnValidate, interactor));
|
||||
invectorTrigger.OnInvalidate.AddListener((interactor) => HandleEvent(TriggerEventType.OnInvalidate, interactor));
|
||||
|
||||
if (DialogueManager.instance != null)
|
||||
{
|
||||
DialogueManager.instance.conversationEnded += OnConversationEnded;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (DialogueManager.instance != null)
|
||||
{
|
||||
DialogueManager.instance.conversationEnded -= OnConversationEnded;
|
||||
}
|
||||
|
||||
// It's good practice to unsubscribe from events when disabled/destroyed to prevent memory leaks
|
||||
if (invectorTrigger != null)
|
||||
{
|
||||
invectorTrigger.OnPressActionInput.RemoveListener(() => HandleEvent(TriggerEventType.OnPressActionInput, _lastInteractor));
|
||||
invectorTrigger.OnStartAnimation.RemoveListener(() => HandleEvent(TriggerEventType.OnStartAnimation, _lastInteractor));
|
||||
invectorTrigger.OnEndAnimation.RemoveListener(() => HandleEvent(TriggerEventType.OnEndAnimation, _lastInteractor));
|
||||
invectorTrigger.OnPlayerEnter.RemoveListener(HandlePlayerEnter);
|
||||
invectorTrigger.OnPlayerExit.RemoveListener(HandlePlayerExit);
|
||||
invectorTrigger.OnValidate.RemoveListener((interactor) => HandleEvent(TriggerEventType.OnValidate, interactor));
|
||||
invectorTrigger.OnInvalidate.RemoveListener((interactor) => HandleEvent(TriggerEventType.OnInvalidate, interactor));
|
||||
}
|
||||
}
|
||||
|
||||
private void HandlePlayerEnter(GameObject interactor)
|
||||
{
|
||||
_lastInteractor = interactor;
|
||||
HandleEvent(TriggerEventType.OnPlayerEnter, interactor);
|
||||
}
|
||||
|
||||
private void HandlePlayerExit(GameObject interactor)
|
||||
{
|
||||
HandleEvent(TriggerEventType.OnPlayerExit, interactor);
|
||||
_lastInteractor = null;
|
||||
}
|
||||
|
||||
private void OnConversationEnded(Transform actor)
|
||||
{
|
||||
if (_lastInteractor != null && actor.gameObject == _lastInteractor)
|
||||
{
|
||||
HandleEvent(TriggerEventType.OnConversationEnd, actor.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleEvent(TriggerEventType eventType, GameObject interactor)
|
||||
{
|
||||
foreach (var action in actions)
|
||||
{
|
||||
if (action.triggerEvent == eventType)
|
||||
{
|
||||
// Check if the optional Dialogue System condition is met
|
||||
if (action.condition == null || action.condition.IsTrue(interactor?.transform))
|
||||
{
|
||||
PerformAction(action, interactor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void PerformAction(TriggeredAction action, GameObject interactor)
|
||||
{
|
||||
var actorTransform = interactor?.transform;
|
||||
|
||||
switch (action.actionType)
|
||||
{
|
||||
case ActionType.StartConversation:
|
||||
if (!string.IsNullOrEmpty(action.conversation))
|
||||
{
|
||||
Transform conversant = action.conversant != null ? action.conversant : this.transform;
|
||||
DialogueManager.StartConversation(action.conversation, actorTransform, conversant);
|
||||
}
|
||||
break;
|
||||
|
||||
case ActionType.ExecuteLua:
|
||||
if (!string.IsNullOrEmpty(action.luaCode))
|
||||
{
|
||||
Lua.Run(action.luaCode, true);
|
||||
}
|
||||
break;
|
||||
|
||||
case ActionType.SendQuestMachineMessage:
|
||||
if (!string.IsNullOrEmpty(action.questMachineMessage))
|
||||
{
|
||||
QuestMachineMessages.SendCompositeMessage(this, action.questMachineMessage);
|
||||
}
|
||||
break;
|
||||
|
||||
case ActionType.SetQuestState:
|
||||
if (!string.IsNullOrEmpty(action.questID))
|
||||
{
|
||||
QuestMachine.SetQuestState(action.questID, action.questState);
|
||||
}
|
||||
break;
|
||||
|
||||
case ActionType.SetQuestNodeState:
|
||||
if (!string.IsNullOrEmpty(action.questID) && !string.IsNullOrEmpty(action.questNodeID))
|
||||
{
|
||||
QuestMachine.SetQuestNodeState(action.questID, action.questNodeID, action.questNodeState);
|
||||
}
|
||||
break;
|
||||
|
||||
case ActionType.InvokeUnityEvent:
|
||||
action.onExecute?.Invoke();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region --- Action Definitions (Enums and Class) ---
|
||||
|
||||
public enum TriggerEventType
|
||||
{
|
||||
OnPlayerEnter,
|
||||
OnPlayerExit,
|
||||
OnValidate,
|
||||
OnInvalidate,
|
||||
OnPressActionInput,
|
||||
OnStartAnimation,
|
||||
OnEndAnimation,
|
||||
OnConversationEnd
|
||||
}
|
||||
|
||||
public enum ActionType
|
||||
{
|
||||
StartConversation,
|
||||
ExecuteLua,
|
||||
SendQuestMachineMessage,
|
||||
SetQuestState,
|
||||
SetQuestNodeState,
|
||||
InvokeUnityEvent
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class TriggeredAction
|
||||
{
|
||||
[HorizontalGroup("Top", 120)]
|
||||
[BoxGroup("Top/Trigger", showLabel: false)]
|
||||
[EnumToggleButtons, HideLabel]
|
||||
public TriggerEventType triggerEvent;
|
||||
|
||||
[BoxGroup("Top/Action", showLabel: false)]
|
||||
[EnumToggleButtons, HideLabel]
|
||||
public ActionType actionType;
|
||||
|
||||
[BoxGroup("Settings")]
|
||||
[Tooltip("Optional Dialogue System condition that must be true for this action to fire.")]
|
||||
[DrawWithUnity] // <-- Tells Odin to use the Pixel Crushers drawer for this field.
|
||||
public Condition condition;
|
||||
|
||||
[BoxGroup("Settings")]
|
||||
[ShowIf("actionType", ActionType.StartConversation)]
|
||||
[ConversationPopup(false)] // <-- The Dialogue System attribute that creates the dropdown.
|
||||
[DrawWithUnity] // <-- The Odin attribute that allows the above attribute to work.
|
||||
public string conversation;
|
||||
|
||||
[BoxGroup("Settings")]
|
||||
[ShowIf("actionType", ActionType.StartConversation)]
|
||||
[Tooltip("The other participant in the conversation. If unassigned, this trigger object will be the conversant.")]
|
||||
public Transform conversant;
|
||||
|
||||
[BoxGroup("Settings")]
|
||||
[ShowIf("actionType", ActionType.ExecuteLua)]
|
||||
[TextArea(2, 5)]
|
||||
public string luaCode;
|
||||
|
||||
[BoxGroup("Settings")]
|
||||
[ShowIf("actionType", ActionType.SendQuestMachineMessage)]
|
||||
public string questMachineMessage;
|
||||
|
||||
[BoxGroup("Settings")]
|
||||
[ShowIf("@this.actionType == ActionType.SetQuestState || this.actionType == ActionType.SetQuestNodeState")]
|
||||
[DrawWithUnity] // <-- Tells Odin to use the Quest Machine drawer for the quest ID field.
|
||||
public string questID;
|
||||
|
||||
[BoxGroup("Settings")]
|
||||
[ShowIf("actionType", ActionType.SetQuestState)]
|
||||
public PixelCrushers.QuestMachine.QuestState questState;
|
||||
|
||||
[BoxGroup("Settings")]
|
||||
[ShowIf("actionType", ActionType.SetQuestNodeState)]
|
||||
[DrawWithUnity] // <-- Tells Odin to use the Quest Machine drawer for the node ID field.
|
||||
public string questNodeID;
|
||||
|
||||
[BoxGroup("Settings")]
|
||||
[ShowIf("actionType", ActionType.SetQuestNodeState)]
|
||||
public PixelCrushers.QuestMachine.QuestNodeState questNodeState;
|
||||
|
||||
[BoxGroup("Settings")]
|
||||
[ShowIf("actionType", ActionType.InvokeUnityEvent)]
|
||||
public UnityEvent onExecute;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
2
Assets/Scripts/Triggers/GenericQuestTrigger.cs.meta
Normal file
2
Assets/Scripts/Triggers/GenericQuestTrigger.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8f03affff5684e10b83ead8d3506a03
|
||||
Reference in New Issue
Block a user