123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- /*******************************************************************************
- The content of this file includes portions of the proprietary AUDIOKINETIC Wwise
- Technology released in source code form as part of the game integration package.
- The content of this file may not be used without valid licenses to the
- AUDIOKINETIC Wwise Technology.
- Note that the use of the game engine is subject to the Unreal(R) Engine End User
- License Agreement at https://www.unrealengine.com/en-US/eula/unreal
-
- License Usage
-
- Licensees holding valid licenses to the AUDIOKINETIC Wwise Technology may use
- this file in accordance with the end user license agreement provided with the
- software or, alternatively, in accordance with the terms contained
- in a written agreement between you and Audiokinetic Inc.
- Copyright (c) 2023 Audiokinetic Inc.
- *******************************************************************************/
- #include "AkAssetFactories.h"
- #include "AkAcousticTexture.h"
- #include "AkAudioBank.h"
- #include "AkAudioDevice.h"
- #include "AkAudioEvent.h"
- #include "AkAuxBus.h"
- #include "AkRtpc.h"
- #include "AkSettings.h"
- #include "AkSettingsPerUser.h"
- #include "AkStateValue.h"
- #include "AkSwitchValue.h"
- #include "AkTrigger.h"
- #include "AkEffectShareSet.h"
- #include "AssetManagement/AkAssetDatabase.h"
- #include "AssetToolsModule.h"
- struct AkAssetFactory_Helper
- {
- template<typename AkAssetType = UAkAudioType>
- static UObject* FactoryCreateNew(UClass* Class, UObject* InParent, const FName& Name, EObjectFlags Flags, FGuid AssetID = FGuid{}, uint32 ShortID = AK_INVALID_UNIQUE_ID, FString WwiseObjectName = "")
- {
- auto ContainingPath = InParent->GetName();
- auto NewWwiseObject = NewObject<AkAssetType>(InParent, Name, Flags);
- FWwiseObjectInfo* Info = NewWwiseObject->GetInfoMutable();
- Info->WwiseGuid = AssetID;
- if (WwiseObjectName.IsEmpty())
- {
- Info->WwiseName = Name;
- }
- else
- {
- Info->WwiseName = FName(WwiseObjectName);
- }
- if (ShortID == AK_INVALID_UNIQUE_ID)
- {
- Info->WwiseShortId = FAkAudioDevice::GetShortID(nullptr, Name.ToString());
- }
- else
- {
- Info->WwiseShortId = ShortID;
- }
- NewWwiseObject->MarkPackageDirty();
- if(NewWwiseObject->bAutoLoad)
- {
- NewWwiseObject->LoadData();
- }
- return NewWwiseObject;
- }
- template<typename AkAssetType = UAkGroupValue>
- static UObject* FactoryCreateNewGroupValue(UClass* Class, UObject* InParent, const FName& Name, EObjectFlags Flags, FGuid AssetID = FGuid{}, uint32 ShortID = AK_INVALID_UNIQUE_ID, FString WwiseObjectName = "")
- {
- auto ContainingPath = InParent->GetName();
- AkAssetType* NewStateValue = NewObject<AkAssetType>(InParent, Name, Flags);
- FWwiseGroupValueInfo* Info = static_cast<FWwiseGroupValueInfo*>(NewStateValue->GetInfoMutable());
- Info->WwiseGuid = AssetID;
- FString StringName = Name.ToString();
- FString ValueName = StringName;
- FString GroupName;
- if (StringName.Contains(TEXT("-")))
- {
- StringName.Split(TEXT("-"), &GroupName, &ValueName);
- }
- if (WwiseObjectName.IsEmpty() && ValueName.IsEmpty())
- {
- Info->WwiseName = FName(StringName);
- }
- else if (WwiseObjectName.IsEmpty())
- {
- Info->WwiseName = FName(ValueName);
- }
- else
- {
- Info->WwiseName = FName(WwiseObjectName);
- }
- if (ShortID == AK_INVALID_UNIQUE_ID)
- {
- Info->WwiseShortId = FAkAudioDevice::GetShortID(nullptr, Info->WwiseName.ToString());
- }
- else
- {
- Info->WwiseShortId = ShortID;
- }
- if (!GroupName.IsEmpty())
- {
- Info->GroupShortId = FAkAudioDevice::GetShortID(nullptr, GroupName);
- }
- else
- {
- Info->GroupShortId = AK_INVALID_UNIQUE_ID;
- UE_LOG(LogAkAudio, Warning, TEXT("FactoryCreateNewGroupValue: New Group Value asset '%s' in '%s' will have an invalid group ID, please set the group ID manually."), *StringName, *InParent->GetPathName());
- }
- NewStateValue->MarkPackageDirty();
- if(NewStateValue->bAutoLoad)
- {
- NewStateValue->LoadData();
- }
- return NewStateValue;
- }
- template<typename AkAssetType>
- static bool CanCreateNew()
- {
- const UAkSettings* AkSettings = GetDefault<UAkSettings>();
- if (AkSettings)
- {
- return true;
- }
- return false;
- }
- private:
- static FString ConvertAssetPathToWwisePath(FString ContainingPath, const FString& AssetName, const FString& BasePath)
- {
- ContainingPath.RemoveFromStart(BasePath, ESearchCase::IgnoreCase);
- ContainingPath.RemoveFromEnd(FString("/") + AssetName);
- return ContainingPath.Replace(TEXT("/"), TEXT("\\")).Replace(TEXT("_"), TEXT(" "));
- }
- };
- //////////////////////////////////////////////////////////////////////////
- // UAkAcousticTextureFactory
- UAkAcousticTextureFactory::UAkAcousticTextureFactory(const class FObjectInitializer& ObjectInitializer)
- : Super(ObjectInitializer)
- {
- SupportedClass = UAkAcousticTexture::StaticClass();
- bCreateNew = bEditorImport = bEditAfterNew = true;
- }
- UObject* UAkAcousticTextureFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)
- {
- return AkAssetFactory_Helper::FactoryCreateNew<UAkAcousticTexture>(Class, InParent, Name, Flags, AssetID, ShortID, WwiseObjectName);
- }
- bool UAkAcousticTextureFactory::CanCreateNew() const
- {
- return AkAssetFactory_Helper::CanCreateNew<UAkAcousticTexture>();
- }
- //////////////////////////////////////////////////////////////////////////
- // UAkAudioEventFactory
- UAkAudioEventFactory::UAkAudioEventFactory(const class FObjectInitializer& ObjectInitializer)
- : Super(ObjectInitializer)
- {
- SupportedClass = UAkAudioEvent::StaticClass();
- bCreateNew = bEditorImport = bEditAfterNew = true;
- }
- UObject* UAkAudioEventFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)
- {
- return AkAssetFactory_Helper::FactoryCreateNew<UAkAudioEvent>(Class, InParent, Name, Flags, AssetID, ShortID, WwiseObjectName);
- }
- bool UAkAudioEventFactory::CanCreateNew() const
- {
- return AkAssetFactory_Helper::CanCreateNew<UAkAudioEvent>();
- }
- //////////////////////////////////////////////////////////////////////////
- // UAkAuxBusFactory
- UAkAuxBusFactory::UAkAuxBusFactory(const class FObjectInitializer& ObjectInitializer)
- : Super(ObjectInitializer)
- {
- SupportedClass = UAkAuxBus::StaticClass();
- bCreateNew = bEditorImport = bEditAfterNew = true;
- }
- UObject* UAkAuxBusFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)
- {
- return AkAssetFactory_Helper::FactoryCreateNew<UAkAuxBus>(Class, InParent, Name, Flags, AssetID, ShortID, WwiseObjectName);
- }
- bool UAkAuxBusFactory::CanCreateNew() const
- {
- return AkAssetFactory_Helper::CanCreateNew<UAkAuxBus>();
- }
- //////////////////////////////////////////////////////////////////////////
- // UAkRtpcFactory
- UAkRtpcFactory::UAkRtpcFactory(const class FObjectInitializer& ObjectInitializer)
- : Super(ObjectInitializer)
- {
- SupportedClass = UAkRtpc::StaticClass();
- bCreateNew = bEditorImport = bEditAfterNew = true;
- }
- UObject* UAkRtpcFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)
- {
- return AkAssetFactory_Helper::FactoryCreateNew<UAkRtpc>(Class, InParent, Name, Flags, AssetID, ShortID, WwiseObjectName);
- }
- bool UAkRtpcFactory::CanCreateNew() const
- {
- return AkAssetFactory_Helper::CanCreateNew<UAkRtpc>();
- }
- //////////////////////////////////////////////////////////////////////////
- // UAkTriggerFactory
- UAkTriggerFactory::UAkTriggerFactory(const class FObjectInitializer& ObjectInitializer)
- : Super(ObjectInitializer)
- {
- SupportedClass = UAkTrigger::StaticClass();
- bCreateNew = bEditorImport = bEditAfterNew = true;
- }
- UObject* UAkTriggerFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)
- {
- return AkAssetFactory_Helper::FactoryCreateNew<UAkTrigger>(Class, InParent, Name, Flags, AssetID, ShortID, WwiseObjectName);
- }
- bool UAkTriggerFactory::CanCreateNew() const
- {
- return AkAssetFactory_Helper::CanCreateNew<UAkTrigger>();
- }
- //////////////////////////////////////////////////////////////////////////
- // UAkStateValueFactory
- UAkStateValueFactory::UAkStateValueFactory(const class FObjectInitializer& ObjectInitializer)
- : Super(ObjectInitializer)
- {
- SupportedClass = UAkStateValue::StaticClass();
- bCreateNew = bEditorImport = bEditAfterNew = true;
- }
- UObject* UAkStateValueFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)
- {
- return AkAssetFactory_Helper::FactoryCreateNewGroupValue<UAkStateValue>(Class, InParent, Name, Flags, AssetID, ShortID, WwiseObjectName);
- }
- //////////////////////////////////////////////////////////////////////////
- // UAkSwitchValueFactory
- UAkSwitchValueFactory::UAkSwitchValueFactory(const class FObjectInitializer& ObjectInitializer)
- : Super(ObjectInitializer)
- {
- SupportedClass = UAkSwitchValue::StaticClass();
- bCreateNew = bEditorImport = bEditAfterNew = true;
- }
- UObject* UAkSwitchValueFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)
- {
- return AkAssetFactory_Helper::FactoryCreateNewGroupValue<UAkSwitchValue>(Class, InParent, Name, Flags, AssetID, ShortID, WwiseObjectName);
- }
- //////////////////////////////////////////////////////////////////////////
- // UAkEffectShareSetFactory
- UAkEffectShareSetFactory::UAkEffectShareSetFactory(const class FObjectInitializer& ObjectInitializer)
- : Super(ObjectInitializer)
- {
- SupportedClass = UAkEffectShareSet::StaticClass();
- bCreateNew = bEditorImport = bEditAfterNew = true;
- }
- UObject* UAkEffectShareSetFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)
- {
- return AkAssetFactory_Helper::FactoryCreateNew<UAkEffectShareSet>(Class, InParent, Name, Flags, AssetID, ShortID, WwiseObjectName);
- }
|