Improvements to Entity Outliner context menu
Signed-off-by: Mikhail Naumov <mnaumov@amazon.com>
This commit is contained in:
@@ -646,16 +646,27 @@ void SandboxIntegrationManager::PopulateEditorGlobalContextMenu(QMenu* menu, con
|
||||
|
||||
QAction* action = nullptr;
|
||||
|
||||
action = menu->addAction(QObject::tr("Create entity"));
|
||||
QObject::connect(action, &QAction::triggered, action, [this] { ContextMenu_NewEntity(); });
|
||||
|
||||
if (selected.size() == 1)
|
||||
// when nothing is selected, entity is created at root level
|
||||
if (selected.size() == 0)
|
||||
{
|
||||
action = menu->addAction(QObject::tr("Create child entity"));
|
||||
QObject::connect(action, &QAction::triggered, action, [selected]
|
||||
{
|
||||
EBUS_EVENT(AzToolsFramework::EditorRequests::Bus, CreateNewEntityAsChild, selected.front());
|
||||
});
|
||||
action = menu->addAction(QObject::tr("Create entity"));
|
||||
QObject::connect(
|
||||
action, &QAction::triggered, action,
|
||||
[this]
|
||||
{
|
||||
ContextMenu_NewEntity();
|
||||
});
|
||||
}
|
||||
// when a single entity is selected, entity is created as its child
|
||||
else if (selected.size() == 1)
|
||||
{
|
||||
action = menu->addAction(QObject::tr("Create entity"));
|
||||
QObject::connect(
|
||||
action, &QAction::triggered, action,
|
||||
[selected]
|
||||
{
|
||||
EBUS_EVENT(AzToolsFramework::EditorRequests::Bus, CreateNewEntityAsChild, selected.front());
|
||||
});
|
||||
}
|
||||
|
||||
bool prefabSystemEnabled = false;
|
||||
|
||||
+18
-4
@@ -11,6 +11,7 @@
|
||||
#include <AzCore/IO/FileIO.h>
|
||||
#include <AzCore/IO/SystemFile.h>
|
||||
#include <AzCore/StringFunc/StringFunc.h>
|
||||
#include <AzCore/Component/TransformBus.h>
|
||||
|
||||
#include <AzFramework/API/ApplicationAPI.h>
|
||||
#include <AzFramework/Asset/AssetSystemBus.h>
|
||||
@@ -363,12 +364,25 @@ namespace AzToolsFramework
|
||||
|
||||
if (hasUserSelectedValidSourceFile)
|
||||
{
|
||||
// Get position (center of viewport). If no viewport is available, (0,0,0) will be used.
|
||||
AZ::Vector3 viewportCenterPosition = AZ::Vector3::CreateZero();
|
||||
EditorRequestBus::BroadcastResult(viewportCenterPosition, &EditorRequestBus::Events::GetWorldPositionAtViewportCenter);
|
||||
AZ::EntityId parentId;
|
||||
AZ::Vector3 position = AZ::Vector3::CreateZero();
|
||||
|
||||
// if one entity is selected, set it as parent
|
||||
EntityIdList selectedEntities;
|
||||
ToolsApplicationRequestBus::BroadcastResult(selectedEntities, &ToolsApplicationRequests::GetSelectedEntities);
|
||||
if (selectedEntities.size() == 1)
|
||||
{
|
||||
parentId = selectedEntities.front();
|
||||
AZ::TransformBus::EventResult(position, parentId, &AZ::TransformInterface::GetWorldTranslation);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get position (center of viewport). If no viewport is available, (0,0,0) will be used.
|
||||
EditorRequestBus::BroadcastResult(position, &EditorRequestBus::Events::GetWorldPositionAtViewportCenter);
|
||||
}
|
||||
|
||||
// Instantiating from context menu always puts the instance at the root level
|
||||
auto createPrefabOutcome = s_prefabPublicInterface->InstantiatePrefab(prefabFilePath, AZ::EntityId(), viewportCenterPosition);
|
||||
auto createPrefabOutcome = s_prefabPublicInterface->InstantiatePrefab(prefabFilePath, parentId, position);
|
||||
|
||||
if (!createPrefabOutcome.IsSuccess())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user