Merged MultiplayerPipeline from CodeCommit
parent
59252235d5
commit
a5fdbddeda
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||||
|
* its licensors.
|
||||||
|
*
|
||||||
|
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||||
|
* distribution (the "License"). All use of this software is governed by the License,
|
||||||
|
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||||
|
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Source/Multiplayer_precompiled.h>
|
||||||
|
#include <Source/MultiplayerToolsModule.h>
|
||||||
|
#include "Pipeline/NetworkPrefabProcessor.h"
|
||||||
|
#include "AzCore/Serialization/Json/RegistrationContext.h"
|
||||||
|
#include "Prefab/Instance/InstanceSerializer.h"
|
||||||
|
|
||||||
|
namespace Multiplayer
|
||||||
|
{
|
||||||
|
//! Multiplayer system component wraps the bridging logic between the game and transport layer.
|
||||||
|
class MultiplayerToolsSystemComponent final
|
||||||
|
: public AZ::Component
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AZ_COMPONENT(MultiplayerToolsSystemComponent, "{65AF5342-0ECE-423B-B646-AF55A122F72B}");
|
||||||
|
|
||||||
|
static void Reflect(AZ::ReflectContext* context)
|
||||||
|
{
|
||||||
|
NetworkPrefabProcessor::Reflect(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
MultiplayerToolsSystemComponent() = default;
|
||||||
|
~MultiplayerToolsSystemComponent() override = default;
|
||||||
|
|
||||||
|
/// AZ::Component overrides.
|
||||||
|
void Activate() override
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Deactivate() override
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
MultiplayerToolsModule::MultiplayerToolsModule()
|
||||||
|
: AZ::Module()
|
||||||
|
{
|
||||||
|
m_descriptors.insert(m_descriptors.end(), {
|
||||||
|
MultiplayerToolsSystemComponent::CreateDescriptor(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
AZ::ComponentTypeList MultiplayerToolsModule::GetRequiredSystemComponents() const
|
||||||
|
{
|
||||||
|
return AZ::ComponentTypeList
|
||||||
|
{
|
||||||
|
azrtti_typeid<MultiplayerToolsSystemComponent>(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} // namespace Multiplayer
|
||||||
|
|
||||||
|
AZ_DECLARE_MODULE_CLASS(Gem_Multiplayer2_Tools, Multiplayer::MultiplayerToolsModule);
|
||||||
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||||
|
* its licensors.
|
||||||
|
*
|
||||||
|
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||||
|
* distribution (the "License"). All use of this software is governed by the License,
|
||||||
|
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||||
|
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <AzCore/Module/Module.h>
|
||||||
|
|
||||||
|
namespace Multiplayer
|
||||||
|
{
|
||||||
|
class MultiplayerToolsModule
|
||||||
|
: public AZ::Module
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
AZ_RTTI(MultiplayerToolsModule, "{3F726172-21FC-48FA-8CFA-7D87EBA07E55}", AZ::Module);
|
||||||
|
AZ_CLASS_ALLOCATOR(MultiplayerToolsModule, AZ::SystemAllocator, 0);
|
||||||
|
|
||||||
|
MultiplayerToolsModule();
|
||||||
|
~MultiplayerToolsModule() override = default;
|
||||||
|
|
||||||
|
AZ::ComponentTypeList GetRequiredSystemComponents() const override;
|
||||||
|
};
|
||||||
|
} // namespace Multiplayer
|
||||||
|
|
||||||
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||||
|
* its licensors.
|
||||||
|
*
|
||||||
|
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||||
|
* distribution (the "License"). All use of this software is governed by the License,
|
||||||
|
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||||
|
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Source/NetworkEntity/NetworkSpawnableLibrary.h>
|
||||||
|
#include <AzCore/Asset/AssetManagerBus.h>
|
||||||
|
#include <AzFramework/Spawnable/Spawnable.h>
|
||||||
|
#include <AzCore/StringFunc/StringFunc.h>
|
||||||
|
|
||||||
|
namespace Multiplayer
|
||||||
|
{
|
||||||
|
NetworkSpawnableLibrary::NetworkSpawnableLibrary()
|
||||||
|
{
|
||||||
|
AzFramework::AssetCatalogEventBus::Handler::BusConnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
NetworkSpawnableLibrary::~NetworkSpawnableLibrary()
|
||||||
|
{
|
||||||
|
AzFramework::AssetCatalogEventBus::Handler::BusDisconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetworkSpawnableLibrary::BuildPrefabsList()
|
||||||
|
{
|
||||||
|
auto enumerateCallback = [this](const AZ::Data::AssetId id, const AZ::Data::AssetInfo& info)
|
||||||
|
{
|
||||||
|
if (info.m_assetType == AZ::AzTypeInfo<AzFramework::Spawnable>::Uuid())
|
||||||
|
{
|
||||||
|
ProcessSpawnableAsset(info.m_relativePath, id);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
AZ::Data::AssetCatalogRequestBus::Broadcast(&AZ::Data::AssetCatalogRequests::EnumerateAssets, nullptr,
|
||||||
|
enumerateCallback, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetworkSpawnableLibrary::ProcessSpawnableAsset(const AZStd::string& relativePath, const AZ::Data::AssetId id)
|
||||||
|
{
|
||||||
|
const AZ::Name name = AZ::Name(relativePath);
|
||||||
|
m_spawnables[name] = id;
|
||||||
|
m_spawnablesReverseLookup[id] = name;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetworkSpawnableLibrary::OnCatalogLoaded([[maybe_unused]] const char* catalogFile)
|
||||||
|
{
|
||||||
|
BuildPrefabsList();
|
||||||
|
}
|
||||||
|
|
||||||
|
AZ::Name NetworkSpawnableLibrary::GetPrefabNameFromAssetId(AZ::Data::AssetId assetId)
|
||||||
|
{
|
||||||
|
if (assetId.IsValid())
|
||||||
|
{
|
||||||
|
auto it = m_spawnablesReverseLookup.find(assetId);
|
||||||
|
if (it != m_spawnablesReverseLookup.end())
|
||||||
|
{
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
AZ::Data::AssetId NetworkSpawnableLibrary::GetAssetIdByName(AZ::Name name)
|
||||||
|
{
|
||||||
|
auto it = m_spawnables.find(name);
|
||||||
|
if (it != m_spawnables.end())
|
||||||
|
{
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||||
|
* its licensors.
|
||||||
|
*
|
||||||
|
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||||
|
* distribution (the "License"). All use of this software is governed by the License,
|
||||||
|
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||||
|
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <AzCore/Asset/AssetCommon.h>
|
||||||
|
#include <AzCore/std/string/string.h>
|
||||||
|
#include <AzFramework/Asset/AssetCatalogBus.h>
|
||||||
|
#include <AzCore/Name/Name.h>
|
||||||
|
|
||||||
|
namespace Multiplayer
|
||||||
|
{
|
||||||
|
/// Implementation of the network prefab library interface.
|
||||||
|
class NetworkSpawnableLibrary final
|
||||||
|
: private AzFramework::AssetCatalogEventBus::Handler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NetworkSpawnableLibrary();
|
||||||
|
~NetworkSpawnableLibrary();
|
||||||
|
|
||||||
|
void BuildPrefabsList();
|
||||||
|
void ProcessSpawnableAsset(const AZStd::string& relativePath, AZ::Data::AssetId id);
|
||||||
|
|
||||||
|
/// AssetCatalogEventBus overrides.
|
||||||
|
void OnCatalogLoaded(const char* catalogFile) override;
|
||||||
|
|
||||||
|
AZ::Name GetPrefabNameFromAssetId(AZ::Data::AssetId assetId);
|
||||||
|
AZ::Data::AssetId GetAssetIdByName(AZ::Name name);
|
||||||
|
|
||||||
|
private:
|
||||||
|
AZStd::unordered_map<AZ::Name, AZ::Data::AssetId> m_spawnables;
|
||||||
|
AZStd::unordered_map<AZ::Data::AssetId, AZ::Name> m_spawnablesReverseLookup;
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||||
|
* its licensors.
|
||||||
|
*
|
||||||
|
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||||
|
* distribution (the "License"). All use of this software is governed by the License,
|
||||||
|
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||||
|
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Source/Pipeline/NetBindMarkerComponent.h>
|
||||||
|
#include <AzCore/Serialization/SerializeContext.h>
|
||||||
|
|
||||||
|
namespace Multiplayer
|
||||||
|
{
|
||||||
|
void NetBindMarkerComponent::Reflect(AZ::ReflectContext* context)
|
||||||
|
{
|
||||||
|
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
|
||||||
|
if (serializeContext)
|
||||||
|
{
|
||||||
|
serializeContext->Class<NetBindMarkerComponent, AZ::Component>()
|
||||||
|
->Version(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetBindMarkerComponent::Activate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetBindMarkerComponent::Deactivate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||||
|
* its licensors.
|
||||||
|
*
|
||||||
|
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||||
|
* distribution (the "License"). All use of this software is governed by the License,
|
||||||
|
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||||
|
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <AzCore/Component/Component.h>
|
||||||
|
|
||||||
|
namespace Multiplayer
|
||||||
|
{
|
||||||
|
//! @class NetBindMarkerComponent
|
||||||
|
//! @brief Component for tracking net entities in the original non-networked spawnable.
|
||||||
|
class NetBindMarkerComponent final : public AZ::Component
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AZ_COMPONENT(NetBindMarkerComponent, "{40612C1B-427D-45C6-A2F0-04E16DF5B718}");
|
||||||
|
|
||||||
|
static void Reflect(AZ::ReflectContext* context);
|
||||||
|
|
||||||
|
NetBindMarkerComponent() = default;
|
||||||
|
~NetBindMarkerComponent() override = default;
|
||||||
|
|
||||||
|
//! AZ::Component overrides.
|
||||||
|
//! @{
|
||||||
|
void Activate() override;
|
||||||
|
void Deactivate() override;
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
} // namespace Multiplayer
|
||||||
@ -0,0 +1,184 @@
|
|||||||
|
/*
|
||||||
|
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||||
|
* its licensors.
|
||||||
|
*
|
||||||
|
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||||
|
* distribution (the "License"). All use of this software is governed by the License,
|
||||||
|
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||||
|
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Source/Pipeline/NetworkPrefabProcessor.h>
|
||||||
|
|
||||||
|
#include <AzCore/Serialization/Utils.h>
|
||||||
|
#include <AzFramework/Components/TransformComponent.h>
|
||||||
|
#include <AzFramework/Spawnable/Spawnable.h>
|
||||||
|
#include <AzToolsFramework/Prefab/Instance/Instance.h>
|
||||||
|
#include <AzToolsFramework/Prefab/PrefabDomUtils.h>
|
||||||
|
#include <Prefab/Spawnable/SpawnableUtils.h>
|
||||||
|
#include <Source/Components/NetBindComponent.h>
|
||||||
|
#include <Source/Pipeline/NetBindMarkerComponent.h>
|
||||||
|
#include <Source/Pipeline/NetworkSpawnableHolderComponent.h>
|
||||||
|
|
||||||
|
namespace Multiplayer
|
||||||
|
{
|
||||||
|
using AzToolsFramework::Prefab::PrefabConversionUtils::PrefabProcessor;
|
||||||
|
using AzToolsFramework::Prefab::PrefabConversionUtils::ProcessedObjectStore;
|
||||||
|
|
||||||
|
void NetworkPrefabProcessor::Process(PrefabProcessorContext& context)
|
||||||
|
{
|
||||||
|
context.ListPrefabs([&context](AZStd::string_view prefabName, PrefabDom& prefab) {
|
||||||
|
ProcessPrefab(context, prefabName, prefab);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetworkPrefabProcessor::Reflect(AZ::ReflectContext* context)
|
||||||
|
{
|
||||||
|
if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context); serializeContext != nullptr)
|
||||||
|
{
|
||||||
|
serializeContext->Class<NetworkPrefabProcessor, PrefabProcessor>()->Version(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static AZStd::vector<AZ::Entity*> GetEntitiesFromInstance(AZStd::unique_ptr<AzToolsFramework::Prefab::Instance>& instance)
|
||||||
|
{
|
||||||
|
AZStd::vector<AZ::Entity*> result;
|
||||||
|
|
||||||
|
instance->GetNestedEntities([&result](const AZStd::unique_ptr<AZ::Entity>& entity) {
|
||||||
|
result.emplace_back(entity.get());
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (instance->HasContainerEntity())
|
||||||
|
{
|
||||||
|
auto containerEntityReference = instance->GetContainerEntity();
|
||||||
|
result.emplace_back(&containerEntityReference->get());
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
void NetworkPrefabProcessor::ProcessPrefab(PrefabProcessorContext& context, AZStd::string_view prefabName, PrefabDom& prefab)
|
||||||
|
{
|
||||||
|
using namespace AzToolsFramework::Prefab;
|
||||||
|
|
||||||
|
// convert Prefab DOM into Prefab Instance.
|
||||||
|
AZStd::unique_ptr<Instance> sourceInstance(aznew Instance());
|
||||||
|
if (!PrefabDomUtils::LoadInstanceFromPrefabDom(*sourceInstance, prefab,
|
||||||
|
PrefabDomUtils::LoadInstanceFlags::AssignRandomEntityId))
|
||||||
|
{
|
||||||
|
PrefabDomValueReference sourceReference = PrefabDomUtils::FindPrefabDomValue(prefab, PrefabDomUtils::SourceName);
|
||||||
|
|
||||||
|
AZStd::string errorMessage("NetworkPrefabProcessor: Failed to Load Prefab Instance from given Prefab Dom.");
|
||||||
|
if (sourceReference.has_value() && sourceReference->get().IsString() && sourceReference->get().GetStringLength() != 0)
|
||||||
|
{
|
||||||
|
AZStd::string_view source(sourceReference->get().GetString(), sourceReference->get().GetStringLength());
|
||||||
|
errorMessage += AZStd::string::format("Prefab Source: %.*s", AZ_STRING_ARG(source));
|
||||||
|
}
|
||||||
|
AZ_Error("NetworkPrefabProcessor", false, errorMessage.c_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AZStd::string uniqueName = prefabName;
|
||||||
|
uniqueName += ".network.spawnable";
|
||||||
|
|
||||||
|
auto serializer = [](AZStd::vector<uint8_t>& output, const ProcessedObjectStore& object) -> bool {
|
||||||
|
AZ::IO::ByteContainerStream stream(&output);
|
||||||
|
auto& asset = object.GetAsset();
|
||||||
|
return AZ::Utils::SaveObjectToStream(stream, AZ::DataStream::ST_JSON, &asset, asset.GetType());
|
||||||
|
};
|
||||||
|
|
||||||
|
auto&& [object, networkSpawnable] =
|
||||||
|
ProcessedObjectStore::Create<AzFramework::Spawnable>(uniqueName, context.GetSourceUuid(), AZStd::move(serializer));
|
||||||
|
|
||||||
|
// grab all nested entities from the Instance as source entities.
|
||||||
|
AZStd::vector<AZ::Entity*> sourceEntities = GetEntitiesFromInstance(sourceInstance);
|
||||||
|
AZStd::vector<AZ::EntityId> networkedEntityIds;
|
||||||
|
networkedEntityIds.reserve(sourceEntities.size());
|
||||||
|
|
||||||
|
for (auto* sourceEntity : sourceEntities)
|
||||||
|
{
|
||||||
|
if (sourceEntity->FindComponent<NetBindComponent>())
|
||||||
|
{
|
||||||
|
networkedEntityIds.push_back(sourceEntity->GetId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!PrefabDomUtils::StoreInstanceInPrefabDom(*sourceInstance, prefab))
|
||||||
|
{
|
||||||
|
AZ_Error("NetworkPrefabProcessor", false, "Saving exported Prefab Instance within a Prefab Dom failed.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AZStd::unique_ptr<Instance> networkInstance(aznew Instance());
|
||||||
|
|
||||||
|
for (auto entityId : networkedEntityIds)
|
||||||
|
{
|
||||||
|
AZ::Entity* netEntity = sourceInstance->DetachEntity(entityId).release();
|
||||||
|
|
||||||
|
networkInstance->AddEntity(*netEntity);
|
||||||
|
|
||||||
|
AZ::Entity* breadcrumbEntity = aznew AZ::Entity(netEntity->GetName());
|
||||||
|
breadcrumbEntity->SetRuntimeActiveByDefault(netEntity->IsRuntimeActiveByDefault());
|
||||||
|
breadcrumbEntity->CreateComponent<NetBindMarkerComponent>();
|
||||||
|
AzFramework::TransformComponent* transformComponent = netEntity->FindComponent<AzFramework::TransformComponent>();
|
||||||
|
breadcrumbEntity->CreateComponent<AzFramework::TransformComponent>(*transformComponent);
|
||||||
|
|
||||||
|
// TODO: Add NetBindMarkerComponent here referring to the net entity
|
||||||
|
sourceInstance->AddEntity(*breadcrumbEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add net spawnable asset holder
|
||||||
|
{
|
||||||
|
AZ::Data::AssetId assetId = networkSpawnable->GetId();
|
||||||
|
AZ::Data::Asset<AzFramework::Spawnable> networkSpawnableAsset;
|
||||||
|
networkSpawnableAsset.Create(assetId);
|
||||||
|
|
||||||
|
EntityOptionalReference containerEntityRef = sourceInstance->GetContainerEntity();
|
||||||
|
if (containerEntityRef.has_value())
|
||||||
|
{
|
||||||
|
auto* networkSpawnableHolderComponent = containerEntityRef.value().get().CreateComponent<NetworkSpawnableHolderComponent>();
|
||||||
|
networkSpawnableHolderComponent->SetNetworkSpawnableAsset(networkSpawnableAsset);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AZ::Entity* networkSpawnableHolderEntity = aznew AZ::Entity(uniqueName);
|
||||||
|
auto* networkSpawnableHolderComponent = networkSpawnableHolderEntity->CreateComponent<NetworkSpawnableHolderComponent>();
|
||||||
|
networkSpawnableHolderComponent->SetNetworkSpawnableAsset(networkSpawnableAsset);
|
||||||
|
sourceInstance->AddEntity(*networkSpawnableHolderEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// save the final result in the target Prefab DOM.
|
||||||
|
PrefabDom networkPrefab;
|
||||||
|
if (!PrefabDomUtils::StoreInstanceInPrefabDom(*networkInstance, networkPrefab))
|
||||||
|
{
|
||||||
|
AZ_Error("NetworkPrefabProcessor", false, "Saving exported Prefab Instance within a Prefab Dom failed.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!PrefabDomUtils::StoreInstanceInPrefabDom(*sourceInstance, prefab))
|
||||||
|
{
|
||||||
|
AZ_Error("NetworkPrefabProcessor", false, "Saving exported Prefab Instance within a Prefab Dom failed.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool result = SpawnableUtils::CreateSpawnable(*networkSpawnable, networkPrefab);
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
AzFramework::Spawnable::EntityList& entities = networkSpawnable->GetEntities();
|
||||||
|
for (auto it = entities.begin(); it != entities.end(); ++it)
|
||||||
|
{
|
||||||
|
(*it)->InvalidateDependencies();
|
||||||
|
(*it)->EvaluateDependencies();
|
||||||
|
}
|
||||||
|
context.GetProcessedObjects().push_back(AZStd::move(object));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AZ_Error("Prefabs", false, "Failed to convert prefab '%.*s' to a spawnable.", AZ_STRING_ARG(prefabName));
|
||||||
|
context.ErrorEncountered();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||||
|
* its licensors.
|
||||||
|
*
|
||||||
|
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||||
|
* distribution (the "License"). All use of this software is governed by the License,
|
||||||
|
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||||
|
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <AzToolsFramework/Prefab/Spawnable/PrefabProcessor.h>
|
||||||
|
|
||||||
|
namespace AzToolsFramework::Prefab::PrefabConversionUtils
|
||||||
|
{
|
||||||
|
class PrefabProcessorContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Multiplayer
|
||||||
|
{
|
||||||
|
using AzToolsFramework::Prefab::PrefabConversionUtils::PrefabProcessor;
|
||||||
|
using AzToolsFramework::Prefab::PrefabConversionUtils::PrefabProcessorContext;
|
||||||
|
using AzToolsFramework::Prefab::PrefabDom;
|
||||||
|
|
||||||
|
class NetworkPrefabProcessor : public PrefabProcessor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AZ_CLASS_ALLOCATOR(NetworkPrefabProcessor, AZ::SystemAllocator, 0);
|
||||||
|
AZ_RTTI(NetworkPrefabProcessor, "{AF6C36DA-CBB9-4DF4-AE2D-7BC6CCE65176}", PrefabProcessor);
|
||||||
|
|
||||||
|
~NetworkPrefabProcessor() override = default;
|
||||||
|
|
||||||
|
void Process(PrefabProcessorContext& context) override;
|
||||||
|
|
||||||
|
static void Reflect(AZ::ReflectContext* context);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static void ProcessPrefab(PrefabProcessorContext& context, AZStd::string_view prefabName, PrefabDom& prefab);
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||||
|
* its licensors.
|
||||||
|
*
|
||||||
|
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||||
|
* distribution (the "License"). All use of this software is governed by the License,
|
||||||
|
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||||
|
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Source/Pipeline/NetworkSpawnableHolderComponent.h>
|
||||||
|
#include <AzCore/Serialization/SerializeContext.h>
|
||||||
|
|
||||||
|
namespace Multiplayer
|
||||||
|
{
|
||||||
|
void NetworkSpawnableHolderComponent::Reflect(AZ::ReflectContext* context)
|
||||||
|
{
|
||||||
|
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
|
||||||
|
if (serializeContext)
|
||||||
|
{
|
||||||
|
serializeContext->Class<NetworkSpawnableHolderComponent, AZ::Component>()
|
||||||
|
->Version(1)
|
||||||
|
->Field("AssetRef", &NetworkSpawnableHolderComponent::m_networkSpawnableAsset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetworkSpawnableHolderComponent::Activate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetworkSpawnableHolderComponent::Deactivate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetworkSpawnableHolderComponent::SetNetworkSpawnableAsset(AZ::Data::Asset<AzFramework::Spawnable> networkSpawnableAsset)
|
||||||
|
{
|
||||||
|
m_networkSpawnableAsset = networkSpawnableAsset;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||||
|
* its licensors.
|
||||||
|
*
|
||||||
|
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||||
|
* distribution (the "License"). All use of this software is governed by the License,
|
||||||
|
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||||
|
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <AzCore/Component/Component.h>
|
||||||
|
#include <AzCore/Asset/AssetCommon.h>
|
||||||
|
#include <AzFramework/Spawnable/Spawnable.h>
|
||||||
|
|
||||||
|
namespace Multiplayer
|
||||||
|
{
|
||||||
|
//! @class NetworkSpawnableHolderComponent
|
||||||
|
//! @brief Component for holding a reference to the network spawnable to make sure it is loaded with the original one.
|
||||||
|
class NetworkSpawnableHolderComponent final : public AZ::Component
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AZ_COMPONENT(NetworkSpawnableHolderComponent, "{B0E3ADEE-FCB4-4A32-8D4F-6920F1CB08E4}");
|
||||||
|
|
||||||
|
static void Reflect(AZ::ReflectContext* context);
|
||||||
|
|
||||||
|
NetworkSpawnableHolderComponent() = default;
|
||||||
|
~NetworkSpawnableHolderComponent() override = default;
|
||||||
|
|
||||||
|
//! AZ::Component overrides.
|
||||||
|
//! @{
|
||||||
|
void Activate() override;
|
||||||
|
void Deactivate() override;
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
void SetNetworkSpawnableAsset(AZ::Data::Asset<AzFramework::Spawnable> networkSpawnableAsset);
|
||||||
|
|
||||||
|
private:
|
||||||
|
AZ::Data::Asset<AzFramework::Spawnable> m_networkSpawnableAsset{ AZ::Data::AssetLoadBehavior::PreLoad };
|
||||||
|
};
|
||||||
|
} // namespace Multiplayer
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
#
|
||||||
|
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||||
|
# its licensors.
|
||||||
|
#
|
||||||
|
# For complete copyright and license terms please see the LICENSE at the root of this
|
||||||
|
# distribution (the "License"). All use of this software is governed by the License,
|
||||||
|
# or, if provided, by the license below or the license accompanying this file. Do not
|
||||||
|
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
#
|
||||||
|
|
||||||
|
set(FILES
|
||||||
|
Source/Multiplayer_precompiled.cpp
|
||||||
|
Source/Multiplayer_precompiled.h
|
||||||
|
Source/Pipeline/NetworkPrefabProcessor.cpp
|
||||||
|
Source/Pipeline/NetworkPrefabProcessor.h
|
||||||
|
Source/MultiplayerToolsModule.h
|
||||||
|
Source/MultiplayerToolsModule.cpp
|
||||||
|
)
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"Amazon":
|
||||||
|
{
|
||||||
|
"Tools":
|
||||||
|
{
|
||||||
|
"Prefab":
|
||||||
|
{
|
||||||
|
"Processing":
|
||||||
|
{
|
||||||
|
"Stack":
|
||||||
|
{
|
||||||
|
"GameObjectCreation":
|
||||||
|
[
|
||||||
|
{ "$type": "AzToolsFramework::Prefab::PrefabConversionUtils::EditorInfoRemover" },
|
||||||
|
{ "$type": "{AF6C36DA-CBB9-4DF4-AE2D-7BC6CCE65176}" },
|
||||||
|
{
|
||||||
|
"$type": "AzToolsFramework::Prefab::PrefabConversionUtils::PrefabCatchmentProcessor",
|
||||||
|
"SerializationFormat": "Text" // Options are "Binary" (default) or "Text". Prefer "Binary" for performance.
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue