diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs index a437a4158..a972f1b78 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs @@ -2042,13 +2042,18 @@ namespace Flax.Build.Bindings GenerateCSharpAttributes(buildData, contents, indent, enumInfo, true); contents.Append(indent).Append(GenerateCSharpAccessLevel(enumInfo.Access)); contents.Append("enum ").Append(enumInfo.Name); + string managedType = string.Empty; if (enumInfo.UnderlyingType != null) - contents.Append(" : ").Append(GenerateCSharpNativeToManaged(buildData, enumInfo.UnderlyingType, enumInfo)); + { + managedType = GenerateCSharpNativeToManaged(buildData, enumInfo.UnderlyingType, enumInfo); + contents.Append(" : ").Append(managedType); + } contents.AppendLine(); contents.Append(indent + "{"); indent += " "; // Entries + bool usedMax = false; foreach (var entryInfo in enumInfo.Entries) { contents.AppendLine(); @@ -2056,7 +2061,29 @@ namespace Flax.Build.Bindings GenerateCSharpAttributes(buildData, contents, indent, enumInfo, entryInfo.Attributes, entryInfo.Comment, true, false); contents.Append(indent).Append(entryInfo.Name); if (!string.IsNullOrEmpty(entryInfo.Value)) - contents.Append(" = ").Append(entryInfo.Value); + { + if (usedMax) + usedMax = false; + + string value; + if (enumInfo.UnderlyingType != null) + { + value = GenerateCSharpDefaultValueNativeToManaged(buildData, entryInfo.Value, enumInfo, enumInfo.UnderlyingType, false, managedType); + if (value.Contains($"{managedType}.MaxValue", StringComparison.Ordinal)) + usedMax = true; + } + else + { + value = entryInfo.Value; + } + contents.Append(" = ").Append(value); + } + // Handle case of next value after Max value being zero if a value is not defined. + else if (string.IsNullOrEmpty(entryInfo.Value) && usedMax) + { + contents.Append(" = ").Append('0'); + usedMax = false; + } contents.Append(','); contents.AppendLine(); }