Fix adding items in Array/List editors if element type is reference (eg. class)

This commit is contained in:
Wojtek Figat
2021-03-01 11:43:46 +01:00
parent dbec1389e8
commit b4e09a9d55
2 changed files with 24 additions and 13 deletions

View File

@@ -43,10 +43,18 @@ namespace FlaxEditor.CustomEditors.Editors
// Copy old values
Array.Copy(array, 0, newValues, 0, sharedCount);
// Fill new entries with the last value
for (int i = oldSize; i < newSize; i++)
if (elementType.IsValueType)
{
Array.Copy(array, oldSize - 1, newValues, i, 1);
// Fill new entries with the last value
for (int i = oldSize; i < newSize; i++)
Array.Copy(array, oldSize - 1, newValues, i, 1);
}
else
{
// Initialize new entries with default values
var defaultValue = TypeUtils.GetDefaultValue(new ScriptType(elementType));
for (int i = oldSize; i < newSize; i++)
newValues.SetValue(defaultValue, i);
}
}
else if (newSize > 0)
@@ -54,9 +62,7 @@ namespace FlaxEditor.CustomEditors.Editors
// Initialize new entries with default values
var defaultValue = TypeUtils.GetDefaultValue(new ScriptType(elementType));
for (int i = 0; i < newSize; i++)
{
newValues.SetValue(defaultValue, i);
}
}
SetValue(newValues);