Add option to hide debug commands (eg. one auto-added within container class)

This commit is contained in:
2026-06-19 14:48:50 +02:00
parent d67c8fee99
commit 882a826360
4 changed files with 32 additions and 16 deletions
+19 -12
View File
@@ -265,8 +265,23 @@ namespace
if (auto* managedModule = dynamic_cast<ManagedBinaryModule*>(module))
{
const MClass* attribute = ((NativeBinaryModule*)GetBinaryModuleFlaxEngine())->Assembly->GetClass("FlaxEngine.DebugCommand");
const MMethod* getInfo = attribute->GetMethod("GetInfoInternal", 1);
ASSERT_LOW_LAYER(attribute);
const auto& classes = managedModule->Assembly->GetClasses();
#define FILTER(type) \
if (useClass && type->GetVisibility() != MVisibility::Public) \
continue; \
MObject* attr = type->GetAttribute(attribute); \
if (!useClass && !attr) \
continue; \
if (attr) \
{ \
bool hide = false; \
void* params[1] = { &hide }; \
getInfo->Invoke(attr, params, nullptr); \
if (hide) \
continue; \
}
for (const auto& e : classes)
{
MClass* mclass = e.Value;
@@ -292,10 +307,7 @@ namespace
name.StartsWith("add_") ||
name.StartsWith("remove_"))
continue;
if (!useClass && !method->HasAttribute(attribute))
continue;
if (useClass && method->GetVisibility() != MVisibility::Public)
continue;
FILTER(method);
auto& commandData = Commands.AddOne();
BuildName(commandData, mclass, method->GetName());
@@ -309,10 +321,7 @@ namespace
{
if (!field->IsStatic())
continue;
if (!useClass && !field->HasAttribute(attribute))
continue;
if (useClass && field->GetVisibility() != MVisibility::Public)
continue;
FILTER(field);
auto& commandData = Commands.AddOne();
BuildName(commandData, mclass, field->GetName());
@@ -326,10 +335,7 @@ namespace
{
if (!property->IsStatic())
continue;
if (!useClass && !property->HasAttribute(attribute))
continue;
if (useClass && property->GetVisibility() != MVisibility::Public)
continue;
FILTER(property);
auto& commandData = Commands.AddOne();
BuildName(commandData, mclass, property->GetName());
@@ -338,6 +344,7 @@ namespace
commandData.MethodSet = property->GetSetMethod();
}
}
#undef FILTER
}
else
#endif
+9
View File
@@ -22,6 +22,15 @@ namespace FlaxEngine
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Property)]
public sealed class DebugCommand : Attribute
{
/// <summary>
/// Hides the entry from the Debug Commands. Can be used to exclude specific members from class marked as debug commands contains as a whole.
/// </summary>
public bool Hide;
internal void GetInfoInternal(out bool hide)
{
hide = Hide;
}
}
partial class DebugCommands
+2 -2
View File
@@ -40,14 +40,14 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(Screen);
/// </summary>
/// <param name="screenPos">The screen-space position.</param>
/// <returns>The game viewport position.</returns>
API_FUNCTION() static Float2 ScreenToGameViewport(const Float2& screenPos);
API_FUNCTION(Attributes="DebugCommand(Hide=true)") static Float2 ScreenToGameViewport(const Float2& screenPos);
/// <summary>
/// Converts the game viewport position to the screen-space position.
/// </summary>
/// <param name="viewportPos">The game viewport position.</param>
/// <returns>The screen-space position.</returns>
API_FUNCTION() static Float2 GameViewportToScreen(const Float2& viewportPos);
API_FUNCTION(Attributes="DebugCommand(Hide=true)") static Float2 GameViewportToScreen(const Float2& viewportPos);
/// <summary>
/// Sets the window size (in screen-space, includes DPI scale).
+2 -2
View File
@@ -151,14 +151,14 @@ public:
/// </summary>
/// <param name="connection">Network connection identifier.</param>
/// <returns>Found client or null.</returns>
API_FUNCTION() static NetworkClient* GetClient(API_PARAM(Ref) const NetworkConnection& connection);
API_FUNCTION(Attributes="DebugCommand(Hide=true)") static NetworkClient* GetClient(API_PARAM(Ref) const NetworkConnection& connection);
/// <summary>
/// Gets the network client with a given identifier. Returns null if failed to find it.
/// </summary>
/// <param name="clientId">Network client identifier (synchronized on all peers).</param>
/// <returns>Found client or null.</returns>
API_FUNCTION() static NetworkClient* GetClient(uint32 clientId);
API_FUNCTION(Attributes="DebugCommand(Hide=true)") static NetworkClient* GetClient(uint32 clientId);
public:
/// <summary>