Add default values initialization for structures and new array entries when resizing

This commit is contained in:
Wojtek Figat
2021-01-12 13:49:26 +01:00
parent 45211fa61c
commit d20cbf434f
4 changed files with 61 additions and 3 deletions

View File

@@ -2,6 +2,7 @@
using System;
using System.Collections;
using FlaxEditor.Scripting;
using FlaxEngine;
namespace FlaxEditor.CustomEditors.Editors
@@ -48,6 +49,15 @@ namespace FlaxEditor.CustomEditors.Editors
Array.Copy(array, oldSize - 1, newValues, i, 1);
}
}
else if (newSize > 0)
{
// 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);
}

View File

@@ -58,7 +58,7 @@ namespace FlaxEditor.CustomEditors.Editors
}
else if (newSize > 0)
{
// Fill new entries
// Fill new entries with default value
var defaultValue = Scripting.TypeUtils.GetDefaultValue(ElementType);
for (int i = oldSize; i < newSize; i++)
{