From 824d6701d82df864cead332f5109987ffebf422d Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 12 Aug 2024 15:34:39 +0200 Subject: [PATCH] Add improved default value detection for scripting object references in bindings generator --- .../Bindings/BindingsGenerator.CSharp.cs | 15 ++++++++++++++- Source/Tools/Flax.Build/Bindings/ClassInfo.cs | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs index 2b97a7168..7d8ba7d43 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs @@ -102,8 +102,22 @@ namespace Flax.Build.Bindings private static string GenerateCSharpDefaultValueNativeToManaged(BuildData buildData, string value, ApiTypeInfo caller, TypeInfo valueType = null, bool attribute = false, string managedType = null) { + ApiTypeInfo apiType = null; if (string.IsNullOrEmpty(value)) + { + if (attribute && valueType != null && !valueType.IsArray) + { + //if (valueType.Type == "") + //ScriptingObjectReference + apiType = FindApiTypeInfo(buildData, valueType, caller); + + // Object reference + if (apiType != null && apiType.IsScriptingObject) + return "null"; + } + return null; + } // Special case for Engine TEXT macro if (value.StartsWith("TEXT(\"") && value.EndsWith("\")")) @@ -150,7 +164,6 @@ namespace Flax.Build.Bindings value = value.Replace("::", "."); var dot = value.LastIndexOf('.'); - ApiTypeInfo apiType = null; if (dot != -1) { var type = new TypeInfo(value.Substring(0, dot)); diff --git a/Source/Tools/Flax.Build/Bindings/ClassInfo.cs b/Source/Tools/Flax.Build/Bindings/ClassInfo.cs index 021b47989..ace04a2e0 100644 --- a/Source/Tools/Flax.Build/Bindings/ClassInfo.cs +++ b/Source/Tools/Flax.Build/Bindings/ClassInfo.cs @@ -17,6 +17,8 @@ namespace Flax.Build.Bindings "ScriptingObject", "ManagedScriptingObject", "PersistentScriptingObject", + "ScriptingObjectReference", + "AssetReference", "BinaryAsset", "SceneObject", "Asset",