Add NavAgentMask

This commit is contained in:
Wojtek Figat
2021-01-15 11:59:04 +01:00
parent d7949b5405
commit 2c2c1af97f
5 changed files with 165 additions and 0 deletions

View File

@@ -97,6 +97,42 @@ bool NavAgentProperties::operator==(const NavAgentProperties& other) const
return Math::NearEqual(Radius, other.Radius) && Math::NearEqual(Height, other.Height) && Math::NearEqual(StepHeight, other.StepHeight) && Math::NearEqual(MaxSlopeAngle, other.MaxSlopeAngle);
}
bool NavAgentMask::IsAgentSupported(int32 agentIndex) const
{
return (Mask & (1 << agentIndex)) != 0;
}
bool NavAgentMask::IsAgentSupported(const NavAgentProperties& agentProperties) const
{
auto settings = NavigationSettings::Get();
for (int32 agentIndex = 0; agentIndex < settings->NavMeshes.Count(); agentIndex++)
{
if (settings->NavMeshes[agentIndex].Agent == agentProperties)
{
return (Mask & (1 << agentIndex)) != 0;
}
}
return false;
}
bool NavAgentMask::IsNavMeshSupported(const NavMeshProperties& navMeshProperties) const
{
auto settings = NavigationSettings::Get();
for (int32 agentIndex = 0; agentIndex < settings->NavMeshes.Count(); agentIndex++)
{
if (settings->NavMeshes[agentIndex] == navMeshProperties)
{
return (Mask & (1 << agentIndex)) != 0;
}
}
return false;
}
bool NavAgentMask::operator==(const NavAgentMask& other) const
{
return Mask == other.Mask;
}
bool NavMeshProperties::operator==(const NavMeshProperties& other) const
{
return Name == other.Name && Quaternion::NearEqual(Rotation, other.Rotation, 0.001f) && Agent == other.Agent;

View File

@@ -72,3 +72,15 @@ namespace FlaxEditor.Content.Settings
}
}
}
namespace FlaxEngine
{
partial struct NavAgentProperties
{
/// <inheritdoc />
public override string ToString()
{
return $"Radius: {Radius}, Height: {Height}, StepHeight: {StepHeight}, MaxSlopeAngle: {MaxSlopeAngle}";
}
}
}

View File

@@ -91,6 +91,30 @@ DECLARE_SCRIPTING_TYPE_MINIMAL(NavMeshProperties);
}
};
/// <summary>
/// The navigation system agents selection mask (from navigation system settings). Uses 1 bit per agent type (up to 32 agents).
/// </summary>
API_STRUCT() struct FLAXENGINE_API NavAgentMask
{
DECLARE_SCRIPTING_TYPE_MINIMAL(NavAgentMask);
/// <summary>
/// The agents selection mask.
/// </summary>
API_FIELD() uint32 Mask = MAX_uint32;
bool IsAgentSupported(int32 agentIndex) const;
bool IsAgentSupported(const NavAgentProperties& agentProperties) const;
bool IsNavMeshSupported(const NavMeshProperties& navMeshProperties) const;
bool operator==(const NavAgentMask& other) const;
bool operator!=(const NavAgentMask& other) const
{
return !operator==(other);
}
};
/// <summary>
/// The result information for navigation mesh queries.
/// </summary>