Add Default auto-generated member to scripting structures and improve deserialization

This commit is contained in:
Wojtek Figat
2022-08-01 18:49:54 +02:00
parent 4915e9fea0
commit fe1cab6a7f
11 changed files with 57 additions and 65 deletions

View File

@@ -6,11 +6,6 @@ namespace FlaxEngine
{
partial struct D6JointDrive
{
/// <summary>
/// The default <see cref="D6JointDrive"/> structure.
/// </summary>
public static readonly D6JointDrive Default = new D6JointDrive(0.0f, 0.0f, float.MaxValue, false);
/// <summary>
/// Initializes a new instance of the <see cref="D6JointDrive"/> struct.
/// </summary>

View File

@@ -4,11 +4,6 @@ namespace FlaxEngine
{
partial struct HingeJointDrive
{
/// <summary>
/// The default <see cref="HingeJointDrive"/> structure.
/// </summary>
public static readonly HingeJointDrive Default = new HingeJointDrive(0.0f, float.MaxValue, 1.0f, false);
/// <summary>
/// Initializes a new instance of the <see cref="HingeJointDrive"/> struct.
/// </summary>

View File

@@ -4,11 +4,6 @@ namespace FlaxEngine
{
partial struct SpringParameters
{
/// <summary>
/// The default <see cref="SpringParameters"/> structure.
/// </summary>
public static readonly SpringParameters Default = new SpringParameters(0.0f, 0.0f);
/// <summary>
/// Constructs a spring.
/// </summary>
@@ -23,11 +18,6 @@ namespace FlaxEngine
partial struct LimitLinearRange
{
/// <summary>
/// The default <see cref="LimitLinearRange"/> structure with empty limit.
/// </summary>
public static readonly LimitLinearRange Default = new LimitLinearRange(0.0f, 0.0f);
/// <summary>
/// Constructs a hard limit. Once the limit is reached the movement of the attached bodies will come to a stop.
/// </summary>
@@ -62,11 +52,6 @@ namespace FlaxEngine
partial struct LimitLinear
{
/// <summary>
/// The default <see cref="LimitLinear"/> structure with empty limit.
/// </summary>
public static readonly LimitLinear Default = new LimitLinear(0.0f);
/// <summary>
/// Constructs a hard limit. Once the limit is reached the movement of the attached bodies will come to a stop.
/// </summary>
@@ -97,11 +82,6 @@ namespace FlaxEngine
partial struct LimitAngularRange
{
/// <summary>
/// The default <see cref="LimitAngularRange"/> structure with empty limit.
/// </summary>
public static readonly LimitAngularRange Default = new LimitAngularRange(0.0f, 0.0f);
/// <summary>
/// Constructs a hard limit. Once the limit is reached the movement of the attached bodies will come to a stop.
/// </summary>
@@ -136,11 +116,6 @@ namespace FlaxEngine
partial struct LimitConeRange
{
/// <summary>
/// The default <see cref="LimitConeRange"/> structure with a 45 degree cone limit.
/// </summary>
public static readonly LimitConeRange Default = new LimitConeRange(90.0f, 90.0f);
/// <summary>
/// Constructs a hard limit. Once the limit is reached the movement of the attached bodies will come to a stop.
/// </summary>

View File

@@ -29,7 +29,7 @@ API_ENUM() enum class WindowStartPosition
/// <summary>
/// Settings for new window.
/// </summary>
API_STRUCT() struct CreateWindowSettings
API_STRUCT(NoDefault) struct CreateWindowSettings
{
DECLARE_SCRIPTING_TYPE_MINIMAL(CreateWindowSettings);

View File

@@ -16,33 +16,8 @@ namespace FlaxEditor.Content.Settings
/// </summary>
public GraphicsSettings()
{
// Initialize PostFx settings with default options (C# structs doesn't support it)
// Initialize PostFx settings with default options (C# structs don't support it)
PostProcessSettings = FlaxEngine.PostProcessSettings.Default;
}
}
}
namespace FlaxEngine
{
partial struct PostProcessSettings
{
private static PostProcessSettings _default;
/// <summary>
/// The default <see cref="PostProcessSettings"/>.
/// </summary>
public static PostProcessSettings Default
{
get
{
if (!_default.AmbientOcclusion.Enabled)
{
object obj = _default;
Utils.InitStructure(obj, typeof(PostProcessSettings));
_default = (PostProcessSettings)obj;
}
return _default;
}
}
}
}

View File

@@ -49,7 +49,7 @@ API_ENUM() enum class TextWrapping
/// <summary>
/// Structure which describes text layout properties.
/// </summary>
API_STRUCT() struct TextLayoutOptions
API_STRUCT(NoDefault) struct TextLayoutOptions
{
DECLARE_SCRIPTING_TYPE_MINIMAL(TextLayoutOptions);

View File

@@ -928,7 +928,12 @@ namespace FlaxEngine
stream.Write(0);
}
internal static void InitStructure(object obj, Type type)
/// <summary>
/// Initializes the structure (value type) by inflating it with values from <see cref="System.ComponentModel.DefaultValueAttribute"/> (recursive).
/// </summary>
/// <param name="obj">The object to initialize.</param>
/// <param name="type">The structure type.</param>
public static void InitStructure(object obj, Type type)
{
var fields = type.GetFields(BindingFlags.Default | BindingFlags.Instance | BindingFlags.Public);
for (var i = 0; i < fields.Length; i++)