Merge remote-tracking branch 'origin/master' into gi

# Conflicts:
#	Source/Editor/Windows/Assets/VisualScriptWindow.cs
This commit is contained in:
Wojciech Figat
2022-05-02 10:38:14 +02:00
42 changed files with 1467 additions and 518 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

@@ -57,8 +57,9 @@ void OnBinaryModuleLoaded(BinaryModule* module);
MonoReflectionType* CustomEditorsUtil::GetCustomEditor(MonoReflectionType* refType)
{
if (!refType)
return nullptr;
MonoType* type = mono_reflection_type_get_type(refType);
Entry result;
if (Cache.TryGet(type, result))
{
@@ -68,7 +69,6 @@ MonoReflectionType* CustomEditorsUtil::GetCustomEditor(MonoReflectionType* refTy
return MUtils::GetType(editor->GetNative());
}
}
return nullptr;
}

View File

@@ -59,6 +59,8 @@ namespace FlaxEditor.CustomEditors
internal static CustomEditor CreateEditor(ScriptType targetType, bool canUseRefPicker = true)
{
if (targetType == ScriptType.Null)
return new GenericEditor();
if (targetType.IsArray)
{
return new ArrayEditor();
@@ -107,7 +109,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>