diff --git a/CHANGELOG.md b/CHANGELOG.md
index 49b1470..47e7420 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Serialization of local components in Blackboard Container.
- Blackboard.GetValueType() method that returns a type of a property by its property name.
- Blackboard.GetPropertyNames() method that returns all property names of properties contained in Blackboard.
+- Blackboard.CopyTo() methods that copy properties to another blackboard.
## [1.1.0] - 2020-09-28
diff --git a/Runtime/Core/Blackboard.cs b/Runtime/Core/Blackboard.cs
index 8b38f05..7c8c556 100644
--- a/Runtime/Core/Blackboard.cs
+++ b/Runtime/Core/Blackboard.cs
@@ -954,9 +954,9 @@ public void Clear()
/// Destination.
public void CopyTo([NotNull] Blackboard blackboard)
{
- Profiler.BeginSample("Blackboard.CopyTo");
+ Profiler.BeginSample("Blackboard.CopyTo(Blackboard)");
- BlackboardDebug.LogDetails($"[Blackboard] CopyTo");
+ BlackboardDebug.LogDetails($"[Blackboard] CopyTo(Blackboard)");
Dictionary.Enumerator tableEnumerator = m_tables.GetEnumerator();
while (tableEnumerator.MoveNext())
@@ -985,6 +985,82 @@ public void CopyTo([NotNull] Blackboard blackboard)
Profiler.EndSample();
}
+ ///
+ /// Copies a property of the property name to .
+ ///
+ /// Destination.
+ /// Property to copy.
+ public void CopyTo([NotNull] Blackboard blackboard, BlackboardPropertyName propertyName)
+ {
+ Profiler.BeginSample("Blackboard.CopyTo(Blackboard, BlackboardPropertyName)");
+
+ BlackboardDebug.LogDetails($"[Blackboard] CopyTo(Blackboard, BlackboardPropertyName)");
+
+ if (m_propertyTypes.TryGetValue(propertyName, out Type propertyType))
+ {
+ IBlackboardTable tableToCopy = m_tables[propertyType];
+ IBlackboardTable tableToCopyTo = blackboard.GetOrCreateTable(propertyType);
+ tableToCopy.CopyTo(tableToCopyTo);
+ blackboard.m_propertyTypes[propertyName] = propertyType;
+ }
+
+ Profiler.EndSample();
+ }
+
+ ///
+ /// Copies properties of the property names to .
+ ///
+ /// Destination.
+ /// Properties to copy.
+ public void CopyTo([NotNull] Blackboard blackboard, BlackboardPropertyName[] propertyNames)
+ {
+ Profiler.BeginSample("Blackboard.CopyTo(Blackboard, BlackboardPropertyName[])");
+
+ BlackboardDebug.LogDetails($"[Blackboard] CopyTo(Blackboard, BlackboardPropertyName[])");
+
+ for (int i = 0, count = propertyNames.Length; i < count; ++i)
+ {
+ BlackboardPropertyName propertyName = propertyNames[i];
+
+ if (m_propertyTypes.TryGetValue(propertyName, out Type propertyType))
+ {
+ IBlackboardTable tableToCopy = m_tables[propertyType];
+ IBlackboardTable tableToCopyTo = blackboard.GetOrCreateTable(propertyType);
+ tableToCopy.CopyTo(tableToCopyTo);
+ blackboard.m_propertyTypes[propertyName] = propertyType;
+ }
+ }
+
+ Profiler.EndSample();
+ }
+
+ ///
+ /// Copies properties of the property names to .
+ ///
+ /// Destination.
+ /// Properties to copy.
+ public void CopyTo([NotNull] Blackboard blackboard, T propertyNames) where T : IList
+ {
+ Profiler.BeginSample("Blackboard.CopyTo(Blackboard, BlackboardPropertyName[])");
+
+ BlackboardDebug.LogDetails($"[Blackboard] CopyTo(Blackboard, BlackboardPropertyName[])");
+
+ for (int i = 0, count = propertyNames.Count; i < count; ++i)
+ {
+ BlackboardPropertyName propertyName = propertyNames[i];
+
+ if (m_propertyTypes.TryGetValue(propertyName, out Type propertyType))
+ {
+ IBlackboardTable tableToCopy = m_tables[propertyType];
+ IBlackboardTable tableToCopyTo = blackboard.GetOrCreateTable(propertyType);
+ tableToCopy.CopyTo(tableToCopyTo);
+ blackboard.m_propertyTypes[propertyName] = propertyType;
+ }
+ }
+
+ Profiler.EndSample();
+ }
+
[Pure]
public override string ToString()
{
diff --git a/Tests/Runtime/BlackboardTests.cs b/Tests/Runtime/BlackboardTests.cs
index 5080322..736d731 100644
--- a/Tests/Runtime/BlackboardTests.cs
+++ b/Tests/Runtime/BlackboardTests.cs
@@ -647,6 +647,10 @@ public static void CopyToTests()
new GameObject().AddComponent(), new GameObject().transform,
1, 230f
});
+
+ CopyToTest(fromBlackboard, toBlackboard, new GameObject());
+ CopyToTest(fromBlackboard, toBlackboard, 1);
+ CopyToTest(fromBlackboard, toBlackboard, new List