Improve generated bindings code usability in Editor
This commit is contained in:
@@ -16,6 +16,9 @@ namespace FlaxEngine.Interop
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Wrapper for managed arrays which are passed to unmanaged code.
|
/// Wrapper for managed arrays which are passed to unmanaged code.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
public unsafe class ManagedArray
|
public unsafe class ManagedArray
|
||||||
{
|
{
|
||||||
private ManagedHandle _pinnedArrayHandle;
|
private ManagedHandle _pinnedArrayHandle;
|
||||||
@@ -266,6 +269,9 @@ namespace FlaxEngine.Interop
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
internal static class ManagedString
|
internal static class ManagedString
|
||||||
{
|
{
|
||||||
internal static ManagedHandle EmptyStringHandle = ManagedHandle.Alloc(string.Empty);
|
internal static ManagedHandle EmptyStringHandle = ManagedHandle.Alloc(string.Empty);
|
||||||
@@ -315,6 +321,9 @@ namespace FlaxEngine.Interop
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handle to managed objects which can be stored in native code.
|
/// Handle to managed objects which can be stored in native code.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
public struct ManagedHandle
|
public struct ManagedHandle
|
||||||
{
|
{
|
||||||
private IntPtr handle;
|
private IntPtr handle;
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ using System.Runtime.InteropServices.Marshalling;
|
|||||||
|
|
||||||
namespace FlaxEngine.Interop
|
namespace FlaxEngine.Interop
|
||||||
{
|
{
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
[CustomMarshaller(typeof(object), MarshalMode.ManagedToUnmanagedIn, typeof(ManagedHandleMarshaller.ManagedToNative))]
|
[CustomMarshaller(typeof(object), MarshalMode.ManagedToUnmanagedIn, typeof(ManagedHandleMarshaller.ManagedToNative))]
|
||||||
[CustomMarshaller(typeof(object), MarshalMode.UnmanagedToManagedOut, typeof(ManagedHandleMarshaller.ManagedToNative))]
|
[CustomMarshaller(typeof(object), MarshalMode.UnmanagedToManagedOut, typeof(ManagedHandleMarshaller.ManagedToNative))]
|
||||||
[CustomMarshaller(typeof(object), MarshalMode.ElementIn, typeof(ManagedHandleMarshaller.ManagedToNative))]
|
[CustomMarshaller(typeof(object), MarshalMode.ElementIn, typeof(ManagedHandleMarshaller.ManagedToNative))]
|
||||||
@@ -23,6 +26,9 @@ namespace FlaxEngine.Interop
|
|||||||
[CustomMarshaller(typeof(object), MarshalMode.ElementRef, typeof(ManagedHandleMarshaller))]
|
[CustomMarshaller(typeof(object), MarshalMode.ElementRef, typeof(ManagedHandleMarshaller))]
|
||||||
public static class ManagedHandleMarshaller
|
public static class ManagedHandleMarshaller
|
||||||
{
|
{
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
public static class NativeToManaged
|
public static class NativeToManaged
|
||||||
{
|
{
|
||||||
public static object ConvertToManaged(IntPtr unmanaged) => unmanaged == IntPtr.Zero ? null : ManagedHandle.FromIntPtr(unmanaged).Target;
|
public static object ConvertToManaged(IntPtr unmanaged) => unmanaged == IntPtr.Zero ? null : ManagedHandle.FromIntPtr(unmanaged).Target;
|
||||||
@@ -33,6 +39,9 @@ namespace FlaxEngine.Interop
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
public static class ManagedToNative
|
public static class ManagedToNative
|
||||||
{
|
{
|
||||||
public static IntPtr ConvertToUnmanaged(object managed) => managed != null ? ManagedHandle.ToIntPtr(managed, GCHandleType.Weak) : IntPtr.Zero;
|
public static IntPtr ConvertToUnmanaged(object managed) => managed != null ? ManagedHandle.ToIntPtr(managed, GCHandleType.Weak) : IntPtr.Zero;
|
||||||
@@ -48,6 +57,9 @@ namespace FlaxEngine.Interop
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
public struct Bidirectional
|
public struct Bidirectional
|
||||||
{
|
{
|
||||||
object managed;
|
object managed;
|
||||||
@@ -99,6 +111,9 @@ namespace FlaxEngine.Interop
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
[CustomMarshaller(typeof(Type), MarshalMode.Default, typeof(SystemTypeMarshaller))]
|
[CustomMarshaller(typeof(Type), MarshalMode.Default, typeof(SystemTypeMarshaller))]
|
||||||
public static class SystemTypeMarshaller
|
public static class SystemTypeMarshaller
|
||||||
{
|
{
|
||||||
@@ -118,6 +133,9 @@ namespace FlaxEngine.Interop
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
[CustomMarshaller(typeof(Exception), MarshalMode.Default, typeof(ExceptionMarshaller))]
|
[CustomMarshaller(typeof(Exception), MarshalMode.Default, typeof(ExceptionMarshaller))]
|
||||||
public static class ExceptionMarshaller
|
public static class ExceptionMarshaller
|
||||||
{
|
{
|
||||||
@@ -126,6 +144,9 @@ namespace FlaxEngine.Interop
|
|||||||
public static void Free(IntPtr unmanaged) => ManagedHandleMarshaller.Free(unmanaged);
|
public static void Free(IntPtr unmanaged) => ManagedHandleMarshaller.Free(unmanaged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
[CustomMarshaller(typeof(FlaxEngine.Object), MarshalMode.ManagedToUnmanagedIn, typeof(ObjectMarshaller.ManagedToNative))]
|
[CustomMarshaller(typeof(FlaxEngine.Object), MarshalMode.ManagedToUnmanagedIn, typeof(ObjectMarshaller.ManagedToNative))]
|
||||||
[CustomMarshaller(typeof(FlaxEngine.Object), MarshalMode.UnmanagedToManagedOut, typeof(ObjectMarshaller.ManagedToNative))]
|
[CustomMarshaller(typeof(FlaxEngine.Object), MarshalMode.UnmanagedToManagedOut, typeof(ObjectMarshaller.ManagedToNative))]
|
||||||
[CustomMarshaller(typeof(FlaxEngine.Object), MarshalMode.ElementIn, typeof(ObjectMarshaller.ManagedToNative))]
|
[CustomMarshaller(typeof(FlaxEngine.Object), MarshalMode.ElementIn, typeof(ObjectMarshaller.ManagedToNative))]
|
||||||
@@ -134,17 +155,26 @@ namespace FlaxEngine.Interop
|
|||||||
[CustomMarshaller(typeof(FlaxEngine.Object), MarshalMode.ElementOut, typeof(ObjectMarshaller.NativeToManaged))]
|
[CustomMarshaller(typeof(FlaxEngine.Object), MarshalMode.ElementOut, typeof(ObjectMarshaller.NativeToManaged))]
|
||||||
public static class ObjectMarshaller
|
public static class ObjectMarshaller
|
||||||
{
|
{
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
public static class NativeToManaged
|
public static class NativeToManaged
|
||||||
{
|
{
|
||||||
public static FlaxEngine.Object ConvertToManaged(IntPtr unmanaged) => unmanaged != IntPtr.Zero ? Unsafe.As<FlaxEngine.Object>(ManagedHandle.FromIntPtr(unmanaged).Target) : null;
|
public static FlaxEngine.Object ConvertToManaged(IntPtr unmanaged) => unmanaged != IntPtr.Zero ? Unsafe.As<FlaxEngine.Object>(ManagedHandle.FromIntPtr(unmanaged).Target) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
public static class ManagedToNative
|
public static class ManagedToNative
|
||||||
{
|
{
|
||||||
public static IntPtr ConvertToUnmanaged(FlaxEngine.Object managed) => Unsafe.As<object>(managed) != null ? ManagedHandle.ToIntPtr(managed) : IntPtr.Zero;
|
public static IntPtr ConvertToUnmanaged(FlaxEngine.Object managed) => Unsafe.As<object>(managed) != null ? ManagedHandle.ToIntPtr(managed) : IntPtr.Zero;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
[CustomMarshaller(typeof(CultureInfo), MarshalMode.Default, typeof(CultureInfoMarshaller))]
|
[CustomMarshaller(typeof(CultureInfo), MarshalMode.Default, typeof(CultureInfoMarshaller))]
|
||||||
public static class CultureInfoMarshaller
|
public static class CultureInfoMarshaller
|
||||||
{
|
{
|
||||||
@@ -159,6 +189,9 @@ namespace FlaxEngine.Interop
|
|||||||
[CustomMarshaller(typeof(Array), MarshalMode.UnmanagedToManagedIn, typeof(SystemArrayMarshaller.NativeToManaged))]
|
[CustomMarshaller(typeof(Array), MarshalMode.UnmanagedToManagedIn, typeof(SystemArrayMarshaller.NativeToManaged))]
|
||||||
public static unsafe class SystemArrayMarshaller
|
public static unsafe class SystemArrayMarshaller
|
||||||
{
|
{
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
public struct ManagedToNative
|
public struct ManagedToNative
|
||||||
{
|
{
|
||||||
ManagedArray managedArray;
|
ManagedArray managedArray;
|
||||||
@@ -187,6 +220,9 @@ namespace FlaxEngine.Interop
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
public struct NativeToManaged
|
public struct NativeToManaged
|
||||||
{
|
{
|
||||||
ManagedHandle handle;
|
ManagedHandle handle;
|
||||||
@@ -217,6 +253,9 @@ namespace FlaxEngine.Interop
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
[CustomMarshaller(typeof(Dictionary<,>), MarshalMode.ManagedToUnmanagedIn, typeof(DictionaryMarshaller<,>.ManagedToNative))]
|
[CustomMarshaller(typeof(Dictionary<,>), MarshalMode.ManagedToUnmanagedIn, typeof(DictionaryMarshaller<,>.ManagedToNative))]
|
||||||
[CustomMarshaller(typeof(Dictionary<,>), MarshalMode.UnmanagedToManagedOut, typeof(DictionaryMarshaller<,>.ManagedToNative))]
|
[CustomMarshaller(typeof(Dictionary<,>), MarshalMode.UnmanagedToManagedOut, typeof(DictionaryMarshaller<,>.ManagedToNative))]
|
||||||
[CustomMarshaller(typeof(Dictionary<,>), MarshalMode.ElementIn, typeof(DictionaryMarshaller<,>.ManagedToNative))]
|
[CustomMarshaller(typeof(Dictionary<,>), MarshalMode.ElementIn, typeof(DictionaryMarshaller<,>.ManagedToNative))]
|
||||||
@@ -228,21 +267,31 @@ namespace FlaxEngine.Interop
|
|||||||
[CustomMarshaller(typeof(Dictionary<,>), MarshalMode.ElementRef, typeof(DictionaryMarshaller<,>))]
|
[CustomMarshaller(typeof(Dictionary<,>), MarshalMode.ElementRef, typeof(DictionaryMarshaller<,>))]
|
||||||
public static unsafe class DictionaryMarshaller<T, U>
|
public static unsafe class DictionaryMarshaller<T, U>
|
||||||
{
|
{
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
public static class NativeToManaged
|
public static class NativeToManaged
|
||||||
{
|
{
|
||||||
public static Dictionary<T, U> ConvertToManaged(IntPtr unmanaged) => DictionaryMarshaller<T, U>.ToManaged(unmanaged);
|
public static Dictionary<T, U> ConvertToManaged(IntPtr unmanaged) => DictionaryMarshaller<T, U>.ToManaged(unmanaged);
|
||||||
public static void Free(IntPtr unmanaged) => DictionaryMarshaller<T, U>.Free(unmanaged);
|
public static void Free(IntPtr unmanaged) => DictionaryMarshaller<T, U>.Free(unmanaged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
public static class ManagedToNative
|
public static class ManagedToNative
|
||||||
{
|
{
|
||||||
public static IntPtr ConvertToUnmanaged(Dictionary<T, U> managed) => DictionaryMarshaller<T, U>.ToNative(managed, GCHandleType.Weak);
|
public static IntPtr ConvertToUnmanaged(Dictionary<T, U> managed) => DictionaryMarshaller<T, U>.ToNative(managed, GCHandleType.Weak);
|
||||||
|
|
||||||
public static void Free(IntPtr unmanaged)
|
public static void Free(IntPtr unmanaged)
|
||||||
{
|
{
|
||||||
//DictionaryMarshaller<T, U>.Free(unmanaged); // No need to free weak handles
|
//DictionaryMarshaller<T, U>.Free(unmanaged); // No need to free weak handles
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
public struct Bidirectional
|
public struct Bidirectional
|
||||||
{
|
{
|
||||||
Dictionary<T, U> managed;
|
Dictionary<T, U> managed;
|
||||||
@@ -281,6 +330,9 @@ namespace FlaxEngine.Interop
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
[CustomMarshaller(typeof(CustomMarshallerAttribute.GenericPlaceholder[]), MarshalMode.ManagedToUnmanagedIn, typeof(ArrayMarshaller<,>.ManagedToNative))]
|
[CustomMarshaller(typeof(CustomMarshallerAttribute.GenericPlaceholder[]), MarshalMode.ManagedToUnmanagedIn, typeof(ArrayMarshaller<,>.ManagedToNative))]
|
||||||
[CustomMarshaller(typeof(CustomMarshallerAttribute.GenericPlaceholder[]), MarshalMode.UnmanagedToManagedOut, typeof(ArrayMarshaller<,>.ManagedToNative))]
|
[CustomMarshaller(typeof(CustomMarshallerAttribute.GenericPlaceholder[]), MarshalMode.UnmanagedToManagedOut, typeof(ArrayMarshaller<,>.ManagedToNative))]
|
||||||
[CustomMarshaller(typeof(CustomMarshallerAttribute.GenericPlaceholder[]), MarshalMode.ElementIn, typeof(ArrayMarshaller<,>.ManagedToNative))]
|
[CustomMarshaller(typeof(CustomMarshallerAttribute.GenericPlaceholder[]), MarshalMode.ElementIn, typeof(ArrayMarshaller<,>.ManagedToNative))]
|
||||||
@@ -293,6 +345,9 @@ namespace FlaxEngine.Interop
|
|||||||
[ContiguousCollectionMarshaller]
|
[ContiguousCollectionMarshaller]
|
||||||
public static unsafe class ArrayMarshaller<T, TUnmanagedElement> where TUnmanagedElement : unmanaged
|
public static unsafe class ArrayMarshaller<T, TUnmanagedElement> where TUnmanagedElement : unmanaged
|
||||||
{
|
{
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
public static class NativeToManaged
|
public static class NativeToManaged
|
||||||
{
|
{
|
||||||
public static T[]? AllocateContainerForManagedElements(TUnmanagedElement* unmanaged, int numElements)
|
public static T[]? AllocateContainerForManagedElements(TUnmanagedElement* unmanaged, int numElements)
|
||||||
@@ -330,6 +385,9 @@ namespace FlaxEngine.Interop
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
public static class ManagedToNative
|
public static class ManagedToNative
|
||||||
{
|
{
|
||||||
public static TUnmanagedElement* AllocateContainerForUnmanagedElements(T[]? managed, out int numElements)
|
public static TUnmanagedElement* AllocateContainerForUnmanagedElements(T[]? managed, out int numElements)
|
||||||
@@ -364,6 +422,9 @@ namespace FlaxEngine.Interop
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
public struct Bidirectional
|
public struct Bidirectional
|
||||||
{
|
{
|
||||||
T[] managedArray;
|
T[] managedArray;
|
||||||
@@ -460,6 +521,9 @@ namespace FlaxEngine.Interop
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
[CustomMarshaller(typeof(string), MarshalMode.ManagedToUnmanagedIn, typeof(StringMarshaller.ManagedToNative))]
|
[CustomMarshaller(typeof(string), MarshalMode.ManagedToUnmanagedIn, typeof(StringMarshaller.ManagedToNative))]
|
||||||
[CustomMarshaller(typeof(string), MarshalMode.UnmanagedToManagedOut, typeof(StringMarshaller.ManagedToNative))]
|
[CustomMarshaller(typeof(string), MarshalMode.UnmanagedToManagedOut, typeof(StringMarshaller.ManagedToNative))]
|
||||||
[CustomMarshaller(typeof(string), MarshalMode.ElementIn, typeof(StringMarshaller.ManagedToNative))]
|
[CustomMarshaller(typeof(string), MarshalMode.ElementIn, typeof(StringMarshaller.ManagedToNative))]
|
||||||
@@ -471,12 +535,18 @@ namespace FlaxEngine.Interop
|
|||||||
[CustomMarshaller(typeof(string), MarshalMode.ElementRef, typeof(StringMarshaller))]
|
[CustomMarshaller(typeof(string), MarshalMode.ElementRef, typeof(StringMarshaller))]
|
||||||
public static class StringMarshaller
|
public static class StringMarshaller
|
||||||
{
|
{
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
public static class NativeToManaged
|
public static class NativeToManaged
|
||||||
{
|
{
|
||||||
public static string ConvertToManaged(IntPtr unmanaged) => ManagedString.ToManaged(unmanaged);
|
public static string ConvertToManaged(IntPtr unmanaged) => ManagedString.ToManaged(unmanaged);
|
||||||
public static void Free(IntPtr unmanaged) => ManagedString.Free(unmanaged);
|
public static void Free(IntPtr unmanaged) => ManagedString.Free(unmanaged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
public static class ManagedToNative
|
public static class ManagedToNative
|
||||||
{
|
{
|
||||||
public static unsafe IntPtr ConvertToUnmanaged(string managed)
|
public static unsafe IntPtr ConvertToUnmanaged(string managed)
|
||||||
@@ -490,6 +560,9 @@ namespace FlaxEngine.Interop
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
public struct Bidirectional
|
public struct Bidirectional
|
||||||
{
|
{
|
||||||
string managed;
|
string managed;
|
||||||
|
|||||||
@@ -1294,6 +1294,9 @@ namespace Flax.Build.Bindings
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Marshaller for type <see cref="{{classInfo.Name}}"/>.
|
/// Marshaller for type <see cref="{{classInfo.Name}}"/>.
|
||||||
/// </summary>");
|
/// </summary>");
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
[CustomMarshaller(typeof({{classInfo.Name}}), MarshalMode.ManagedToUnmanagedIn, typeof({{marshallerName}}.ManagedToNative))]
|
[CustomMarshaller(typeof({{classInfo.Name}}), MarshalMode.ManagedToUnmanagedIn, typeof({{marshallerName}}.ManagedToNative))]
|
||||||
[CustomMarshaller(typeof({{classInfo.Name}}), MarshalMode.UnmanagedToManagedOut, typeof({{marshallerName}}.ManagedToNative))]
|
[CustomMarshaller(typeof({{classInfo.Name}}), MarshalMode.UnmanagedToManagedOut, typeof({{marshallerName}}.ManagedToNative))]
|
||||||
[CustomMarshaller(typeof({{classInfo.Name}}), MarshalMode.ElementIn, typeof({{marshallerName}}.ManagedToNative))]
|
[CustomMarshaller(typeof({{classInfo.Name}}), MarshalMode.ElementIn, typeof({{marshallerName}}.ManagedToNative))]
|
||||||
@@ -1306,17 +1309,25 @@ namespace Flax.Build.Bindings
|
|||||||
{{GenerateCSharpAccessLevel(classInfo.Access)}}static class {{marshallerName}}
|
{{GenerateCSharpAccessLevel(classInfo.Access)}}static class {{marshallerName}}
|
||||||
{
|
{
|
||||||
#pragma warning disable 1591
|
#pragma warning disable 1591
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
public static class NativeToManaged
|
public static class NativeToManaged
|
||||||
{
|
{
|
||||||
public static {{classInfo.Name}} ConvertToManaged(IntPtr unmanaged) => Unsafe.As<{{classInfo.Name}}>(ManagedHandleMarshaller.NativeToManaged.ConvertToManaged(unmanaged));
|
public static {{classInfo.Name}} ConvertToManaged(IntPtr unmanaged) => Unsafe.As<{{classInfo.Name}}>(ManagedHandleMarshaller.NativeToManaged.ConvertToManaged(unmanaged));
|
||||||
public static void Free(IntPtr unmanaged) => ManagedHandleMarshaller.NativeToManaged.Free(unmanaged);
|
public static void Free(IntPtr unmanaged) => ManagedHandleMarshaller.NativeToManaged.Free(unmanaged);
|
||||||
}
|
}
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
public static class ManagedToNative
|
public static class ManagedToNative
|
||||||
{
|
{
|
||||||
public static IntPtr ConvertToUnmanaged({{classInfo.Name}} managed) => ManagedHandleMarshaller.ManagedToNative.ConvertToUnmanaged(managed);
|
public static IntPtr ConvertToUnmanaged({{classInfo.Name}} managed) => ManagedHandleMarshaller.ManagedToNative.ConvertToUnmanaged(managed);
|
||||||
public static void Free(IntPtr unmanaged) => ManagedHandleMarshaller.ManagedToNative.Free(unmanaged);
|
public static void Free(IntPtr unmanaged) => ManagedHandleMarshaller.ManagedToNative.Free(unmanaged);
|
||||||
}
|
}
|
||||||
|
#if FLAX_EDITOR
|
||||||
[HideInEditor]
|
[HideInEditor]
|
||||||
|
#endif
|
||||||
public struct Bidirectional
|
public struct Bidirectional
|
||||||
{
|
{
|
||||||
ManagedHandleMarshaller.Bidirectional marsh;
|
ManagedHandleMarshaller.Bidirectional marsh;
|
||||||
@@ -1365,6 +1376,8 @@ namespace Flax.Build.Bindings
|
|||||||
contents.Append(indent).AppendLine($"/// <summary>");
|
contents.Append(indent).AppendLine($"/// <summary>");
|
||||||
contents.Append(indent).AppendLine($"/// Marshaller for type <see cref=\"{structureInfo.Name}\"/>.");
|
contents.Append(indent).AppendLine($"/// Marshaller for type <see cref=\"{structureInfo.Name}\"/>.");
|
||||||
contents.Append(indent).AppendLine($"/// </summary>");
|
contents.Append(indent).AppendLine($"/// </summary>");
|
||||||
|
if (buildData.Target != null & buildData.Target.IsEditor)
|
||||||
|
contents.Append(indent).AppendLine("[HideInEditor]");
|
||||||
contents.Append(indent).AppendLine($"[CustomMarshaller(typeof({structureInfo.Name}), MarshalMode.ManagedToUnmanagedIn, typeof({marshallerName}.ManagedToNative))]");
|
contents.Append(indent).AppendLine($"[CustomMarshaller(typeof({structureInfo.Name}), MarshalMode.ManagedToUnmanagedIn, typeof({marshallerName}.ManagedToNative))]");
|
||||||
contents.Append(indent).AppendLine($"[CustomMarshaller(typeof({structureInfo.Name}), MarshalMode.UnmanagedToManagedOut, typeof({marshallerName}.ManagedToNative))]");
|
contents.Append(indent).AppendLine($"[CustomMarshaller(typeof({structureInfo.Name}), MarshalMode.UnmanagedToManagedOut, typeof({marshallerName}.ManagedToNative))]");
|
||||||
contents.Append(indent).AppendLine($"[CustomMarshaller(typeof({structureInfo.Name}), MarshalMode.ElementIn, typeof({marshallerName}.ManagedToNative))]");
|
contents.Append(indent).AppendLine($"[CustomMarshaller(typeof({structureInfo.Name}), MarshalMode.ElementIn, typeof({marshallerName}.ManagedToNative))]");
|
||||||
@@ -1389,7 +1402,8 @@ namespace Flax.Build.Bindings
|
|||||||
// Native struct begin
|
// Native struct begin
|
||||||
// TODO: skip using this utility structure if the auto-generated C# struct is already the same as XXXInternal here below
|
// TODO: skip using this utility structure if the auto-generated C# struct is already the same as XXXInternal here below
|
||||||
GenerateCSharpAttributes(buildData, contents, indent, structureInfo, true);
|
GenerateCSharpAttributes(buildData, contents, indent, structureInfo, true);
|
||||||
contents.Append(indent).AppendLine("[HideInEditor]");
|
if (buildData.Target != null & buildData.Target.IsEditor)
|
||||||
|
contents.Append(indent).AppendLine("[HideInEditor]");
|
||||||
contents.Append(indent).AppendLine("[StructLayout(LayoutKind.Sequential)]");
|
contents.Append(indent).AppendLine("[StructLayout(LayoutKind.Sequential)]");
|
||||||
contents.Append(indent).Append("public struct ").Append(structureInfo.Name).Append("Internal");
|
contents.Append(indent).Append("public struct ").Append(structureInfo.Name).Append("Internal");
|
||||||
if (structureInfo.BaseType != null && structureInfo.IsPod)
|
if (structureInfo.BaseType != null && structureInfo.IsPod)
|
||||||
@@ -1625,13 +1639,17 @@ namespace Flax.Build.Bindings
|
|||||||
|
|
||||||
// NativeToManaged stateless shape
|
// NativeToManaged stateless shape
|
||||||
// NOTE: GCHandles of FlaxEngine.Object must not be released in this case
|
// NOTE: GCHandles of FlaxEngine.Object must not be released in this case
|
||||||
contents.Append(indent).AppendLine($"public static class NativeToManaged").Append(indent).AppendLine("{");
|
if (buildData.Target != null && buildData.Target.IsEditor)
|
||||||
|
contents.Append(indent).AppendLine("[HideInEditor]");
|
||||||
|
contents.Append(indent).AppendLine("public static class NativeToManaged").Append(indent).AppendLine("{");
|
||||||
contents.Append(indent2).AppendLine($"public static {structureInfo.Name} ConvertToManaged({structureInfo.Name}Internal unmanaged) => {marshallerName}.ToManaged(unmanaged);");
|
contents.Append(indent2).AppendLine($"public static {structureInfo.Name} ConvertToManaged({structureInfo.Name}Internal unmanaged) => {marshallerName}.ToManaged(unmanaged);");
|
||||||
contents.Append(indent2).AppendLine($"public static void Free({structureInfo.Name}Internal unmanaged)");
|
contents.Append(indent2).AppendLine($"public static void Free({structureInfo.Name}Internal unmanaged)");
|
||||||
contents.Append(indent2).AppendLine("{").Append(indent3).AppendLine(freeContents2.Replace("\n", "\n" + indent3).ToString().TrimEnd()).Append(indent2).AppendLine("}");
|
contents.Append(indent2).AppendLine("{").Append(indent3).AppendLine(freeContents2.Replace("\n", "\n" + indent3).ToString().TrimEnd()).Append(indent2).AppendLine("}");
|
||||||
contents.Append(indent).AppendLine("}");
|
contents.Append(indent).AppendLine("}");
|
||||||
|
|
||||||
// ManagedToNative stateless shape
|
// ManagedToNative stateless shape
|
||||||
|
if (buildData.Target != null && buildData.Target.IsEditor)
|
||||||
|
contents.Append(indent).AppendLine("[HideInEditor]");
|
||||||
contents.Append(indent).AppendLine($"public static class ManagedToNative").Append(indent).AppendLine("{");
|
contents.Append(indent).AppendLine($"public static class ManagedToNative").Append(indent).AppendLine("{");
|
||||||
contents.Append(indent2).AppendLine($"public static {structureInfo.Name}Internal ConvertToUnmanaged({structureInfo.Name} managed) => {marshallerName}.ToNative(managed);");
|
contents.Append(indent2).AppendLine($"public static {structureInfo.Name}Internal ConvertToUnmanaged({structureInfo.Name} managed) => {marshallerName}.ToNative(managed);");
|
||||||
contents.Append(indent2).AppendLine($"public static void Free({structureInfo.Name}Internal unmanaged) => {marshallerName}.Free(unmanaged);");
|
contents.Append(indent2).AppendLine($"public static void Free({structureInfo.Name}Internal unmanaged) => {marshallerName}.Free(unmanaged);");
|
||||||
@@ -1639,7 +1657,8 @@ namespace Flax.Build.Bindings
|
|||||||
|
|
||||||
// Bidirectional stateful shape
|
// Bidirectional stateful shape
|
||||||
// NOTE: GCHandles of FlaxEngine.Object must not be released unless they were allocated by this marshaller
|
// NOTE: GCHandles of FlaxEngine.Object must not be released unless they were allocated by this marshaller
|
||||||
contents.Append(indent).AppendLine("[HideInEditor]");
|
if (buildData.Target != null && buildData.Target.IsEditor)
|
||||||
|
contents.Append(indent).AppendLine("[HideInEditor]");
|
||||||
contents.Append(indent).AppendLine($"public struct Bidirectional").Append(indent).AppendLine("{");
|
contents.Append(indent).AppendLine($"public struct Bidirectional").Append(indent).AppendLine("{");
|
||||||
contents.Append(indent2).AppendLine($"{structureInfo.Name} managed;");
|
contents.Append(indent2).AppendLine($"{structureInfo.Name} managed;");
|
||||||
contents.Append(indent2).AppendLine($"{structureInfo.Name}Internal unmanaged;");
|
contents.Append(indent2).AppendLine($"{structureInfo.Name}Internal unmanaged;");
|
||||||
@@ -1976,9 +1995,11 @@ namespace Flax.Build.Bindings
|
|||||||
{
|
{
|
||||||
string marshallerName = interfaceInfo.Name + "Marshaller";
|
string marshallerName = interfaceInfo.Name + "Marshaller";
|
||||||
contents.AppendLine();
|
contents.AppendLine();
|
||||||
contents.Append(indent).AppendLine($"/// <summary>");
|
contents.Append(indent).AppendLine("/// <summary>");
|
||||||
contents.Append(indent).AppendLine($"/// Marshaller for type <see cref=\"{interfaceInfo.Name}\"/>.");
|
contents.Append(indent).AppendLine($"/// Marshaller for type <see cref=\"{interfaceInfo.Name}\"/>.");
|
||||||
contents.Append(indent).AppendLine($"/// </summary>");
|
contents.Append(indent).AppendLine("/// </summary>");
|
||||||
|
if (buildData.Target != null & buildData.Target.IsEditor)
|
||||||
|
contents.Append(indent).AppendLine("[HideInEditor]");
|
||||||
contents.Append(indent).AppendLine($"[CustomMarshaller(typeof({interfaceInfo.Name}), MarshalMode.Default, typeof({marshallerName}))]");
|
contents.Append(indent).AppendLine($"[CustomMarshaller(typeof({interfaceInfo.Name}), MarshalMode.Default, typeof({marshallerName}))]");
|
||||||
contents.Append(indent).AppendLine($"public static class {marshallerName}");
|
contents.Append(indent).AppendLine($"public static class {marshallerName}");
|
||||||
contents.Append(indent).AppendLine("{");
|
contents.Append(indent).AppendLine("{");
|
||||||
|
|||||||
Reference in New Issue
Block a user