Merge pull request #7013 from aws-lumberyard-dev/mnaumov/FixingEOOrdering_signofffix
Fixing entity outliner order when creating prefab
This commit is contained in:
@@ -201,11 +201,8 @@ namespace AzToolsFramework
|
||||
//! Fired after the EditorEntityContext fails to export the root level slice to the game stream
|
||||
virtual void OnSaveStreamForGameFailure(AZStd::string_view /*failureString*/) {}
|
||||
|
||||
//! Fired when the user triggers a clone of ComponentEntity object(s), before operation begins
|
||||
virtual void OnEntitiesAboutToBeCloned() {}
|
||||
|
||||
//! Fires when the user triggers a clone of ComponentEntity object(s)), after operation completes
|
||||
virtual void OnEntitiesCloned() {}
|
||||
//! Preserve entity order when re-parenting entities
|
||||
virtual void SetForceAddEntitiesToBackFlag(bool /*forceAddToBack*/) {}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -1157,7 +1157,7 @@ namespace AzToolsFramework
|
||||
|
||||
bool CloneInstantiatedEntities(const EntityIdSet& entitiesToClone, EntityIdSet& clonedEntities)
|
||||
{
|
||||
EditorEntityContextNotificationBus::Broadcast(&EditorEntityContextNotification::OnEntitiesAboutToBeCloned);
|
||||
EditorEntityContextNotificationBus::Broadcast(&EditorEntityContextNotification::SetForceAddEntitiesToBackFlag, true);
|
||||
ScopedUndoBatch undoBatch("Clone Selection");
|
||||
|
||||
// Track the mapping of source to cloned entity. This both helps make sure that an entity is not accidentally
|
||||
@@ -1199,7 +1199,7 @@ namespace AzToolsFramework
|
||||
// Also replace the selection with the entities that have been cloned.
|
||||
Internal::UpdateUndoStackAndSelectClonedEntities(allEntityClonesContainer.m_entities, undoBatch);
|
||||
|
||||
EditorEntityContextNotificationBus::Broadcast(&EditorEntityContextNotification::OnEntitiesCloned);
|
||||
EditorEntityContextNotificationBus::Broadcast(&EditorEntityContextNotification::SetForceAddEntitiesToBackFlag, false);
|
||||
|
||||
for (const AZ::Entity* entity : allEntityClonesContainer.m_entities)
|
||||
{
|
||||
|
||||
@@ -643,14 +643,9 @@ namespace AzToolsFramework
|
||||
}
|
||||
}
|
||||
|
||||
void EditorEntityModel::OnEntitiesAboutToBeCloned()
|
||||
void EditorEntityModel::SetForceAddEntitiesToBackFlag(bool forceAddToBack)
|
||||
{
|
||||
m_forceAddToBack = true;
|
||||
}
|
||||
|
||||
void EditorEntityModel::OnEntitiesCloned()
|
||||
{
|
||||
m_forceAddToBack = false;
|
||||
m_forceAddToBack = forceAddToBack;
|
||||
}
|
||||
|
||||
void EditorEntityModel::ChildEntityOrderArrayUpdated()
|
||||
|
||||
@@ -94,9 +94,7 @@ namespace AzToolsFramework
|
||||
void OnEntityStreamLoadBegin() override;
|
||||
void OnEntityStreamLoadSuccess() override;
|
||||
void OnEntityStreamLoadFailed() override;
|
||||
void OnEntitiesAboutToBeCloned() override;
|
||||
void OnEntitiesCloned() override;
|
||||
|
||||
void SetForceAddEntitiesToBackFlag(bool forceAddToBack) override;
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// AzFramework::EntityContextEventBus::Handler
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <AzCore/JSON/writer.h>
|
||||
#include <AzCore/Serialization/Json/JsonSerialization.h>
|
||||
#include <AzCore/Utils/TypeHash.h>
|
||||
#include <AzCore/std/sort.h>
|
||||
|
||||
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
|
||||
#include <AzToolsFramework/ContainerEntity/ContainerEntityInterface.h>
|
||||
@@ -83,6 +84,20 @@ namespace AzToolsFramework
|
||||
return AZ::Failure(findCommonRootOutcome.TakeError());
|
||||
}
|
||||
|
||||
// order entities by their respective position within Entity Outliner
|
||||
EditorEntitySortRequestBus::Event(
|
||||
commonRootEntityId,
|
||||
[&topLevelEntities](EditorEntitySortRequestBus::Events* sortRequests)
|
||||
{
|
||||
AZStd::sort(
|
||||
topLevelEntities.begin(), topLevelEntities.end(),
|
||||
[&sortRequests](AZ::Entity* entity1, AZ::Entity* entity2)
|
||||
{
|
||||
return sortRequests->GetChildEntityIndex(entity1->GetId()) <
|
||||
sortRequests->GetChildEntityIndex(entity2->GetId());
|
||||
});
|
||||
});
|
||||
|
||||
AZ::EntityId containerEntityId;
|
||||
|
||||
InstanceOptionalReference instanceToCreate;
|
||||
@@ -153,8 +168,6 @@ namespace AzToolsFramework
|
||||
}
|
||||
|
||||
// Create the Prefab
|
||||
AZ_Assert(filePath.IsAbsolute(), "CreatePrefabInMemory requires an absolute file path.");
|
||||
|
||||
instanceToCreate = prefabEditorEntityOwnershipInterface->CreatePrefab(
|
||||
entities, AZStd::move(instancePtrs), m_prefabLoaderInterface->GenerateRelativePath(filePath),
|
||||
commonRootEntityOwningInstance);
|
||||
@@ -172,6 +185,7 @@ namespace AzToolsFramework
|
||||
|
||||
// Parent the non-container top level entities to the container entity.
|
||||
// Parenting the top level container entities will be done during the creation of links.
|
||||
EditorEntityContextNotificationBus::Broadcast(&EditorEntityContextNotification::SetForceAddEntitiesToBackFlag, true);
|
||||
for (AZ::Entity* topLevelEntity : topLevelEntities)
|
||||
{
|
||||
if (!IsInstanceContainerEntity(topLevelEntity->GetId()))
|
||||
@@ -179,6 +193,7 @@ namespace AzToolsFramework
|
||||
AZ::TransformBus::Event(topLevelEntity->GetId(), &AZ::TransformBus::Events::SetParent, containerEntityId);
|
||||
}
|
||||
}
|
||||
EditorEntityContextNotificationBus::Broadcast(&EditorEntityContextNotification::SetForceAddEntitiesToBackFlag, false);
|
||||
|
||||
// Update the template of the instance since the entities are modified since the template creation.
|
||||
Prefab::PrefabDom serializedInstance;
|
||||
@@ -279,6 +294,8 @@ namespace AzToolsFramework
|
||||
|
||||
CreatePrefabResult PrefabPublicHandler::CreatePrefabInDisk(const EntityIdList& entityIds, AZ::IO::PathView filePath)
|
||||
{
|
||||
AZ_Assert(filePath.IsAbsolute(), "CreatePrefabInDisk requires an absolute file path.");
|
||||
|
||||
auto result = CreatePrefabInMemory(entityIds, filePath);
|
||||
if (result.IsSuccess())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user