Revamped AzFramework::Scene (#332)
Updated AzFramework::Scene to allow it to serve as the one-stop location for localized singletons. Localized singletons in this case are instance that can only occur once in an environment but multiple times within an application. As an example, this allows settings up a single camera per viewport for instance. Highlights of changes: Replaced the original ebuses with interfaces and events for easy of use and performance. Removed the Entity Context specific code and moved that to new locations within the Entity Context itself. Allowed basic inheritance. If a subsystem isn't found in a scene the parent can optionally be searched. Scenes can enter a zombie state and avoid immediately being deleted. This is needed for situations where subsystems can't be destroyed until async calls have been completed.
This commit is contained in:
@@ -49,6 +49,8 @@ namespace AzToolsFramework
|
||||
/// Retrieve the Id of the editor entity context.
|
||||
virtual AzFramework::EntityContextId GetEditorEntityContextId() = 0;
|
||||
|
||||
virtual AzFramework::EntityContext* GetEditorEntityContextInstance() = 0;
|
||||
|
||||
/// Creates an entity in the editor context.
|
||||
/// \return the EntityId for the created Entity
|
||||
virtual AZ::EntityId CreateNewEditorEntity(const char* name) = 0;
|
||||
|
||||
@@ -77,6 +77,7 @@ namespace AzToolsFramework
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// EditorEntityContextRequestBus
|
||||
AzFramework::EntityContextId GetEditorEntityContextId() override { return GetContextId(); }
|
||||
AzFramework::EntityContext* GetEditorEntityContextInstance() override { return this; }
|
||||
void ResetEditorContext() override;
|
||||
|
||||
AZ::EntityId CreateNewEditorEntity(const char* name) override;
|
||||
|
||||
+33
-8
@@ -16,7 +16,7 @@
|
||||
#include <AzCore/Serialization/EditContext.h>
|
||||
|
||||
#include <AzFramework/Scene/Scene.h>
|
||||
#include <AzFramework/Scene/SceneSystemBus.h>
|
||||
#include <AzFramework/Scene/SceneSystemInterface.h>
|
||||
|
||||
#include <AzToolsFramework/Editor/EditorSettingsAPIBus.h>
|
||||
#include <AzToolsFramework/Entity/EditorEntityContextComponent.h>
|
||||
@@ -56,22 +56,47 @@ namespace AzToolsFramework
|
||||
|
||||
void AzToolsFrameworkConfigurationSystemComponent::Activate()
|
||||
{
|
||||
// Associate the EditorEntityContext with the default scene.
|
||||
// Create the editor specific child scene to the main scene and add the editor entity context to it.
|
||||
AzFramework::EntityContextId editorEntityContextId;
|
||||
EditorEntityContextRequestBus::BroadcastResult(editorEntityContextId, &EditorEntityContextRequests::GetEditorEntityContextId);
|
||||
|
||||
AzFramework::Scene* defaultScene = nullptr;
|
||||
AzFramework::SceneSystemRequestBus::BroadcastResult(defaultScene, &AzFramework::SceneSystemRequests::GetScene, "default");
|
||||
|
||||
if (!editorEntityContextId.IsNull() && defaultScene)
|
||||
if (!editorEntityContextId.IsNull())
|
||||
{
|
||||
bool success = false;
|
||||
AzFramework::SceneSystemRequestBus::BroadcastResult(success, &AzFramework::SceneSystemRequests::SetSceneForEntityContextId, editorEntityContextId, defaultScene);
|
||||
auto sceneSystem = AzFramework::SceneSystemInterface::Get();
|
||||
AZ_Assert(sceneSystem, "Scene system not available to create the editor scene.");
|
||||
AZStd::shared_ptr<AzFramework::Scene> mainScene = sceneSystem->GetScene(AzFramework::Scene::MainSceneName);
|
||||
if (mainScene)
|
||||
{
|
||||
AZ::Outcome<AZStd::shared_ptr<AzFramework::Scene>, AZStd::string> editorScene =
|
||||
sceneSystem->CreateSceneWithParent(AzFramework::Scene::EditorMainSceneName, mainScene);
|
||||
if (editorScene.IsSuccess())
|
||||
{
|
||||
AzFramework::EntityContext* editorEntityContext = nullptr;
|
||||
EditorEntityContextRequestBus::BroadcastResult(
|
||||
editorEntityContext, &EditorEntityContextRequests::GetEditorEntityContextInstance);
|
||||
if (editorEntityContext != nullptr)
|
||||
{
|
||||
[[maybe_unused]] bool contextAdded =
|
||||
editorScene.GetValue()->SetSubsystem<AzFramework::EntityContext::SceneStorageType&>(editorEntityContext);
|
||||
AZ_Assert(contextAdded, "Unable to add editor entity context to scene.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Assert(false, "Failed to create editor scene because: %s", editorScene.GetError().c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Assert(false, "No main scene to parent the editor scene under.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AzToolsFrameworkConfigurationSystemComponent::Deactivate()
|
||||
{
|
||||
[[maybe_unused]] bool success = AzFramework::SceneSystemInterface::Get()->RemoveScene(AzFramework::Scene::EditorMainSceneName);
|
||||
AZ_Assert(success, "Unable to remove the main editor scene.");
|
||||
}
|
||||
|
||||
void AzToolsFrameworkConfigurationSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
|
||||
|
||||
Reference in New Issue
Block a user