Refactor #2746 to use ScriptingObjectInterfaceReference for C# too instead of attribute
Use `MarshalAs=ScriptingObject*` for more universal way of marshaling data between C++ and C#
This commit is contained in:
@@ -1,15 +1,62 @@
|
||||
// Copyright (c) Wojciech Figat. All rights reserved.
|
||||
|
||||
using FlaxEditor.Content;
|
||||
using FlaxEngine;
|
||||
using FlaxEngine.TypeConverters;
|
||||
using FlaxEngine.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.Design.Serialization;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using FlaxEditor.Content;
|
||||
using FlaxEngine;
|
||||
using FlaxEngine.Utilities;
|
||||
|
||||
namespace FlaxEngine.TypeConverters
|
||||
{
|
||||
/// <summary>
|
||||
/// Internal ITypeDescriptorContext used to pass some context for custom TypeConvert implementations.
|
||||
/// Allows passing CurrentType to TypeConverter.ConvertFrom method to support custom type conversion for FlaxEngine types (simpler than PropertyDescriptor.PropertyType).
|
||||
/// </summary>
|
||||
internal sealed class DummyTypeDescriptorContext : ITypeDescriptorContext
|
||||
{
|
||||
private static DummyTypeDescriptorContext _cached;
|
||||
|
||||
public Type CurrentType;
|
||||
|
||||
public static object ConvertFrom(TypeConverter converter, object value, Type type)
|
||||
{
|
||||
if (_cached == null)
|
||||
_cached = new DummyTypeDescriptorContext();
|
||||
_cached.CurrentType = type;
|
||||
var result = converter.ConvertFrom(_cached, CultureInfo.CurrentUICulture, value);
|
||||
_cached.CurrentType = null;
|
||||
return result;
|
||||
}
|
||||
|
||||
public object GetService(Type serviceType)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public void OnComponentChanged()
|
||||
{
|
||||
}
|
||||
|
||||
public bool OnComponentChanging()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public IContainer Container => null;
|
||||
|
||||
public object Instance => null;
|
||||
|
||||
public PropertyDescriptor PropertyDescriptor => null;
|
||||
}
|
||||
}
|
||||
|
||||
namespace FlaxEditor.Scripting
|
||||
{
|
||||
@@ -681,7 +728,7 @@ namespace FlaxEditor.Scripting
|
||||
if (converter.CanConvertTo(type))
|
||||
value = converter.ConvertTo(value, type);
|
||||
else if (converter.CanConvertFrom(valueType))
|
||||
value = converter.ConvertFrom(null, null, value);
|
||||
value = DummyTypeDescriptorContext.ConvertFrom(converter, value, type);
|
||||
}
|
||||
|
||||
if (_managed is PropertyInfo propertyInfo)
|
||||
|
||||
Reference in New Issue
Block a user