Add support for array of Visual Script objects

This commit is contained in:
Wojtek Figat
2022-05-01 20:42:05 +02:00
parent c5bfdc66a4
commit 74b23d0e00
20 changed files with 221 additions and 62 deletions

View File

@@ -548,7 +548,7 @@ namespace FlaxEditor.CustomEditors
text = text.Remove(idx, endIdx - idx);
}
}
else if (new ScriptType(typeof(FlaxEngine.Object)).IsAssignableFrom(Values.Type))
else if (ScriptType.FlaxObject.IsAssignableFrom(Values.Type))
{
// Object reference
text = JsonSerializer.GetStringID(Values[0] as FlaxEngine.Object);
@@ -598,7 +598,7 @@ namespace FlaxEditor.CustomEditors
return false;
}
}
else if (new ScriptType(typeof(FlaxEngine.Object)).IsAssignableFrom(Values.Type))
else if (ScriptType.FlaxObject.IsAssignableFrom(Values.Type))
{
// Object reference
if (text.Length != 32)

View File

@@ -155,7 +155,7 @@ namespace FlaxEditor.CustomEditors
}
if (targetType.IsGenericType)
{
if (DictionaryEditor.CanEditType(targetTypeType))
if (targetTypeType.GetGenericTypeDefinition() == typeof(Dictionary<,>))
{
return new DictionaryEditor();
}

View File

@@ -21,7 +21,7 @@ namespace FlaxEditor.CustomEditors.Editors
{
var arrayType = Values.Type;
var elementType = arrayType.GetElementType();
return Array.CreateInstance(elementType, size);
return TypeUtils.CreateArrayInstance(elementType, size);
}
/// <inheritdoc />
@@ -35,7 +35,7 @@ namespace FlaxEditor.CustomEditors.Editors
// Allocate new array
var arrayType = Values.Type;
var elementType = arrayType.GetElementType();
var newValues = Array.CreateInstance(elementType, newSize);
var newValues = TypeUtils.CreateArrayInstance(elementType, newSize);
var sharedCount = Mathf.Min(oldSize, newSize);
if (array != null && sharedCount > 0)
@@ -52,7 +52,7 @@ namespace FlaxEditor.CustomEditors.Editors
else
{
// Initialize new entries with default values
var defaultValue = TypeUtils.GetDefaultValue(new ScriptType(elementType));
var defaultValue = TypeUtils.GetDefaultValue(elementType);
for (int i = oldSize; i < newSize; i++)
newValues.SetValue(defaultValue, i);
}
@@ -60,7 +60,7 @@ namespace FlaxEditor.CustomEditors.Editors
else if (newSize > 0)
{
// Initialize new entries with default values
var defaultValue = TypeUtils.GetDefaultValue(new ScriptType(elementType));
var defaultValue = TypeUtils.GetDefaultValue(elementType);
for (int i = 0; i < newSize; i++)
newValues.SetValue(defaultValue, i);
}
@@ -79,7 +79,7 @@ namespace FlaxEditor.CustomEditors.Editors
var size = array.Length;
var arrayType = Values.Type;
var elementType = arrayType.GetElementType();
var cloned = Array.CreateInstance(elementType, size);
var cloned = TypeUtils.CreateArrayInstance(elementType, size);
Array.Copy(array, 0, cloned, 0, size);

View File

@@ -101,7 +101,7 @@ namespace FlaxEditor.CustomEditors.Editors
get
{
var type = Values.Type;
return new ScriptType(type.IsGenericType ? type.GetGenericArguments()[0] : type.GetElementType());
return type.IsGenericType ? new ScriptType(type.GetGenericArguments()[0]) : type.GetElementType();
}
}

View File

@@ -142,22 +142,6 @@ namespace FlaxEditor.CustomEditors.Editors
private bool _canEditKeys;
private bool _keyEdited;
/// <summary>
/// Determines whether this editor[can edit the specified dictionary type.
/// </summary>
/// <param name="type">Type of the dictionary.</param>
/// <returns>True if can edit, otherwise false.</returns>
public static bool CanEditType(Type type)
{
// Ensure it's a generic dictionary type
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary<,>))
{
return true;
}
return false;
}
/// <summary>
/// Gets the length of the collection.
/// </summary>