WwiseUnrealHelper.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 "WwiseUnrealHelper.h"
  16. #include "Misc/Guid.h"
  17. #include "Misc/Paths.h"
  18. #include "Wwise/Stats/Global.h"
  19. namespace WwiseUnrealHelper
  20. {
  21. const TCHAR* MediaFolderName = TEXT("Media");
  22. const TCHAR* ExternalSourceFolderName = TEXT("ExternalSources");
  23. constexpr auto SoundBankNamePrefix = TEXT("SB_");
  24. const FGuid InitBankID(0x701ECBBD, 0x9C7B4030, 0x8CDB749E, 0xE5D1C7B9);
  25. FString(*GetWwisePluginDirectoryPtr)();
  26. FString(*GetWwiseProjectPathPtr)();
  27. FString(*GetSoundBankDirectoryPtr)();
  28. FString(*GetStagePathPtr)();
  29. void SetHelperFunctions(FString(* GetWwisePluginDirectoryImpl)(), FString(* GetWwiseProjectPathImpl)(),
  30. FString(* GetSoundBankDirectoryImpl)(), FString(* GetStagePathImpl)())
  31. {
  32. GetWwisePluginDirectoryPtr = GetWwisePluginDirectoryImpl;
  33. GetWwiseProjectPathPtr = GetWwiseProjectPathImpl;
  34. GetSoundBankDirectoryPtr = GetSoundBankDirectoryImpl;
  35. GetStagePathPtr = GetStagePathImpl;
  36. }
  37. FString GetWwisePluginDirectory()
  38. {
  39. if (!GetWwisePluginDirectoryPtr)
  40. {
  41. UE_LOG(LogWwiseUtils, Error, TEXT("WwiseUnrealHelper::GetWwisePluginDirectory implementation not set."));
  42. return {};
  43. }
  44. return GetWwisePluginDirectoryPtr();
  45. }
  46. FString GetWwiseProjectPath()
  47. {
  48. if (!GetWwiseProjectPathPtr)
  49. {
  50. UE_LOG(LogWwiseUtils, Error, TEXT("WwiseUnrealHelper::GetWwiseProjectPath implementation not set."));
  51. return {};
  52. }
  53. return GetWwiseProjectPathPtr();
  54. }
  55. FString GetSoundBankDirectory()
  56. {
  57. if (!GetSoundBankDirectoryPtr)
  58. {
  59. UE_LOG(LogWwiseUtils, Error, TEXT("WwiseUnrealHelper::GetSoundBankDirectory implementation not set."));
  60. return {};
  61. }
  62. return GetSoundBankDirectoryPtr();
  63. }
  64. FString GetStagePath()
  65. {
  66. if (!GetStagePathPtr)
  67. {
  68. UE_LOG(LogWwiseUtils, Error, TEXT("WwiseUnrealHelper::GetStagePath implementation not set."));
  69. return {};
  70. }
  71. return GetStagePathPtr();
  72. }
  73. void TrimPath(FString& Path)
  74. {
  75. Path.TrimStartAndEndInline();
  76. }
  77. FString GetProjectDirectory()
  78. {
  79. return FPaths::ConvertRelativePathToFull(FPaths::ProjectDir());
  80. }
  81. FString GetContentDirectory()
  82. {
  83. return FPaths::ConvertRelativePathToFull(FPaths::ProjectContentDir());
  84. }
  85. FString GetThirdPartyDirectory()
  86. {
  87. return FPaths::Combine(GetWwisePluginDirectory(), TEXT("ThirdParty"));
  88. }
  89. FString GetExternalSourceDirectory()
  90. {
  91. return FPaths::Combine(GetSoundBankDirectory(), ExternalSourceFolderName);
  92. }
  93. FString GetWwiseProjectDirectoryPath()
  94. {
  95. return FPaths::GetPath(GetWwiseProjectPath()) + TEXT("/");
  96. }
  97. bool MakePathRelativeToWwiseProject(FString& AbsolutePath)
  98. {
  99. auto wwiseProjectRoot = WwiseUnrealHelper::GetWwiseProjectDirectoryPath();
  100. #if PLATFORM_WINDOWS
  101. AbsolutePath.ReplaceInline(TEXT("/"), TEXT("\\"));
  102. wwiseProjectRoot.ReplaceInline(TEXT("/"), TEXT("\\"));
  103. #endif
  104. bool success = FPaths::MakePathRelativeTo(AbsolutePath, *wwiseProjectRoot);
  105. #if PLATFORM_WINDOWS
  106. AbsolutePath.ReplaceInline(TEXT("/"), TEXT("\\"));
  107. #endif
  108. return success;
  109. }
  110. FString GetWwiseSoundBankInfoCachePath()
  111. {
  112. return FPaths::Combine(FPaths::GetPath(GetWwiseProjectPath()), TEXT(".cache"), TEXT("SoundBankInfoCache.dat"));
  113. }
  114. #if WITH_EDITOR
  115. FString GuidToBankName(const FGuid& Guid)
  116. {
  117. if (Guid == InitBankID)
  118. {
  119. return TEXT("Init");
  120. }
  121. return FString(SoundBankNamePrefix) + Guid.ToString(EGuidFormats::Digits);
  122. }
  123. FGuid BankNameToGuid(const FString& BankName)
  124. {
  125. FString copy = BankName;
  126. copy.RemoveFromStart(SoundBankNamePrefix);
  127. FGuid result;
  128. FGuid::ParseExact(copy, EGuidFormats::Digits, result);
  129. return result;
  130. }
  131. FString FormatFolderPath(const FString folderPath)
  132. {
  133. auto path = folderPath.Replace(TEXT("\\"), TEXT("/"));
  134. if (path[0] == '/') {
  135. path.RemoveAt(0);
  136. }
  137. return path;
  138. }
  139. #endif
  140. }