/* * 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 "StdAfx.h" #include #include #include #include namespace Blast { BlastAssetHandler::~BlastAssetHandler() { Unregister(); } AZ::Data::AssetPtr BlastAssetHandler::CreateAsset( const AZ::Data::AssetId& id, [[maybe_unused]] const AZ::Data::AssetType& type) { if (!CanHandleAsset(id) || type != GetAssetType()) { AZ_Error("Blast", false, "Invalid asset type! BlastAssetHandler only handle 'BlastAsset'"); return nullptr; } return aznew BlastAsset; } AZ::Data::AssetHandler::LoadResult BlastAssetHandler::LoadAssetData( const AZ::Data::Asset& asset, AZStd::shared_ptr stream, [[maybe_unused]] const AZ::Data::AssetFilterCB& assetLoadFilterCB) { if (!stream || asset.GetType() != AZ::AzTypeInfo::Uuid()) { AZ_Error( "Blast", asset.GetType() == AZ::AzTypeInfo::Uuid(), "Invalid asset type! We only handle 'BlastAsset'"); return LoadResult::Error; } BlastAsset* data = asset.GetAs(); const size_t sizeBytes = static_cast(stream->GetLength()); AZStd::vector buffer; buffer.resize_no_construct(sizeBytes); stream->Read(sizeBytes, buffer.data()); return data->LoadFromBuffer(buffer.data(), sizeBytes) ? LoadResult::LoadComplete : LoadResult::Error; } void BlastAssetHandler::DestroyAsset(AZ::Data::AssetPtr ptr) { delete ptr; } void BlastAssetHandler::GetHandledAssetTypes(AZStd::vector& assetTypes) { assetTypes.push_back(AZ::AzTypeInfo::Uuid()); } void BlastAssetHandler::Register() { AZ_Assert(AZ::Data::AssetManager::IsReady(), "Asset manager isn't ready!"); AZ::Data::AssetManager::Instance().RegisterHandler(this, AZ::AzTypeInfo::Uuid()); AZ::AssetTypeInfoBus::Handler::BusConnect(AZ::AzTypeInfo::Uuid()); } void BlastAssetHandler::Unregister() { AZ::AssetTypeInfoBus::Handler::BusDisconnect(AZ::AzTypeInfo::Uuid()); if (AZ::Data::AssetManager::IsReady()) { AZ::Data::AssetManager::Instance().UnregisterHandler(this); } } AZ::Data::AssetType BlastAssetHandler::GetAssetType() const { return AZ::AzTypeInfo::Uuid(); } const char* BlastAssetHandler::GetAssetTypeDisplayName() const { return "Blast Asset"; } const char* BlastAssetHandler::GetGroup() const { return "Blast"; } const char* BlastAssetHandler::GetBrowserIcon() const { return "Editor/Icons/Components/Box.png"; } void BlastAssetHandler::GetAssetTypeExtensions(AZStd::vector& extensions) { extensions.push_back("blast"); } } // namespace Blast