继续
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SLSFramework.General
|
||||
{
|
||||
@@ -17,15 +18,16 @@ namespace SLSFramework.General
|
||||
context = new Dictionary<string, object>();
|
||||
}
|
||||
|
||||
public CommandContext(string key, object value)
|
||||
public CommandContext((string, object)[] pairs)
|
||||
{
|
||||
context = new Dictionary<string, object>
|
||||
context = new Dictionary<string, object>();
|
||||
foreach ((string, object) pair in pairs)
|
||||
{
|
||||
{ key, value }
|
||||
};
|
||||
context[pair.Item1] = pair.Item2;
|
||||
}
|
||||
}
|
||||
|
||||
public CommandContext(List<KeyValuePair<string, object>> initialInfo)
|
||||
|
||||
public CommandContext(Dictionary<string, object> initialInfo)
|
||||
{
|
||||
context = new Dictionary<string, object>();
|
||||
foreach (var pair in initialInfo)
|
||||
@@ -33,7 +35,7 @@ namespace SLSFramework.General
|
||||
context[pair.Key] = pair.Value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public CommandContext Clone()
|
||||
{
|
||||
var newContext = new CommandContext();
|
||||
@@ -43,6 +45,15 @@ namespace SLSFramework.General
|
||||
}
|
||||
return newContext;
|
||||
}
|
||||
|
||||
public CommandContext Merge(CommandContext other)
|
||||
{
|
||||
foreach (var pair in other.context)
|
||||
{
|
||||
this.context[pair.Key] = pair.Value;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public T GetInfo<T>(string key)
|
||||
{
|
||||
@@ -50,6 +61,8 @@ namespace SLSFramework.General
|
||||
{
|
||||
return typedValue;
|
||||
}
|
||||
|
||||
Debug.LogWarning($"CommandContext 中不存在键 '{key}',或其类型不匹配。返回默认值。");
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user