using System; using UniRx; using UnityEngine; namespace SLSFramework.General { /// /// 指令:在指令上下文 (CommandContext) 中声明并设置一个变量。 /// public class Cmd_SetVariable : CommandBase { private readonly string variableName; private readonly object value; public Cmd_SetVariable(string variableName, object value) { this.variableName = variableName; this.value = value; } protected override IObservable OnExecute(CommandContext outerContext) { Debug.Log($"[Cmd_SetVariable] 正在设置变量 '{variableName}',值为: '{value}'"); // 直接操作 Context 的 SharedData 字典来存入数据。 // 使用索引器会覆盖同名旧值,如果需要更复杂的逻辑可以先用 TryGetValue 检查。 outerContext.context[variableName] = value; // 这是一个瞬时操作,所以返回一个立即完成的 Observable。 return Observable.Return(Unit.Default); } } }