53 lines
1.7 KiB
C#
53 lines
1.7 KiB
C#
using System.Collections.Generic;
|
|
using LLM.Facts;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
namespace LLM.Facts
|
|
{
|
|
public class FactsSequence : MonoBehaviour
|
|
{
|
|
[Header("References")]
|
|
[SerializeField] private ContextMemoryManager contextMemory;
|
|
|
|
[Header("Behavior")]
|
|
[SerializeField] private bool includeInactiveChildren = false;
|
|
[SerializeField] private bool saveGameAfterApply = true;
|
|
[SerializeField] private UnityEvent onApplied = new UnityEvent();
|
|
[SerializeField] private bool debugLogs = true;
|
|
|
|
public void Apply()
|
|
{
|
|
if (contextMemory == null)
|
|
{
|
|
contextMemory = FindObjectOfType<ContextMemoryManager>(true);
|
|
}
|
|
|
|
if (contextMemory == null)
|
|
{
|
|
if (debugLogs) Debug.LogWarning("[FactsSequence] ContextMemoryManager not found.", this);
|
|
return;
|
|
}
|
|
|
|
var nodes = GetComponentsInChildren<FactOperationBehaviour>(includeInactiveChildren);
|
|
if (nodes == null || nodes.Length == 0)
|
|
{
|
|
if (debugLogs) Debug.LogWarning("[FactsSequence] No FactOperationBehaviour found.", this);
|
|
return;
|
|
}
|
|
|
|
List<FactOperation> ops = new List<FactOperation>(nodes.Length);
|
|
for (int i = 0; i < nodes.Length; i++)
|
|
{
|
|
if (nodes[i] == null) continue;
|
|
ops.Add(nodes[i].ToOperation());
|
|
}
|
|
|
|
contextMemory.ApplyOperations(ops, saveGameAfterApply);
|
|
onApplied?.Invoke();
|
|
|
|
if (debugLogs) Debug.Log($"[FactsSequence] Applied operations={ops.Count} save={saveGameAfterApply}", this);
|
|
}
|
|
}
|
|
}
|