Fix duplicating array values in Editor

#1959
This commit is contained in:
Wojtek Figat
2024-03-04 18:25:57 +01:00
parent 5fdf1789ce
commit bbe08be462
3 changed files with 21 additions and 17 deletions

View File

@@ -11,7 +11,6 @@ using System.Globalization;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
@@ -20,6 +19,7 @@ using FlaxEditor.GUI.Input;
using FlaxEditor.GUI.Tree;
using FlaxEditor.SceneGraph;
using FlaxEngine;
using FlaxEngine.Json;
using FlaxEngine.GUI;
using FlaxEngine.Utilities;
using FlaxEditor.Windows;
@@ -203,6 +203,22 @@ namespace FlaxEditor.Utilities
}
}
/// <summary>
/// Clones the value. handles non-value types (such as arrays) that need deep value cloning.
/// </summary>
/// <param name="value">The source value to clone.</param>
/// <returns>The duplicated value.</returns>
internal static object CloneValue(object value)
{
// For objects (eg. arrays) we need to clone them to prevent editing default/reference value within editor
if (value != null && (!value.GetType().IsValueType || !value.GetType().IsClass))
{
var json = JsonSerializer.Serialize(value);
value = JsonSerializer.Deserialize(json, value.GetType());
}
return value;
}
/// <summary>
/// The colors for the keyframes used by the curve editor.
/// </summary>