PageRenderTime 26ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/ville_emergente_4.6.7/Assets/Wwise/Deployment/Components/AkBankPathUtil.cs

https://gitlab.com/NunezG/villeEmergente
C# | 226 lines | 179 code | 22 blank | 25 comment | 17 complexity | fef33d0e9566c612604321c8dc6e2f8c MD5 | raw file
  1. #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
  2. //////////////////////////////////////////////////////////////////////
  3. //
  4. // Copyright (c) 2012 Audiokinetic Inc. / All Rights Reserved
  5. //
  6. //////////////////////////////////////////////////////////////////////
  7. using UnityEngine;
  8. using System.Collections.Generic;
  9. using System.IO;
  10. /// @brief This class is used for returning correct path strings for retrieving the soundbank file locations.
  11. /// The class makes path string retrieval transparent for all platforms in all contexts. Clients of the class
  12. /// only needs to use the public methods to get physically correct path strings after setting flag isToUsePosixPathSeparator. By default, the flag is turned off for non-buildPipeline usecases.
  13. ///
  14. /// Unity usecases:
  15. /// - A BuildPipeline user context uses POSIX path convention for all platforms, including Windows and Xbox360.
  16. /// - Other usecases (runtime) use platform-specific path conventions.
  17. public class AkBankPathUtil
  18. {
  19. private static string defaultBasePath = Path.Combine("Audio", "GeneratedSoundBanks"); //Default value. Will be overwritten by the user.
  20. private static bool isToUsePosixPathSeparator = false;
  21. private static bool isToAppendTrailingPathSeparator = true;
  22. static AkBankPathUtil ()
  23. {
  24. isToUsePosixPathSeparator = false;
  25. }
  26. /// Call to force usage of POSIX path format.
  27. public static void UsePosixPath() { isToUsePosixPathSeparator = true; }
  28. /// Call to use platform-specific path format
  29. public static void UsePlatformSpecificPath() { isToUsePosixPathSeparator = false; }
  30. public static void SetToAppendTrailingPathSeparator(bool add) { isToAppendTrailingPathSeparator = add; }
  31. #if !UNITY_METRO
  32. public static bool Exists(string path)
  33. {
  34. return Directory.Exists(path);
  35. }
  36. #endif // #if !UNITY_METRO
  37. /// Returns the default path for banks
  38. public static string GetDefaultPath() { return defaultBasePath; }
  39. /// Returns the bank path, depending on the settings of AkInitializer, without platform-specific folder, in the proper path format.
  40. public static string GetFullBasePath()
  41. {
  42. // Get full path of base path
  43. #if UNITY_ANDROID && ! UNITY_EDITOR
  44. // Wwise Android SDK now loads SoundBanks from APKs.
  45. #if AK_LOAD_BANK_IN_MEMORY
  46. string fullBasePath = Path.Combine(Application.streamingAssetsPath, AkInitializer.GetBasePath());
  47. #else
  48. string fullBasePath = AkInitializer.GetBasePath();
  49. #endif // #if AK_LOAD_BANK_IN_MEMORY
  50. #else
  51. string fullBasePath = Path.Combine(Application.streamingAssetsPath, AkInitializer.GetBasePath());
  52. #endif
  53. LazyAppendTrailingSeparator(ref fullBasePath);
  54. LazyConvertPathConvention(ref fullBasePath);
  55. return fullBasePath;
  56. }
  57. /// Returns the bank path, depending on the settings of AkInitializer, in the proper path format.
  58. public static string GetPlatformBasePath()
  59. {
  60. string platformBasePath = string.Empty;
  61. #if UNITY_EDITOR
  62. platformBasePath = GetPlatformBasePathEditor();
  63. if( !string.IsNullOrEmpty(platformBasePath) )
  64. {
  65. return platformBasePath;
  66. }
  67. #endif
  68. // Combine base path with platform sub-folder
  69. platformBasePath = Path.Combine(GetFullBasePath(), GetPlatformSubDirectory());
  70. LazyAppendTrailingSeparator(ref platformBasePath);
  71. LazyConvertPathConvention(ref platformBasePath);
  72. return platformBasePath;
  73. }
  74. #if UNITY_EDITOR
  75. public static string GetPlatformBasePathEditor()
  76. {
  77. try
  78. {
  79. WwiseSettings Settings = WwiseSettings.LoadSettings();
  80. string platformSubDir = Path.DirectorySeparatorChar == '/' ? "Mac" : "Windows";
  81. string WwiseProjectFullPath = AkUtilities.GetFullPath(Application.dataPath, Settings.WwiseProjectPath);
  82. string SoundBankDest = AkUtilities.GetWwiseSoundBankDestinationFolder(platformSubDir, WwiseProjectFullPath);
  83. if( Path.GetPathRoot(SoundBankDest) == "" )
  84. {
  85. // Path is relative, make it full
  86. SoundBankDest = AkUtilities.GetFullPath(Path.GetDirectoryName(WwiseProjectFullPath), SoundBankDest);
  87. }
  88. // Verify if there are banks in there
  89. DirectoryInfo di = new DirectoryInfo(SoundBankDest);
  90. FileInfo[] foundBanks = di.GetFiles ("*.bnk", SearchOption.AllDirectories);
  91. if( foundBanks.Length == 0 )
  92. {
  93. SoundBankDest = string.Empty;
  94. }
  95. return SoundBankDest;
  96. }
  97. catch
  98. {
  99. return string.Empty;
  100. }
  101. }
  102. #endif
  103. /// Returns the bank subdirectory of the current platform
  104. static public string GetPlatformSubDirectory()
  105. {
  106. string platformSubDir = "Undefined platform sub-folder";
  107. #if UNITY_EDITOR_WIN
  108. // NOTE: Due to a Unity3.5 bug, projects upgraded from 3.4 will have malfunctioning platform preprocessors
  109. // We have to use Path.DirectorySeparatorChar to know if we are in the Unity Editor for Windows or Mac.
  110. platformSubDir = "Windows";
  111. #elif UNITY_EDITOR_OSX
  112. platformSubDir = "Mac";
  113. #elif UNITY_STANDALONE_WIN
  114. platformSubDir = Path.DirectorySeparatorChar == '/' ? "Mac" : "Windows";
  115. #elif UNITY_STANDALONE_LINUX
  116. platformSubDir = "Linux";
  117. #elif UNITY_STANDALONE_OSX
  118. platformSubDir = Path.DirectorySeparatorChar == '/' ? "Mac" : "Windows";
  119. #elif UNITY_XBOX360
  120. platformSubDir = "XBox360";
  121. #elif UNITY_XBOXONE
  122. platformSubDir = "XBoxOne";
  123. #elif UNITY_IOS
  124. platformSubDir = "iOS";
  125. #elif UNITY_ANDROID
  126. platformSubDir = "Android";
  127. #elif UNITY_PS3
  128. platformSubDir = "PS3";
  129. #elif UNITY_PS4
  130. platformSubDir = "PS4";
  131. #elif UNITY_WP_8_1
  132. platformSubDir = "WindowsPhone";
  133. #elif UNITY_METRO
  134. platformSubDir = "Windows";
  135. #elif UNITY_WIIU
  136. platformSubDir = "WiiUSW";
  137. #elif UNITY_WP8
  138. platformSubDir = "WindowsPhone";
  139. #elif UNITY_PSP2
  140. #if AK_ARCH_VITA_SW
  141. platformSubDir = "VitaSW";
  142. #elif AK_ARCH_VITA_HW
  143. platformSubDir = "VitaHW";
  144. #else
  145. platformSubDir = "VitaSW";
  146. #endif
  147. #endif
  148. return platformSubDir;
  149. }
  150. public static void LazyConvertPathConvention(ref string path)
  151. {
  152. if (isToUsePosixPathSeparator)
  153. ConvertToPosixPath(ref path);
  154. else
  155. {
  156. #if !UNITY_METRO
  157. if (Path.DirectorySeparatorChar == '/')
  158. ConvertToPosixPath(ref path);
  159. else
  160. ConvertToWindowsPath(ref path);
  161. #else
  162. ConvertToWindowsPath(ref path);
  163. #endif // #if !UNITY_METRO
  164. }
  165. }
  166. public static void ConvertToWindowsPath(ref string path)
  167. {
  168. path.Trim();
  169. path = path.Replace("/", "\\");
  170. path = path.TrimStart('\\');
  171. }
  172. public static void ConvertToWindowsCommandPath(ref string path)
  173. {
  174. path.Trim();
  175. path = path.Replace("/", "\\\\");
  176. path = path.Replace("\\", "\\\\");
  177. path = path.TrimStart('\\');
  178. }
  179. public static void ConvertToPosixPath(ref string path)
  180. {
  181. path.Trim();
  182. path = path.Replace("\\", "/");
  183. path = path.TrimStart('\\');
  184. }
  185. public static void LazyAppendTrailingSeparator(ref string path)
  186. {
  187. if ( ! isToAppendTrailingPathSeparator )
  188. return;
  189. #if !UNITY_METRO
  190. if ( ! path.EndsWith(Path.DirectorySeparatorChar.ToString()) )
  191. {
  192. path += Path.DirectorySeparatorChar;
  193. }
  194. #else
  195. if ( ! path.EndsWith("\\") )
  196. {
  197. path += "\\";
  198. }
  199. #endif // #if !UNITY_METRO
  200. }
  201. }
  202. #endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.