41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
namespace LLM.Commands
|
|
{
|
|
public class UnityEventCommandReceiver : LLMCommandReceiverBase
|
|
{
|
|
[Serializable]
|
|
private class ActionBinding
|
|
{
|
|
public string action;
|
|
public UnityEvent onExecute = new UnityEvent();
|
|
}
|
|
|
|
[SerializeField] private List<ActionBinding> bindings = new List<ActionBinding>();
|
|
[SerializeField] private bool debugLogs = true;
|
|
|
|
public override bool TryExecute(LLMCommand command)
|
|
{
|
|
if (command == null) return false;
|
|
if (!string.Equals(command.type, "Event", StringComparison.OrdinalIgnoreCase)) return false;
|
|
if (string.IsNullOrWhiteSpace(command.action)) return false;
|
|
|
|
for (int i = 0; i < bindings.Count; i++)
|
|
{
|
|
var b = bindings[i];
|
|
if (b == null) continue;
|
|
if (!string.Equals(b.action, command.action, StringComparison.OrdinalIgnoreCase)) continue;
|
|
b.onExecute?.Invoke();
|
|
if (debugLogs) Debug.Log($"[UnityEventCommandReceiver] Executed action='{command.action}' targetId='{TargetId}'", this);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|