AkUEPlatform.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 "Platforms/AkUEPlatform.h"
  16. #include "AkAudioDevice.h"
  17. #include "Interfaces/IProjectManager.h"
  18. #include "ProjectDescriptor.h"
  19. #if WITH_EDITOR
  20. #include "PlatformInfo.h"
  21. #include "Platforms/AkPlatformInfo.h"
  22. TMap<FString, UAkPlatformInfo*> UAkPlatformInfo::UnrealNameToPlatformInfo;
  23. TMap<FString, FWwiseSharedPlatformId> UAkPlatformInfo::UnrealTargetNameToSharedPlatformId;
  24. TSet<FString> AkUnrealPlatformHelper::GetAllSupportedUnrealPlatforms()
  25. {
  26. TSet<FString> SupportedPlatforms;
  27. #if UE_5_0_OR_LATER
  28. for (const PlatformInfo::FTargetPlatformInfo* TargetPlatformInfo : PlatformInfo::GetPlatformInfoArray())
  29. {
  30. auto Info = *TargetPlatformInfo;
  31. FName PlatformInfoName = Info.Name;
  32. FString VanillaName = Info.VanillaInfo->Name.ToString();
  33. #else
  34. for (const PlatformInfo::FPlatformInfo& Info : PlatformInfo::GetPlatformInfoArray())
  35. {
  36. FName PlatformInfoName = Info.PlatformInfoName;
  37. FString VanillaName = Info.VanillaPlatformName.ToString();
  38. #endif
  39. bool bIsGame = Info.PlatformType == EBuildTargetType::Game;
  40. if (Info.IsVanilla() && bIsGame && (PlatformInfoName != TEXT("AllDesktop")))
  41. {
  42. VanillaName.RemoveFromEnd(TEXT("NoEditor"));
  43. SupportedPlatforms.Add(VanillaName);
  44. }
  45. }
  46. return SupportedPlatforms;
  47. }
  48. TSet<FString> AkUnrealPlatformHelper::GetAllSupportedUnrealPlatformsForProject()
  49. {
  50. TSet<FString> SupportedPlatforms = GetAllSupportedUnrealPlatforms();
  51. IProjectManager& ProjectManager = IProjectManager::Get();
  52. auto* CurrentProject = ProjectManager.GetCurrentProject();
  53. if (CurrentProject && CurrentProject->TargetPlatforms.Num() > 0)
  54. {
  55. auto& TargetPlatforms = CurrentProject->TargetPlatforms;
  56. TSet<FString> AvailablePlatforms;
  57. for (const auto& TargetPlatform : TargetPlatforms)
  58. {
  59. FString PlatformName = TargetPlatform.ToString();
  60. PlatformName.RemoveFromEnd(TEXT("NoEditor"));
  61. AvailablePlatforms.Add(PlatformName);
  62. }
  63. auto Intersection = SupportedPlatforms.Intersect(AvailablePlatforms);
  64. if (Intersection.Num() > 0)
  65. {
  66. SupportedPlatforms = Intersection;
  67. }
  68. }
  69. return SupportedPlatforms;
  70. }
  71. TArray<TSharedPtr<FString>> AkUnrealPlatformHelper::GetAllSupportedWwisePlatforms(bool ProjectScope /* = false */)
  72. {
  73. TArray<TSharedPtr<FString>> WwisePlatforms;
  74. TSet<FString> TemporaryWwisePlatformNames;
  75. auto UnrealPlatforms = ProjectScope ? GetAllSupportedUnrealPlatformsForProject() : GetAllSupportedUnrealPlatforms();
  76. for (const auto& AvailablePlatform : UnrealPlatforms)
  77. {
  78. FString SettingsClassName = FString::Format(TEXT("Ak{0}InitializationSettings"), { *AvailablePlatform });
  79. #if UE_5_1_OR_LATER
  80. SettingsClassName = "/Script/AkAudio." + SettingsClassName;
  81. if (UClass::TryFindTypeSlow<UClass>(*SettingsClassName))
  82. #else
  83. if (FindObject<UClass>(ANY_PACKAGE, *SettingsClassName))
  84. #endif
  85. {
  86. TemporaryWwisePlatformNames.Add(AvailablePlatform);
  87. }
  88. }
  89. TemporaryWwisePlatformNames.Sort([](const FString& L, const FString& R) { return L.Compare(R) < 0; });
  90. for (const auto& WwisePlatformName : TemporaryWwisePlatformNames)
  91. {
  92. WwisePlatforms.Add(TSharedPtr<FString>(new FString(WwisePlatformName)));
  93. }
  94. return WwisePlatforms;
  95. }
  96. bool AkUnrealPlatformHelper::IsEditorPlatform(FString Platform)
  97. {
  98. return Platform == "Windows" || Platform == "Mac" || Platform == "Linux";
  99. }
  100. #endif // WITH_EDITOR