lamets fix, bagge dialogue and VO

This commit is contained in:
2025-10-17 10:27:14 +02:00
parent 9bf7ab7489
commit 147c9c4312
8 changed files with 869 additions and 649 deletions

View 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();
}
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 6709a146e599d4c46882e1173a52b192