lamets fix, bagge dialogue and VO
This commit is contained in:
89
Assets/Scripts/Save/ConditionalEventTrigger.cs
Normal file
89
Assets/Scripts/Save/ConditionalEventTrigger.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
// ConditionalEventTrigger.cs
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using PixelCrushers.DialogueSystem;
|
||||
using PixelCrushers;
|
||||
|
||||
namespace Beyond
|
||||
{
|
||||
/// <summary>
|
||||
/// A generic, saveable trigger that checks a Lua condition on start or load,
|
||||
/// and fires a UnityEvent based on the result.
|
||||
/// </summary>
|
||||
[AddComponentMenu("Pixel Crushers/Dialogue System/Trigger/Conditional Event Trigger")]
|
||||
public class ConditionalEventTrigger : Saver
|
||||
{
|
||||
[Header("Condition")]
|
||||
[Tooltip("The Lua condition to check.")]
|
||||
public Condition condition = new Condition();
|
||||
|
||||
[Tooltip("If ticked, the events will only be fired the first time the condition is met. This state is saved and loaded.")]
|
||||
public bool fireOnce = true;
|
||||
|
||||
[Header("Events")]
|
||||
[Tooltip("Actions to perform if the condition is true.")]
|
||||
public UnityEvent onConditionTrue;
|
||||
|
||||
[Tooltip("Actions to perform if the condition is false.")]
|
||||
public UnityEvent onConditionFalse;
|
||||
|
||||
// This field is used by the custom editor for the Lua wizard.
|
||||
[HideInInspector]
|
||||
public DialogueDatabase selectedDatabase = null;
|
||||
|
||||
private bool hasFired = false;
|
||||
|
||||
/// <summary>
|
||||
/// On game start, check the condition. Handles new games or scene loads.
|
||||
/// </summary>
|
||||
public override void Start()
|
||||
{
|
||||
base.Start();
|
||||
CheckConditionAndExecute();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called by the Save System when saving a game. Records if this trigger has already fired.
|
||||
/// </summary>
|
||||
public override string RecordData()
|
||||
{
|
||||
return SaveSystem.Serialize(hasFired);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called by the Save System when loading a game. Restores the fired state
|
||||
/// and then re-evaluates the condition.
|
||||
/// </summary>
|
||||
public override void ApplyData(string s)
|
||||
{
|
||||
hasFired = !string.IsNullOrEmpty(s) ? SaveSystem.Deserialize<bool>(s) : false;
|
||||
CheckConditionAndExecute();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Evaluates the Lua condition and invokes the appropriate UnityEvent.
|
||||
/// </summary>
|
||||
public void CheckConditionAndExecute()
|
||||
{
|
||||
if (fireOnce && hasFired)
|
||||
{
|
||||
if (DialogueDebug.logInfo) Debug.Log($"Dialogue System: ConditionalEventTrigger '{name}' will not fire again because Fire Once is true and it has already fired.", this);
|
||||
return;
|
||||
}
|
||||
|
||||
bool conditionResult = condition.IsTrue(null);
|
||||
|
||||
if (DialogueDebug.logInfo) Debug.Log($"Dialogue System: ConditionalEventTrigger '{name}' condition is {conditionResult}. Invoking events.", this);
|
||||
|
||||
if (conditionResult)
|
||||
{
|
||||
onConditionTrue.Invoke();
|
||||
hasFired = true; // Mark as fired if the condition was met
|
||||
}
|
||||
else
|
||||
{
|
||||
onConditionFalse.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Save/ConditionalEventTrigger.cs.meta
Normal file
2
Assets/Scripts/Save/ConditionalEventTrigger.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6709a146e599d4c46882e1173a52b192
|
||||
Reference in New Issue
Block a user