diff --git a/Source/Engine/Content/JsonAsset.cpp b/Source/Engine/Content/JsonAsset.cpp index 4e1f90d70..3779181b7 100644 --- a/Source/Engine/Content/JsonAsset.cpp +++ b/Source/Engine/Content/JsonAsset.cpp @@ -190,13 +190,11 @@ ISerializable* Create() return New(); } +// Key: managed class typename, Value: unmanaged instance spawner function Dictionary UnmanagedTypes(32); void InitUnmanagedJsonTypes() { - ASSERT(UnmanagedTypes.IsEmpty()); - - // Key: managed class typename, Value: unmanaged instance spawner function UnmanagedTypes[TEXT("FlaxEngine.PhysicalMaterial")] = &Create; } diff --git a/Source/Engine/Engine/PhysicalMaterial.cs b/Source/Engine/Engine/PhysicalMaterial.cs deleted file mode 100644 index 1ad1c732c..000000000 --- a/Source/Engine/Engine/PhysicalMaterial.cs +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) 2012-2020 Wojciech Figat. All rights reserved. - -namespace FlaxEngine -{ - /// - /// Physical materials are used to define the response of a physical object when interacting dynamically with the world. - /// - public sealed class PhysicalMaterial - { - /// - /// The friction value of surface, controls how easily things can slide on this surface. - /// - [EditorOrder(0), Limit(0), EditorDisplay("Physical Material"), Tooltip("The friction value of surface, controls how easily things can slide on this surface.")] - public float Friction = 0.7f; - - /// - /// The friction combine mode, controls how friction is computed for multiple materials. - /// - [EditorOrder(1), EditorDisplay("Physical Material"), Tooltip("The friction combine mode, controls how friction is computed for multiple materials.")] - public PhysicsCombineMode FrictionCombineMode = PhysicsCombineMode.Average; - - /// - /// If set we will use the FrictionCombineMode of this material, instead of the FrictionCombineMode found in the Physics settings. - /// - [HideInEditor] - public bool OverrideFrictionCombineMode = false; - - /// - /// The restitution or 'bounciness' of this surface, between 0 (no bounce) and 1 (outgoing velocity is same as incoming). - /// - [EditorOrder(3), Range(0, 1), EditorDisplay("Physical Material"), Tooltip("The restitution or \'bounciness\' of this surface, between 0 (no bounce) and 1 (outgoing velocity is same as incoming).")] - public float Restitution = 0.3f; - - /// - /// The restitution combine mode, controls how restitution is computed for multiple materials. - /// - [EditorOrder(4), EditorDisplay("Physical Material"), Tooltip("The restitution combine mode, controls how restitution is computed for multiple materials.")] - public PhysicsCombineMode RestitutionCombineMode = PhysicsCombineMode.Average; - - /// - /// If set we will use the RestitutionCombineMode of this material, instead of the RestitutionCombineMode found in the Physics settings. - /// - [HideInEditor] - public bool OverrideRestitutionCombineMode = false; - } -} diff --git a/Source/Engine/Physics/PhysicalMaterial.cpp b/Source/Engine/Physics/PhysicalMaterial.cpp index 61ba840be..115e85a15 100644 --- a/Source/Engine/Physics/PhysicalMaterial.cpp +++ b/Source/Engine/Physics/PhysicalMaterial.cpp @@ -2,7 +2,6 @@ #include "PhysicalMaterial.h" #include "PhysicsSettings.h" -#include "Engine/Serialization/JsonTools.h" #include "Physics.h" #include #include @@ -51,18 +50,3 @@ void PhysicalMaterial::UpdatePhysXMaterial() _material->setRestitutionCombineMode(static_cast(useRestitutionCombineMode)); } } - -void PhysicalMaterial::Serialize(SerializeStream& stream, const void* otherObj) -{ - MISSING_CODE("PhysicalMaterial::Serialize is not implemented"); -} - -void PhysicalMaterial::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) -{ - Friction = JsonTools::GetFloat(stream, "Friction", PhysicalMaterial_Friction); - FrictionCombineMode = JsonTools::GetEnum(stream, "FrictionCombineMode", PhysicalMaterial_FrictionCombineMode); - OverrideFrictionCombineMode = JsonTools::GetBool(stream, "OverrideFrictionCombineMode", PhysicalMaterial_OverrideFrictionCombineMode); - Restitution = JsonTools::GetFloat(stream, "Restitution", PhysicalMaterial_Restitution); - RestitutionCombineMode = JsonTools::GetEnum(stream, "RestitutionCombineMode", PhysicalMaterial_RestitutionCombineMode); - OverrideRestitutionCombineMode = JsonTools::GetBool(stream, "OverrideRestitutionCombineMode", PhysicalMaterial_OverrideRestitutionCombineMode); -} diff --git a/Source/Engine/Physics/PhysicalMaterial.h b/Source/Engine/Physics/PhysicalMaterial.h index b2dc3f8e6..8bc0eebf7 100644 --- a/Source/Engine/Physics/PhysicalMaterial.h +++ b/Source/Engine/Physics/PhysicalMaterial.h @@ -5,20 +5,13 @@ #include "Types.h" #include "Engine/Serialization/ISerializable.h" -// Default values for the physical material - -#define PhysicalMaterial_Friction 0.7f -#define PhysicalMaterial_FrictionCombineMode PhysicsCombineMode::Average -#define PhysicalMaterial_OverrideFrictionCombineMode false -#define PhysicalMaterial_Restitution 0.3f -#define PhysicalMaterial_RestitutionCombineMode PhysicsCombineMode::Average -#define PhysicalMaterial_OverrideRestitutionCombineMode false - /// /// Physical materials are used to define the response of a physical object when interacting dynamically with the world. /// -class FLAXENGINE_API PhysicalMaterial : public ISerializable +API_CLASS() class FLAXENGINE_API PhysicalMaterial final : public ISerializable { +API_AUTO_SERIALIZATION(); +DECLARE_SCRIPTING_TYPE_MINIMAL(PhysicalMaterial); private: PxMaterial* _material; @@ -40,32 +33,38 @@ public: /// /// The friction value of surface, controls how easily things can slide on this surface. /// - float Friction = PhysicalMaterial_Friction; + API_FIELD(Attributes="EditorOrder(0), Limit(0), EditorDisplay(\"Physical Material\")") + float Friction = 0.7f; /// /// The friction combine mode, controls how friction is computed for multiple materials. /// - PhysicsCombineMode FrictionCombineMode = PhysicalMaterial_FrictionCombineMode; + API_FIELD(Attributes="EditorOrder(1), EditorDisplay(\"Physical Material\")") + PhysicsCombineMode FrictionCombineMode = PhysicsCombineMode::Average; /// /// If set we will use the FrictionCombineMode of this material, instead of the FrictionCombineMode found in the Physics settings. /// - bool OverrideFrictionCombineMode = PhysicalMaterial_OverrideFrictionCombineMode; + API_FIELD(Attributes="HideInEditor") + bool OverrideFrictionCombineMode = false; /// /// The restitution or 'bounciness' of this surface, between 0 (no bounce) and 1 (outgoing velocity is same as incoming). /// - float Restitution = PhysicalMaterial_Restitution; + API_FIELD(Attributes="EditorOrder(3), Range(0, 1), EditorDisplay(\"Physical Material\")") + float Restitution = 0.3f; /// /// The restitution combine mode, controls how restitution is computed for multiple materials. /// - PhysicsCombineMode RestitutionCombineMode = PhysicalMaterial_RestitutionCombineMode; + API_FIELD(Attributes="EditorOrder(4), EditorDisplay(\"Physical Material\")") + PhysicsCombineMode RestitutionCombineMode = PhysicsCombineMode::Average; /// /// If set we will use the RestitutionCombineMode of this material, instead of the RestitutionCombineMode found in the Physics settings. /// - bool OverrideRestitutionCombineMode = PhysicalMaterial_OverrideRestitutionCombineMode; + API_FIELD(Attributes="HideInEditor") + bool OverrideRestitutionCombineMode = false; public: @@ -79,10 +78,4 @@ public: /// Updates the PhysX material (after any property change). /// void UpdatePhysXMaterial(); - -public: - - // [ISerializable] - void Serialize(SerializeStream& stream, const void* otherObj) override; - void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override; }; diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs index b53c147c2..966737e95 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs @@ -393,7 +393,7 @@ namespace Flax.Build.Bindings { // Write attributes contents.Append(indent).Append('[').Append(attributes).Append(']').AppendLine(); - writeTooltip = !attributes.Contains("Tooltip("); + writeTooltip = !attributes.Contains("Tooltip(") && !attributes.Contains("HideInEditor"); } if (useUnmanaged) @@ -462,7 +462,7 @@ namespace Flax.Build.Bindings else if (classInfo.IsAbstract) contents.Append("abstract "); contents.Append("unsafe partial class ").Append(classInfo.Name); - if (classInfo.BaseType != null && classInfo.BaseTypeInheritance != AccessLevel.Private) + if (classInfo.BaseType != null && !classInfo.IsBaseTypeHidden) contents.Append(" : ").Append(GenerateCSharpNativeToManaged(buildData, classInfo.BaseType, classInfo)); contents.AppendLine(); contents.Append(indent + "{"); diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs index f9a695b77..e64240b9e 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs @@ -949,6 +949,8 @@ namespace Flax.Build.Bindings var baseType = classInfo?.BaseType ?? structureInfo?.BaseType; if (baseType != null && baseType.Type == "ISerializable") baseType = null; + else if (classInfo != null && classInfo.IsBaseTypeHidden) + baseType = null; CppAutoSerializeFields.Clear(); CppAutoSerializeProperties.Clear(); CppIncludeFiles.Add("Engine/Serialization/Serialization.h"); diff --git a/Source/Tools/Flax.Build/Bindings/ClassInfo.cs b/Source/Tools/Flax.Build/Bindings/ClassInfo.cs index 1a62132b2..3ac5b37fc 100644 --- a/Source/Tools/Flax.Build/Bindings/ClassInfo.cs +++ b/Source/Tools/Flax.Build/Bindings/ClassInfo.cs @@ -25,6 +25,7 @@ namespace Flax.Build.Bindings public AccessLevel Access; public TypeInfo BaseType; public AccessLevel BaseTypeInheritance; + public bool IsBaseTypeHidden; public bool IsStatic; public bool IsSealed; public bool IsAbstract; @@ -50,6 +51,9 @@ namespace Flax.Build.Bindings { base.Init(buildData); + // Internal base types are usually hidden from bindings (used in core-only internally) + IsBaseTypeHidden = BaseTypeInheritance == AccessLevel.Private || BaseType.Type == "ISerializable"; + // Cache if it it Scripting Object type if (InBuildScriptingObjectTypes.Contains(Name)) _isScriptingObject = true;