#include <GenericAssetHandler.h>
Inherits AZ::Data::AssetHandler.
Inherited by AzFramework::GenericAssetHandler< AssetType >.
Public Member Functions | |
| AZ_RTTI (GenericAssetHandlerBase, "{B153B8B5-25CC-4BB7-A2BD-9A47ECF4123C}", AZ::Data::AssetHandler) | |
| AZ::Data::AssetId | AssetMissingInCatalog (const AZ::Data::Asset< AZ::Data::AssetData > &asset) override |
| virtual bool | AutoBuildAssetToCache ()=0 |
Generic implementation of an asset handler for any arbitrary type that is reflected for serialization.
Simple or game specific assets that wish to make use of automated loading and editing facilities can use this handler with any asset type that's reflected for editing.
Example:
class MyAsset : public AZ::Data::AssetData { public: AZ_CLASS_ALLOCATOR(MyAsset, AZ::SystemAllocator); AZ_RTTI(MyAsset, "{AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE}", AZ::Data::AssetData);
static void Reflect(AZ::ReflectContext* context) { AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context); if (serialize) { serialize->Class<MyAsset>() ->Version(0) ->Attribute(AZ::Edit::Attributes::EnableForAssetEditor, true) // optional: automatically show in "create new" menu in Asset Editor ->Field("SomeField", &MyAsset::m_someField) // a plain old data field (example) ->Field("myAsset", &MyAsset::m_myAsset) // assignment of some other asset we depend on (example)
;
AZ::EditContext* edit = serialize->GetEditContext(); if (edit) { edit->Class<MyAsset>("My Asset", "Asset for representing X, Y, and Z") ->DataElement(0, &MyAsset::m_someField, "Some data field", "It's a float") ->DataElement(0, &MyAsset::m_myAsset, "Some Asset To Use", "It's a reference to some other asset") ; } } }
float m_someField; Asset<SomeType> m_myAsset { AZ::Data::AssetLoadBehavior::PreLoad }; // example, can choose a different auto load behavior here if you want };
using MyAssetHandler = GenericAssetHandler<MyAsset>;
// Note that you must still register the actual asset handler instance on startup and tear it down on shutdown, using a system component or other // singleton. // Alternatively you can set autoprocess later: s_myAssetHandler = new MyAssetHandler("My Asset Friendly Display Name", "My Asset Group (ie, Graphics, Audio ...)", "my_file_extension_without_dot"); s_myAssetHandler->SetAutoProcessToCache(true); // if you want the system to register, build and copy it to cache and extract deps for you. s_myAssetHandler->Register();
// Registration timing is important. Your component must activate and register its type before the system component that auto builds // asset checks for registration. You do this by making sure your singleton / system component providing the above registration emits // AzFramework::s_GenericAssetRegistrar as one of its Provided Services, which will cause it to activate before the system // that depends on that service.
Example:
void MySystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) override { provided.push_back(AzFramework::s_GenericAssetRegistrar); // Activate me before things that need these registrations. } Just a base class to assign concrete RTTI to these classes - Don't derive from this - use GenericAssetHandler<T> instead. This being in the heirarchy allows you to easily ask whether a particular handler derives from this type and thus is a GenericAssetHandler.
|
pure virtual |
Overridden in GenericAssetHandler to return whether or not the asset should be auto processed into the cache. This is based on what the constructor sets.
Implemented in AzFramework::GenericAssetHandler< AssetType >.