AkTrigger.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*******************************************************************************
  2. The content of this file includes portions of the proprietary AUDIOKINETIC Wwise
  3. Technology released in source code form as part of the game integration package.
  4. The content of this file may not be used without valid licenses to the
  5. AUDIOKINETIC Wwise Technology.
  6. Note that the use of the game engine is subject to the Unreal(R) Engine End User
  7. License Agreement at https://www.unrealengine.com/en-US/eula/unreal
  8. License Usage
  9. Licensees holding valid licenses to the AUDIOKINETIC Wwise Technology may use
  10. this file in accordance with the end user license agreement provided with the
  11. software or, alternatively, in accordance with the terms contained
  12. in a written agreement between you and Audiokinetic Inc.
  13. Copyright (c) 2023 Audiokinetic Inc.
  14. *******************************************************************************/
  15. #include "AkTrigger.h"
  16. #include "Wwise/Stats/AkAudio.h"
  17. #if WITH_EDITORONLY_DATA
  18. #include "Wwise/WwiseProjectDatabase.h"
  19. #include "Wwise/WwiseResourceCooker.h"
  20. #include "AkAudioDevice.h"
  21. #endif
  22. void UAkTrigger::Serialize(FArchive& Ar)
  23. {
  24. Super::Serialize(Ar);
  25. if (HasAnyFlags(RF_ClassDefaultObject))
  26. {
  27. return;
  28. }
  29. #if !UE_SERVER
  30. #if WITH_EDITORONLY_DATA
  31. if (Ar.IsCooking() && Ar.IsSaving() && !Ar.CookingTarget()->IsServerOnly())
  32. {
  33. FWwiseTriggerCookedData CookedDataToArchive;
  34. if (auto* ResourceCooker = FWwiseResourceCooker::GetForArchive(Ar))
  35. {
  36. ResourceCooker->PrepareCookedData(CookedDataToArchive, GetValidatedInfo(TriggerInfo));
  37. }
  38. CookedDataToArchive.Serialize(Ar);
  39. }
  40. #else
  41. TriggerCookedData.Serialize(Ar);
  42. #endif
  43. #endif
  44. }
  45. #if WITH_EDITOR
  46. void UAkTrigger::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
  47. {
  48. Super::PostEditChangeProperty(PropertyChangedEvent);
  49. GetTriggerCookedData();
  50. }
  51. #endif
  52. #if WITH_EDITORONLY_DATA
  53. void UAkTrigger::FillInfo()
  54. {
  55. auto* ResourceCooker = FWwiseResourceCooker::GetDefault();
  56. if (UNLIKELY(!ResourceCooker))
  57. {
  58. UE_LOG(LogAkAudio, Error, TEXT("UAkTrigger::FillInfo: ResourceCooker not initialized"));
  59. return;
  60. }
  61. auto ProjectDatabase = ResourceCooker->GetProjectDatabase();
  62. if (UNLIKELY(!ProjectDatabase))
  63. {
  64. UE_LOG(LogAkAudio, Error, TEXT("UAkTrigger::FillInfo: ProjectDatabase not initialized"));
  65. return;
  66. }
  67. FWwiseObjectInfo* AudioTypeInfo = &TriggerInfo;
  68. FWwiseRefTrigger TriggerRef = FWwiseDataStructureScopeLock(*ProjectDatabase).GetTrigger(
  69. GetValidatedInfo(TriggerInfo));
  70. if (TriggerRef.TriggerName().ToString().IsEmpty() || !TriggerRef.TriggerGuid().IsValid() || TriggerRef.TriggerId() == AK_INVALID_UNIQUE_ID)
  71. {
  72. UE_LOG(LogAkAudio, Warning, TEXT("UAkTrigger::FillInfo: Valid object not found in Project Database"));
  73. return;
  74. }
  75. AudioTypeInfo->WwiseName = TriggerRef.TriggerName();
  76. AudioTypeInfo->WwiseGuid = TriggerRef.TriggerGuid();
  77. AudioTypeInfo->WwiseShortId = TriggerRef.TriggerId();
  78. }
  79. bool UAkTrigger::ObjectIsInSoundBanks()
  80. {
  81. auto* ResourceCooker = FWwiseResourceCooker::GetDefault();
  82. if (UNLIKELY(!ResourceCooker))
  83. {
  84. UE_LOG(LogAkAudio, Error, TEXT("UAkTrigger::GetWwiseRef: ResourceCooker not initialized"));
  85. return false;
  86. }
  87. auto ProjectDatabase = ResourceCooker->GetProjectDatabase();
  88. if (UNLIKELY(!ProjectDatabase))
  89. {
  90. UE_LOG(LogAkAudio, Error, TEXT("UAkTrigger::GetWwiseRef: ProjectDatabase not initialized"));
  91. return false;
  92. }
  93. FWwiseObjectInfo* AudioTypeInfo = &TriggerInfo;
  94. FWwiseRefTrigger TriggerRef = FWwiseDataStructureScopeLock(*ProjectDatabase).GetTrigger(
  95. GetValidatedInfo(TriggerInfo));
  96. return TriggerRef.IsValid();
  97. }
  98. void UAkTrigger::GetTriggerCookedData()
  99. {
  100. SCOPED_AKAUDIO_EVENT_2(TEXT("GetTriggerCookedData"));
  101. if (!IWwiseProjectDatabaseModule::ShouldInitializeProjectDatabase())
  102. {
  103. return;
  104. }
  105. auto* ProjectDatabase = FWwiseProjectDatabase::Get();
  106. if (!ProjectDatabase || !ProjectDatabase->IsProjectDatabaseParsed())
  107. {
  108. UE_LOG(LogAkAudio, VeryVerbose, TEXT("UAkTrigger::GetTriggerCookedData: Not loading '%s' because project database is not parsed."), *GetName())
  109. return;
  110. }
  111. auto* ResourceCooker = FWwiseResourceCooker::GetDefault();
  112. if (UNLIKELY(!ResourceCooker))
  113. {
  114. return;
  115. }
  116. ResourceCooker->PrepareCookedData(TriggerCookedData, GetValidatedInfo(TriggerInfo));
  117. }
  118. #endif