Fix pasting or duplicating Multi Blend nodes
This commit is contained in:
@@ -885,6 +885,17 @@ namespace FlaxEditor.Surface.Archetypes
|
||||
_selectedAnimation.SelectedIndex = 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void SetValuesPaste(object[] values)
|
||||
{
|
||||
// Fix Guids pasted as string
|
||||
// TODO: let copy/paste system in Visject handle value types to be strongly typed
|
||||
for (int i = 5; i < values.Length; i += 2)
|
||||
values[i] = Guid.Parse((string)values[i]);
|
||||
|
||||
base.SetValuesPaste(values);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnValuesChanged()
|
||||
{
|
||||
|
||||
@@ -1001,6 +1001,15 @@ namespace FlaxEditor.Surface
|
||||
_isDuringValuesEditing = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets teh node values from the given pasted source. Can be overriden to perform validation or custom values processing.
|
||||
/// </summary>
|
||||
/// <param name="values">The input values array.</param>
|
||||
public virtual void SetValuesPaste(object[] values)
|
||||
{
|
||||
Values = values;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when node values set gets changed.
|
||||
/// </summary>
|
||||
|
||||
@@ -286,13 +286,14 @@ namespace FlaxEditor.Surface
|
||||
// Initialize
|
||||
if (nodeData.Values != null && node.Values.Length > 0)
|
||||
{
|
||||
if (node.Values != null && node.Values.Length == nodeData.Values.Length)
|
||||
var nodeValues = (object[])node.Values?.Clone();
|
||||
if (nodeValues != null && nodeValues.Length == nodeData.Values.Length)
|
||||
{
|
||||
// Copy and fix values (Json deserializes may output them in a different format)
|
||||
for (int l = 0; l < node.Values.Length; l++)
|
||||
for (int l = 0; l < nodeData.Values.Length; l++)
|
||||
{
|
||||
var src = nodeData.Values[l].Value;
|
||||
var dst = node.Values[l];
|
||||
var dst = nodeValues[l];
|
||||
|
||||
try
|
||||
{
|
||||
@@ -364,13 +365,24 @@ namespace FlaxEditor.Surface
|
||||
Editor.LogWarning(ex);
|
||||
}
|
||||
|
||||
node.Values[l] = src;
|
||||
nodeValues[l] = src;
|
||||
}
|
||||
}
|
||||
else if (node.Archetype.Flags.HasFlag(NodeFlags.VariableValuesSize))
|
||||
{
|
||||
// Copy values
|
||||
nodeValues = new object[nodeData.Values.Length];
|
||||
for (int l = 0; l < nodeData.Values.Length; l++)
|
||||
{
|
||||
nodeValues[l] = nodeData.Values[l].Value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Editor.LogWarning("Invalid node custom values.");
|
||||
}
|
||||
if (nodeValues != null)
|
||||
node.SetValuesPaste(nodeValues);
|
||||
}
|
||||
|
||||
Context.OnControlLoaded(node, SurfaceNodeActions.Paste);
|
||||
|
||||
Reference in New Issue
Block a user