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