From 74b23d0e00f041f780cfba5ce99f72fdf52422b4 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Sun, 1 May 2022 20:42:05 +0200 Subject: [PATCH] Add support for array of Visual Script objects --- .../Editor/Content/Items/VisualScriptItem.cs | 4 +- Source/Editor/CustomEditors/CustomEditor.cs | 4 +- .../Editor/CustomEditors/CustomEditorsUtil.cs | 2 +- .../CustomEditors/Editors/ArrayEditor.cs | 10 +- .../CustomEditors/Editors/CollectionEditor.cs | 2 +- .../CustomEditors/Editors/DictionaryEditor.cs | 16 -- Source/Editor/Scripting/ScriptType.Custom.cs | 148 ++++++++++++++++++ .../Editor/Scripting/ScriptType.Interfaces.cs | 2 +- Source/Editor/Scripting/ScriptType.cs | 25 ++- Source/Editor/Scripting/TypeUtils.cs | 36 +++-- .../Editor/Surface/Archetypes/Collections.cs | 2 +- .../Editor/Surface/Archetypes/Parameters.cs | 4 +- Source/Editor/Surface/Archetypes/Tools.cs | 6 +- Source/Editor/Surface/Elements/InputBox.cs | 2 +- Source/Editor/Surface/SurfaceStyle.cs | 4 +- .../Surface/VisjectSurface.Connecting.cs | 2 +- Source/Editor/Utilities/MemberInfoPath.cs | 2 +- Source/Editor/Utilities/ObjectSnapshot.cs | 8 +- Source/Editor/Utilities/VariantUtils.cs | 2 +- .../Windows/Assets/VisualScriptWindow.cs | 2 +- 20 files changed, 221 insertions(+), 62 deletions(-) create mode 100644 Source/Editor/Scripting/ScriptType.Custom.cs diff --git a/Source/Editor/Content/Items/VisualScriptItem.cs b/Source/Editor/Content/Items/VisualScriptItem.cs index 4ce8a0d9d..3fc030420 100644 --- a/Source/Editor/Content/Items/VisualScriptItem.cs +++ b/Source/Editor/Content/Items/VisualScriptItem.cs @@ -375,9 +375,9 @@ namespace FlaxEditor.Content } /// - public bool ImplementInterface(ScriptType c) + public bool HasInterface(ScriptType c) { - return BaseType.ImplementInterface(c); + return BaseType.HasInterface(c); } /// diff --git a/Source/Editor/CustomEditors/CustomEditor.cs b/Source/Editor/CustomEditors/CustomEditor.cs index 14e5e641f..73cc82192 100644 --- a/Source/Editor/CustomEditors/CustomEditor.cs +++ b/Source/Editor/CustomEditors/CustomEditor.cs @@ -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) diff --git a/Source/Editor/CustomEditors/CustomEditorsUtil.cs b/Source/Editor/CustomEditors/CustomEditorsUtil.cs index 27e9896ee..debd43cba 100644 --- a/Source/Editor/CustomEditors/CustomEditorsUtil.cs +++ b/Source/Editor/CustomEditors/CustomEditorsUtil.cs @@ -155,7 +155,7 @@ namespace FlaxEditor.CustomEditors } if (targetType.IsGenericType) { - if (DictionaryEditor.CanEditType(targetTypeType)) + if (targetTypeType.GetGenericTypeDefinition() == typeof(Dictionary<,>)) { return new DictionaryEditor(); } diff --git a/Source/Editor/CustomEditors/Editors/ArrayEditor.cs b/Source/Editor/CustomEditors/Editors/ArrayEditor.cs index b1d4494b0..e641dfb33 100644 --- a/Source/Editor/CustomEditors/Editors/ArrayEditor.cs +++ b/Source/Editor/CustomEditors/Editors/ArrayEditor.cs @@ -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); } /// @@ -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); diff --git a/Source/Editor/CustomEditors/Editors/CollectionEditor.cs b/Source/Editor/CustomEditors/Editors/CollectionEditor.cs index 5deff5d71..28a15cd47 100644 --- a/Source/Editor/CustomEditors/Editors/CollectionEditor.cs +++ b/Source/Editor/CustomEditors/Editors/CollectionEditor.cs @@ -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(); } } diff --git a/Source/Editor/CustomEditors/Editors/DictionaryEditor.cs b/Source/Editor/CustomEditors/Editors/DictionaryEditor.cs index 5f6dacc9f..5035a48f5 100644 --- a/Source/Editor/CustomEditors/Editors/DictionaryEditor.cs +++ b/Source/Editor/CustomEditors/Editors/DictionaryEditor.cs @@ -142,22 +142,6 @@ namespace FlaxEditor.CustomEditors.Editors private bool _canEditKeys; private bool _keyEdited; - /// - /// Determines whether this editor[can edit the specified dictionary type. - /// - /// Type of the dictionary. - /// True if can edit, otherwise false. - public static bool CanEditType(Type type) - { - // Ensure it's a generic dictionary type - if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary<,>)) - { - return true; - } - - return false; - } - /// /// Gets the length of the collection. /// diff --git a/Source/Editor/Scripting/ScriptType.Custom.cs b/Source/Editor/Scripting/ScriptType.Custom.cs new file mode 100644 index 000000000..17fbfa261 --- /dev/null +++ b/Source/Editor/Scripting/ScriptType.Custom.cs @@ -0,0 +1,148 @@ +// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. + +using System; +using System.Reflection; +using FlaxEditor.Content; +using FlaxEngine; + +namespace FlaxEditor.Scripting +{ + /// + /// The implementation of the for array of custom script type. + /// + [HideInEditor] + internal sealed class ScriptTypeArray : IScriptType + { + /// + /// The array element type. + /// + public readonly ScriptType ElementType; + + /// + /// Initializes a new instance of the class. + /// + /// Type of the array element. + public ScriptTypeArray(ScriptType elementType) + { + ElementType = elementType; + } + + /// + public string Name => ElementType + "[]"; + + /// + public string Namespace => ElementType.Namespace; + + /// + public string TypeName + { + get + { + var result = ElementType + "[]"; + var nameSpace = ElementType.Namespace; + if (nameSpace.Length != 0) + result = nameSpace + '.'; + return result; + } + } + + /// + public bool IsPublic => ElementType.IsPublic; + + /// + public bool IsAbstract => false; + + /// + public bool IsSealed => true; + + /// + public bool IsEnum => false; + + /// + public bool IsClass => true; + + /// + public bool IsInterface => false; + + /// + public bool IsArray => true; + + /// + public bool IsValueType => false; + + /// + public bool IsGenericType => false; + + /// + public bool IsReference => false; + + /// + public bool IsPointer => false; + + /// + public bool IsStatic => false; + + /// + public bool CanCreateInstance => false; + + /// + public ScriptType BaseType => new ScriptType(typeof(Array)); + + /// + public ContentItem ContentItem => null; + + /// + public object CreateInstance() + { + return null; + } + + /// + public bool HasInterface(ScriptType c) + { + return false; + } + + /// + public bool HasAttribute(Type attributeType, bool inherit) + { + return false; + } + + /// + public object[] GetAttributes(bool inherit) + { + return Utils.GetEmptyArray(); + } + + /// + public ScriptMemberInfo[] GetMembers(string name, MemberTypes type, BindingFlags bindingAttr) + { + return Utils.GetEmptyArray(); + } + + /// + public ScriptMemberInfo[] GetMembers(BindingFlags bindingAttr) + { + return Utils.GetEmptyArray(); + } + + /// + public ScriptMemberInfo[] GetFields(BindingFlags bindingAttr) + { + return Utils.GetEmptyArray(); + } + + /// + public ScriptMemberInfo[] GetProperties(BindingFlags bindingAttr) + { + return Utils.GetEmptyArray(); + } + + /// + public ScriptMemberInfo[] GetMethods(BindingFlags bindingAttr) + { + return Utils.GetEmptyArray(); + } + } +} diff --git a/Source/Editor/Scripting/ScriptType.Interfaces.cs b/Source/Editor/Scripting/ScriptType.Interfaces.cs index 1239bd155..1e27dd5b9 100644 --- a/Source/Editor/Scripting/ScriptType.Interfaces.cs +++ b/Source/Editor/Scripting/ScriptType.Interfaces.cs @@ -113,7 +113,7 @@ namespace FlaxEditor.Scripting /// /// The type of the interface to check. /// True if this type implements the given interface, otherwise false. - bool ImplementInterface(ScriptType c); + bool HasInterface(ScriptType c); /// /// Determines whether the specified attribute was defined for this type. diff --git a/Source/Editor/Scripting/ScriptType.cs b/Source/Editor/Scripting/ScriptType.cs index 402612c88..8ddb2a514 100644 --- a/Source/Editor/Scripting/ScriptType.cs +++ b/Source/Editor/Scripting/ScriptType.cs @@ -703,6 +703,11 @@ namespace FlaxEditor.Scripting /// public static readonly ScriptType Object = new ScriptType(typeof(object)); + /// + /// A that is FlaxEngine.Object. + /// + public static readonly ScriptType FlaxObject = new ScriptType(typeof(FlaxEngine.Object)); + /// /// Gets the type of the script as . /// @@ -827,7 +832,7 @@ namespace FlaxEditor.Scripting { if (_managed != null) return _managed.GetConstructor(Type.EmptyTypes) != null; - return _custom.CanCreateInstance; + return _custom?.CanCreateInstance ?? false; } } @@ -1003,12 +1008,12 @@ namespace FlaxEditor.Scripting /// /// The type of the interface to check. /// True if this type implements the given interface, otherwise false. - public bool ImplementInterface(ScriptType c) + public bool HasInterface(ScriptType c) { if (c._managed != null && _managed != null) return c._managed.IsAssignableFrom(_managed); if (_custom != null) - return _custom.ImplementInterface(c); + return _custom.HasInterface(c); return false; } @@ -1032,7 +1037,7 @@ namespace FlaxEditor.Scripting public bool IsAssignableFrom(ScriptType c) { if (IsInterface) - return c.ImplementInterface(this); + return c.HasInterface(this); while (c != Null) { if (c == this) @@ -1075,11 +1080,13 @@ namespace FlaxEditor.Scripting /// When overridden in a derived class, returns the type of the object encompassed or referred to by the current array, pointer or reference type. /// /// The type of the object encompassed or referred to by the current array, pointer, or reference type, or if the current type is not an array or a pointer, or is not passed by reference, or represents a generic type or a type parameter in the definition of a generic type or generic method. - public Type GetElementType() + public ScriptType GetElementType() { if (_managed != null) - return _managed.GetElementType(); - throw new NotImplementedException("TODO: Script.Type.GetElementType for custom types"); + return new ScriptType(_managed.GetElementType()); + if (_custom is ScriptTypeArray array) + return array.ElementType; + return Null; } /// @@ -1112,7 +1119,9 @@ namespace FlaxEditor.Scripting { if (_managed != null) return new ScriptType(_managed.MakeArrayType()); - throw new NotImplementedException("TODO: Script.Type.MakeArrayType for custom types"); + if (_custom != null) + return new ScriptType(new ScriptTypeArray(this)); + return Null; } /// diff --git a/Source/Editor/Scripting/TypeUtils.cs b/Source/Editor/Scripting/TypeUtils.cs index 4bf02911c..9b4b0be5e 100644 --- a/Source/Editor/Scripting/TypeUtils.cs +++ b/Source/Editor/Scripting/TypeUtils.cs @@ -335,9 +335,7 @@ namespace FlaxEditor.Scripting { var type = assembly.GetType(typeName); if (type != null) - { return new ScriptType(type); - } } } @@ -346,8 +344,18 @@ namespace FlaxEditor.Scripting { var type = customTypesInfo.GetType(typeName); if (type) - { return type; + } + if (typeName.EndsWith("[]")) + { + if (typeName[0] == '.') + typeName = typeName.Substring(1); + typeName = typeName.Substring(0, typeName.Length - 2); + foreach (var customTypesInfo in CustomTypes) + { + var type = customTypesInfo.GetType(typeName); + if (type) + return type.MakeArrayType(); } } @@ -361,10 +369,10 @@ namespace FlaxEditor.Scripting /// The created object or null if failed. public static object CreateInstance(string typeName) { - var type = GetType(typeName); - if (type) + object obj = null; + ScriptType type = GetType(typeName); + if (type && type.CanCreateInstance) { - object obj = null; try { return obj = type.CreateInstance(); @@ -373,11 +381,19 @@ namespace FlaxEditor.Scripting { Debug.LogException(ex); } - - return obj; } + return obj; + } - return null; + /// + /// Creates a one-dimensional of the specified type and length. + /// + /// The type of the array to create. + /// The length of the array to create. + /// The created object or null if failed. + public static Array CreateArrayInstance(ScriptType elementType, int size) + { + return Array.CreateInstance(GetType(elementType), size); } /// @@ -402,6 +418,8 @@ namespace FlaxEditor.Scripting /// The managed type. public static Type GetType(ScriptType type) { + if (type == ScriptType.Null) + return null; while (type.Type == null) type = type.BaseType; return type.Type; diff --git a/Source/Editor/Surface/Archetypes/Collections.cs b/Source/Editor/Surface/Archetypes/Collections.cs index 3880d0975..59198e350 100644 --- a/Source/Editor/Surface/Archetypes/Collections.cs +++ b/Source/Editor/Surface/Archetypes/Collections.cs @@ -16,7 +16,7 @@ namespace FlaxEditor.Surface.Archetypes { if (type == ScriptType.Null) return box.DefaultType; - return box.DefaultType != null ? new ScriptType(type.GetElementType()) : type; + return box.DefaultType != null ? type.GetElementType() : type; } internal static ScriptType GetDictionaryItemType(Box box, ScriptType type) diff --git a/Source/Editor/Surface/Archetypes/Parameters.cs b/Source/Editor/Surface/Archetypes/Parameters.cs index 4c7b62c32..10748c447 100644 --- a/Source/Editor/Surface/Archetypes/Parameters.cs +++ b/Source/Editor/Surface/Archetypes/Parameters.cs @@ -181,9 +181,9 @@ namespace FlaxEditor.Surface.Archetypes private NodeElementArchetype[] GetElementArchetypes(SurfaceParameter selected) { - if (selected != null && selected.Type.Type != null) + if (selected != null && selected.Type != ScriptType.Null) { - if (Prototypes != null && Prototypes.TryGetValue(selected.Type.Type, out var elements)) + if (selected.Type.Type != null && Prototypes != null && Prototypes.TryGetValue(selected.Type.Type, out var elements)) { // Special case for Normal Maps if (selected.Type.Type == typeof(Texture) && UseNormalMaps && selected.Value != null) diff --git a/Source/Editor/Surface/Archetypes/Tools.cs b/Source/Editor/Surface/Archetypes/Tools.cs index 6b4da738a..3bf8909b6 100644 --- a/Source/Editor/Surface/Archetypes/Tools.cs +++ b/Source/Editor/Surface/Archetypes/Tools.cs @@ -796,7 +796,7 @@ namespace FlaxEditor.Surface.Archetypes { _picker = new TypePickerControl { - Type = new ScriptType(typeof(FlaxEngine.Object)), + Type = ScriptType.FlaxObject, Bounds = new Rectangle(FlaxEditor.Surface.Constants.NodeMarginX + 20, FlaxEditor.Surface.Constants.NodeMarginY + FlaxEditor.Surface.Constants.NodeHeaderSize, 160, 16), Parent = this, }; @@ -833,7 +833,7 @@ namespace FlaxEditor.Surface.Archetypes { var type = TypeUtils.GetType((string)Values[0]); var box = (OutputBox)GetBox(0); - box.CurrentType = type ? type : new ScriptType(typeof(FlaxEngine.Object)); + box.CurrentType = type ? type : ScriptType.FlaxObject; } /// @@ -905,7 +905,7 @@ namespace FlaxEditor.Surface.Archetypes { _picker = new TypePickerControl { - Type = new ScriptType(typeof(FlaxEngine.Object)), + Type = ScriptType.FlaxObject, Bounds = new Rectangle(FlaxEditor.Surface.Constants.NodeMarginX + 20, FlaxEditor.Surface.Constants.NodeMarginY + FlaxEditor.Surface.Constants.NodeHeaderSize, 160, 16), Parent = this, }; diff --git a/Source/Editor/Surface/Elements/InputBox.cs b/Source/Editor/Surface/Elements/InputBox.cs index 237ae69f0..06c83de7f 100644 --- a/Source/Editor/Surface/Elements/InputBox.cs +++ b/Source/Editor/Surface/Elements/InputBox.cs @@ -1078,7 +1078,7 @@ namespace FlaxEditor.Surface.Elements object obj; var type = CurrentType; - if (new ScriptType(typeof(FlaxEngine.Object)).IsAssignableFrom(type)) + if (ScriptType.FlaxObject.IsAssignableFrom(type)) { // Object reference if (text.Length != 32) diff --git a/Source/Editor/Surface/SurfaceStyle.cs b/Source/Editor/Surface/SurfaceStyle.cs index 79cab8156..b11fd698e 100644 --- a/Source/Editor/Surface/SurfaceStyle.cs +++ b/Source/Editor/Surface/SurfaceStyle.cs @@ -157,7 +157,7 @@ namespace FlaxEditor.Surface GetConnectionColor(type, hint, out color); } else if (type.IsArray) - GetConnectionColor(new ScriptType(type.GetElementType()), hint, out color); + GetConnectionColor(type.GetElementType(), hint, out color); else if (type.Type == typeof(void)) color = Colors.Impulse; else if (type.Type == typeof(bool)) @@ -180,7 +180,7 @@ namespace FlaxEditor.Surface color = Colors.Enum; else if (type.IsValueType) color = Colors.Structures; - else if (new ScriptType(typeof(FlaxEngine.Object)).IsAssignableFrom(type) || type.IsInterface) + else if (ScriptType.FlaxObject.IsAssignableFrom(type) || type.IsInterface) color = Colors.Object; else if (hint == ConnectionsHint.Vector) color = Colors.Vector; diff --git a/Source/Editor/Surface/VisjectSurface.Connecting.cs b/Source/Editor/Surface/VisjectSurface.Connecting.cs index 28fcf1f1f..fb6bc9f84 100644 --- a/Source/Editor/Surface/VisjectSurface.Connecting.cs +++ b/Source/Editor/Surface/VisjectSurface.Connecting.cs @@ -76,7 +76,7 @@ namespace FlaxEditor.Surface // Implicit casting is supported for object reference to test whenever it is valid var toType = to.Type; - if (_supportsImplicitCastFromObjectToBoolean && toType == typeof(bool) && new ScriptType(typeof(FlaxEngine.Object)).IsAssignableFrom(from)) + if (_supportsImplicitCastFromObjectToBoolean && toType == typeof(bool) && ScriptType.FlaxObject.IsAssignableFrom(from)) { return true; } diff --git a/Source/Editor/Utilities/MemberInfoPath.cs b/Source/Editor/Utilities/MemberInfoPath.cs index 99a4c7799..c76130d61 100644 --- a/Source/Editor/Utilities/MemberInfoPath.cs +++ b/Source/Editor/Utilities/MemberInfoPath.cs @@ -41,7 +41,7 @@ namespace FlaxEditor.Utilities // Special case for collections if (Index != null) - result = new ScriptType(result.GetElementType()); + result = result.GetElementType(); return result; } diff --git a/Source/Editor/Utilities/ObjectSnapshot.cs b/Source/Editor/Utilities/ObjectSnapshot.cs index 7b70438d0..3c7e7ec3a 100644 --- a/Source/Editor/Utilities/ObjectSnapshot.cs +++ b/Source/Editor/Utilities/ObjectSnapshot.cs @@ -64,11 +64,11 @@ namespace FlaxEditor.Utilities && memberValue != null && !refStack.Contains(memberValue)) { - if (memberType.IsArray && !typeof(FlaxEngine.Object).IsAssignableFrom(memberType.GetElementType())) + if (memberType.IsArray && !ScriptType.FlaxObject.IsAssignableFrom(memberType.GetElementType())) { // Array var array = (Array)memberValue; - var elementType = new ScriptType(memberType.GetElementType()); + var elementType = memberType.GetElementType(); var length = array.Length; refStack.Push(memberValue); for (int i = 0; i < length; i++) @@ -78,7 +78,7 @@ namespace FlaxEditor.Utilities } refStack.Pop(); } - else if (typeof(IList).IsAssignableFrom(memberType.Type) && !typeof(FlaxEngine.Object).IsAssignableFrom(memberType.GetElementType())) + else if (typeof(IList).IsAssignableFrom(memberType.Type) && !ScriptType.FlaxObject.IsAssignableFrom(memberType.GetElementType())) { // List var list = (IList)memberValue; @@ -105,7 +105,7 @@ namespace FlaxEditor.Utilities GetEntries(new MemberInfoPath.Entry(member.Member, key), membersPath, result, values, refStack, valueType, value); } } - else if (memberType.IsClass && !new ScriptType(typeof(FlaxEngine.Object)).IsAssignableFrom(memberType)) + else if (memberType.IsClass && !ScriptType.FlaxObject.IsAssignableFrom(memberType)) { // Object refStack.Push(memberValue); diff --git a/Source/Editor/Utilities/VariantUtils.cs b/Source/Editor/Utilities/VariantUtils.cs index 98e4a6730..8cca826ff 100644 --- a/Source/Editor/Utilities/VariantUtils.cs +++ b/Source/Editor/Utilities/VariantUtils.cs @@ -282,7 +282,7 @@ namespace FlaxEditor.Utilities case VariantType.Pointer: return new ScriptType(typeof(IntPtr)); case VariantType.String: return new ScriptType(typeof(string)); case VariantType.Typename: return new ScriptType(typeof(Type)); - case VariantType.Object: return new ScriptType(typeof(FlaxEngine.Object)); + case VariantType.Object: return ScriptType.FlaxObject; case VariantType.Asset: return new ScriptType(typeof(Asset)); case VariantType.Vector2: return new ScriptType(typeof(Vector2)); case VariantType.Vector3: return new ScriptType(typeof(Vector3)); diff --git a/Source/Editor/Windows/Assets/VisualScriptWindow.cs b/Source/Editor/Windows/Assets/VisualScriptWindow.cs index ee395cb94..2cb8fc0e8 100644 --- a/Source/Editor/Windows/Assets/VisualScriptWindow.cs +++ b/Source/Editor/Windows/Assets/VisualScriptWindow.cs @@ -203,7 +203,7 @@ namespace FlaxEditor.Windows.Assets { if (isArray) { - singleValueType = new ScriptType(param.Type.GetElementType()); + singleValueType = param.Type.GetElementType(); arrayType = param.Type; dictionaryType = ScriptType.MakeDictionaryType(new ScriptType(typeof(int)), singleValueType); b = cmType.ContextMenu.AddButton(window.Surface.GetTypeName(singleValueType) + "[]...", () => OnChangeType(item => window.SetParamType(index, ((ScriptType)item.Tag).MakeArrayType())));