Converted to use AZ::Events for hiearchy notifications. Added unittests.
Signed-off-by: AMZN-Olex <5432499+AMZN-Olex@users.noreply.github.com>
This commit is contained in:
@@ -98,6 +98,16 @@ namespace Multiplayer
|
||||
return {};
|
||||
}
|
||||
|
||||
void NetworkHierarchyChildComponent::BindNetworkHierarchyChangedEventHandler(NetworkHierarchyChangedEvent::Handler& handler)
|
||||
{
|
||||
handler.Connect(m_networkHierarchyChangedEvent);
|
||||
}
|
||||
|
||||
void NetworkHierarchyChildComponent::BindNetworkHierarchyLeaveEventHandler(NetworkHierarchyLeaveEvent::Handler& handler)
|
||||
{
|
||||
handler.Connect(m_networkHierarchyLeaveEvent);
|
||||
}
|
||||
|
||||
void NetworkHierarchyChildComponent::SetTopLevelHierarchyRootComponent(NetworkHierarchyRootComponent* hierarchyRoot)
|
||||
{
|
||||
m_hierarchyRootComponent = hierarchyRoot;
|
||||
@@ -109,12 +119,13 @@ namespace Multiplayer
|
||||
const NetEntityId netRootId = GetNetworkEntityManager()->GetNetEntityIdById(hierarchyRoot->GetEntityId());
|
||||
controller->SetHierarchyRoot(netRootId);
|
||||
|
||||
NetworkHierarchyNotificationBus::Event(GetEntityId(), &NetworkHierarchyNotificationBus::Events::OnNetworkHierarchyUpdated, hierarchyRoot->GetEntityId());
|
||||
m_networkHierarchyChangedEvent.Signal(hierarchyRoot->GetEntityId());
|
||||
}
|
||||
else
|
||||
{
|
||||
controller->SetHierarchyRoot(InvalidNetEntityId);
|
||||
NetworkHierarchyNotificationBus::Event(GetEntityId(), &NetworkHierarchyNotificationBus::Events::OnNetworkHierarchyLeave);
|
||||
|
||||
m_networkHierarchyLeaveEvent.Signal();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -125,10 +136,12 @@ namespace Multiplayer
|
||||
if (rootHandle.Exists())
|
||||
{
|
||||
m_hierarchyRootComponent = rootHandle.FindComponent<NetworkHierarchyRootComponent>();
|
||||
m_networkHierarchyChangedEvent.Signal(m_hierarchyRootComponent->GetEntityId());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_hierarchyRootComponent = nullptr;
|
||||
m_networkHierarchyLeaveEvent.Signal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,6 +124,16 @@ namespace Multiplayer
|
||||
return GetEntity();
|
||||
}
|
||||
|
||||
void NetworkHierarchyRootComponent::BindNetworkHierarchyChangedEventHandler(NetworkHierarchyChangedEvent::Handler& handler)
|
||||
{
|
||||
handler.Connect(m_networkHierarchyChangedEvent);
|
||||
}
|
||||
|
||||
void NetworkHierarchyRootComponent::BindNetworkHierarchyLeaveEventHandler(NetworkHierarchyLeaveEvent::Handler& handler)
|
||||
{
|
||||
handler.Connect(m_networkHierarchyLeaveEvent);
|
||||
}
|
||||
|
||||
void NetworkHierarchyRootComponent::OnParentChanged([[maybe_unused]] AZ::EntityId oldParent, AZ::EntityId newParent)
|
||||
{
|
||||
const AZ::EntityId entityBusId = *AZ::TransformNotificationBus::GetCurrentBusId();
|
||||
@@ -168,6 +178,8 @@ namespace Multiplayer
|
||||
|
||||
uint32_t currentEntityCount = aznumeric_cast<uint32_t>(m_hierarchicalEntities.size());
|
||||
RecursiveAttachHierarchicalEntities(GetEntityId(), currentEntityCount);
|
||||
|
||||
m_networkHierarchyChangedEvent.Signal(GetEntityId());
|
||||
}
|
||||
|
||||
bool NetworkHierarchyRootComponent::RecursiveAttachHierarchicalEntities(AZ::EntityId underEntity, uint32_t& currentEntityCount)
|
||||
@@ -255,6 +267,8 @@ namespace Multiplayer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_networkHierarchyChangedEvent.Signal(GetEntityId());
|
||||
}
|
||||
|
||||
void NetworkHierarchyRootComponent::SetTopLevelHierarchyRootEntity(AZ::Entity* hierarchyRoot)
|
||||
|
||||
@@ -97,15 +97,28 @@ namespace Multiplayer
|
||||
|
||||
void NetworkTransformComponent::OnParentIdChangedEvent([[maybe_unused]] NetEntityId newParent)
|
||||
{
|
||||
const ConstNetworkEntityHandle rootHandle = GetNetworkEntityManager()->GetEntity(newParent);
|
||||
if (rootHandle.Exists())
|
||||
if (newParent == InvalidNetEntityId)
|
||||
{
|
||||
const AZ::EntityId parentEntityId = rootHandle.GetEntity()->GetId();
|
||||
if (AzFramework::TransformComponent* transformComponent = GetEntity()->FindComponent<AzFramework::TransformComponent>())
|
||||
{
|
||||
if (transformComponent->GetParentId() != parentEntityId)
|
||||
if (transformComponent->GetParentId() != AZ::EntityId())
|
||||
{
|
||||
transformComponent->SetParent(parentEntityId);
|
||||
transformComponent->SetParent(AZ::EntityId());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const ConstNetworkEntityHandle rootHandle = GetNetworkEntityManager()->GetEntity(newParent);
|
||||
if (rootHandle.Exists())
|
||||
{
|
||||
const AZ::EntityId parentEntityId = rootHandle.GetEntity()->GetId();
|
||||
if (AzFramework::TransformComponent* transformComponent = GetEntity()->FindComponent<AzFramework::TransformComponent>())
|
||||
{
|
||||
if (transformComponent->GetParentId() != parentEntityId)
|
||||
{
|
||||
transformComponent->SetParent(parentEntityId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user