PageRenderTime 29ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/ville_emergente_4.6.7/Assets/Wwise/Editor/WwiseSetupWizard/AkPluginActivator.cs

https://gitlab.com/NunezG/villeEmergente
C# | 386 lines | 349 code | 26 blank | 11 comment | 58 complexity | fb1b097ae6ee28d0446304fa9a582266 MD5 | raw file
  1. #if UNITY_EDITOR && UNITY_5
  2. using UnityEngine;
  3. using UnityEditor;
  4. using System.Collections.Generic;
  5. using System.Reflection;
  6. using System;
  7. public class AkPluginActivator
  8. {
  9. public const string ALL_PLATFORMS = "All";
  10. public const string CONFIG_DEBUG = "Debug";
  11. public const string CONFIG_PROFILE = "Profile";
  12. public const string CONFIG_RELEASE = "Release";
  13. // Use reflection because projects that were created in Unity 4 won't have the CurrentPluginConfig field
  14. static string GetCurrentConfig()
  15. {
  16. //populate trigger list
  17. FieldInfo CurrentPluginConfigField = typeof(AkWwiseProjectData).GetField("CurrentPluginConfig");
  18. string CurrentConfig = string.Empty;
  19. if( CurrentPluginConfigField != null )
  20. {
  21. CurrentConfig = (string)CurrentPluginConfigField.GetValue(AkWwiseProjectInfo.GetData ());
  22. }
  23. return CurrentConfig;
  24. }
  25. static void SetCurrentConfig(string config)
  26. {
  27. //populate trigger list
  28. FieldInfo CurrentPluginConfigField = typeof(AkWwiseProjectData).GetField("CurrentPluginConfig");
  29. if( CurrentPluginConfigField != null )
  30. {
  31. CurrentPluginConfigField.SetValue(AkWwiseProjectInfo.GetData (), config);
  32. }
  33. }
  34. [MenuItem("Assets/Wwise/Activate Plugins/Debug")]
  35. public static void ActivateDebug()
  36. {
  37. if( GetCurrentConfig() != CONFIG_DEBUG )
  38. {
  39. SetPlugin (ALL_PLATFORMS, GetCurrentConfig(), false);
  40. SetCurrentConfig(CONFIG_DEBUG);
  41. SetPlugin(ALL_PLATFORMS, CONFIG_DEBUG, true);
  42. }
  43. else
  44. {
  45. Debug.Log ("AkSoundEngine Plugins already activated for Debug.");
  46. }
  47. }
  48. [MenuItem("Assets/Wwise/Activate Plugins/Profile")]
  49. public static void ActivateProfile()
  50. {
  51. if( GetCurrentConfig() != CONFIG_PROFILE )
  52. {
  53. SetPlugin (ALL_PLATFORMS, GetCurrentConfig(), false);
  54. SetCurrentConfig(CONFIG_PROFILE);
  55. SetPlugin(ALL_PLATFORMS, CONFIG_PROFILE, true);
  56. }
  57. else
  58. {
  59. Debug.Log ("AkSoundEngine Plugins already activated for Profile.");
  60. }
  61. }
  62. [MenuItem("Assets/Wwise/Activate Plugins/Release")]
  63. public static void ActivateRelease()
  64. {
  65. if( GetCurrentConfig() != CONFIG_RELEASE )
  66. {
  67. SetPlugin (ALL_PLATFORMS, GetCurrentConfig(), false);
  68. SetCurrentConfig(CONFIG_RELEASE);
  69. SetPlugin(ALL_PLATFORMS, CONFIG_RELEASE, true);
  70. }
  71. else
  72. {
  73. Debug.Log ("AkSoundEngine Plugins already activated for Release.");
  74. }
  75. }
  76. public static void RefreshPlugins()
  77. {
  78. SetPlugin (ALL_PLATFORMS, GetCurrentConfig(), true);
  79. }
  80. private static void SetStandaloneTarget(PluginImporter pluginImporter, BuildTarget target)
  81. {
  82. switch(target)
  83. {
  84. case BuildTarget.StandaloneLinux:
  85. pluginImporter.SetPlatformData (BuildTarget.StandaloneLinux, "CPU", "x86");
  86. pluginImporter.SetPlatformData (BuildTarget.StandaloneLinux64, "CPU", "None");
  87. pluginImporter.SetPlatformData (BuildTarget.StandaloneLinuxUniversal, "CPU", "x86");
  88. pluginImporter.SetPlatformData (BuildTarget.StandaloneOSXIntel, "CPU", "None");
  89. pluginImporter.SetPlatformData (BuildTarget.StandaloneOSXIntel64, "CPU", "None");
  90. pluginImporter.SetPlatformData (BuildTarget.StandaloneOSXUniversal, "CPU", "None");
  91. pluginImporter.SetPlatformData (BuildTarget.StandaloneWindows, "CPU", "None");
  92. pluginImporter.SetPlatformData (BuildTarget.StandaloneWindows64, "CPU", "None");
  93. return;
  94. case BuildTarget.StandaloneLinux64:
  95. pluginImporter.SetPlatformData (BuildTarget.StandaloneLinux, "CPU", "None");
  96. pluginImporter.SetPlatformData (BuildTarget.StandaloneLinux64, "CPU", "x86_64");
  97. pluginImporter.SetPlatformData (BuildTarget.StandaloneLinuxUniversal, "CPU", "x86_64");
  98. pluginImporter.SetPlatformData (BuildTarget.StandaloneOSXIntel, "CPU", "None");
  99. pluginImporter.SetPlatformData (BuildTarget.StandaloneOSXIntel64, "CPU", "None");
  100. pluginImporter.SetPlatformData (BuildTarget.StandaloneOSXUniversal, "CPU", "None");
  101. pluginImporter.SetPlatformData (BuildTarget.StandaloneWindows, "CPU", "None");
  102. pluginImporter.SetPlatformData (BuildTarget.StandaloneWindows64, "CPU", "None");
  103. return;
  104. case BuildTarget.StandaloneOSXIntel:
  105. case BuildTarget.StandaloneOSXIntel64:
  106. pluginImporter.SetPlatformData (BuildTarget.StandaloneLinux, "CPU", "None");
  107. pluginImporter.SetPlatformData (BuildTarget.StandaloneLinux64, "CPU", "None");
  108. pluginImporter.SetPlatformData (BuildTarget.StandaloneLinuxUniversal, "CPU", "None");
  109. pluginImporter.SetPlatformData (BuildTarget.StandaloneOSXIntel, "CPU", "AnyCPU");
  110. pluginImporter.SetPlatformData (BuildTarget.StandaloneOSXIntel64, "CPU", "AnyCPU");
  111. pluginImporter.SetPlatformData (BuildTarget.StandaloneOSXUniversal, "CPU", "AnyCPU");
  112. pluginImporter.SetPlatformData (BuildTarget.StandaloneWindows, "CPU", "None");
  113. pluginImporter.SetPlatformData (BuildTarget.StandaloneWindows64, "CPU", "None");
  114. return;
  115. case BuildTarget.StandaloneWindows:
  116. pluginImporter.SetPlatformData (BuildTarget.StandaloneLinux, "CPU", "None");
  117. pluginImporter.SetPlatformData (BuildTarget.StandaloneLinux64, "CPU", "None");
  118. pluginImporter.SetPlatformData (BuildTarget.StandaloneLinuxUniversal, "CPU", "None");
  119. pluginImporter.SetPlatformData (BuildTarget.StandaloneOSXIntel, "CPU", "None");
  120. pluginImporter.SetPlatformData (BuildTarget.StandaloneOSXIntel64, "CPU", "None");
  121. pluginImporter.SetPlatformData (BuildTarget.StandaloneOSXUniversal, "CPU", "None");
  122. pluginImporter.SetPlatformData (BuildTarget.StandaloneWindows, "CPU", "AnyCPU");
  123. pluginImporter.SetPlatformData (BuildTarget.StandaloneWindows64, "CPU", "None");
  124. return;
  125. case BuildTarget.StandaloneWindows64:
  126. pluginImporter.SetPlatformData (BuildTarget.StandaloneLinux, "CPU", "None");
  127. pluginImporter.SetPlatformData (BuildTarget.StandaloneLinux64, "CPU", "None");
  128. pluginImporter.SetPlatformData (BuildTarget.StandaloneLinuxUniversal, "CPU", "None");
  129. pluginImporter.SetPlatformData (BuildTarget.StandaloneOSXIntel, "CPU", "None");
  130. pluginImporter.SetPlatformData (BuildTarget.StandaloneOSXIntel64, "CPU", "None");
  131. pluginImporter.SetPlatformData (BuildTarget.StandaloneOSXUniversal, "CPU", "None");
  132. pluginImporter.SetPlatformData (BuildTarget.StandaloneWindows, "CPU", "None");
  133. pluginImporter.SetPlatformData (BuildTarget.StandaloneWindows64, "CPU", "AnyCPU");
  134. return;
  135. default:
  136. return;
  137. }
  138. }
  139. // Properly set the platforms for Ak plugins. If platformToActivate is set to ALL_PLATFORMS, all platforms
  140. // will be activated.
  141. public static void SetPlugin(string platformToActivate, string configToActivate, bool Activate)
  142. {
  143. PluginImporter[] importers = PluginImporter.GetAllImporters();
  144. bool ChangedSomeAssets = false;
  145. foreach(PluginImporter pluginImporter in importers)
  146. {
  147. if( pluginImporter.assetPath.StartsWith("Assets/Plugins", StringComparison.CurrentCultureIgnoreCase) && pluginImporter.assetPath.Contains("AkSoundEngine") )
  148. {
  149. AssetDatabase.DeleteAsset(pluginImporter.assetPath);
  150. continue;
  151. }
  152. if( !pluginImporter.assetPath.Contains("AkSoundEngine") )
  153. {
  154. continue;
  155. }
  156. // Special case for WP8. Somehow, unity thinks .cpp and .h files are plugins
  157. if( pluginImporter.assetPath.Contains(".h") || pluginImporter.assetPath.Contains(".cpp") )
  158. {
  159. if( pluginImporter.GetCompatibleWithAnyPlatform() )
  160. {
  161. pluginImporter.SetCompatibleWithAnyPlatform(false);
  162. AssetDatabase.ImportAsset(pluginImporter.assetPath);
  163. }
  164. continue;
  165. }
  166. string[] splitPath = pluginImporter.assetPath.Split('/');
  167. // Path is Assets/Wwise/Deployment/Plugins/Platform. We need the platform string
  168. string pluginPlatform = splitPath[4];
  169. if( pluginPlatform != platformToActivate && platformToActivate != ALL_PLATFORMS )
  170. {
  171. continue;
  172. }
  173. // Architecture and configuration (Debug, Profile, Release) are platform-dependent
  174. string pluginArch = string.Empty;
  175. string pluginConfig = string.Empty;
  176. string editorCPU = string.Empty;
  177. string editorOS = string.Empty;
  178. List<BuildTarget> targetsToSet = new List<BuildTarget>();
  179. bool setEditor = false;
  180. switch (pluginPlatform)
  181. {
  182. case "Android":
  183. pluginConfig = splitPath[6];
  184. pluginArch = splitPath[5];
  185. targetsToSet.Add (BuildTarget.Android);
  186. if (pluginArch == "armeabi-v7a")
  187. pluginImporter.SetPlatformData(BuildTarget.Android, "CPU", "ARMv7");
  188. else if (pluginArch == "x86")
  189. pluginImporter.SetPlatformData(BuildTarget.Android, "CPU", "x86");
  190. else
  191. {
  192. Debug.Log("Architecture not found: " + pluginArch);
  193. }
  194. break;
  195. case "iOS":
  196. pluginConfig = splitPath[5];
  197. targetsToSet.Add (BuildTarget.iOS);
  198. break;
  199. case "Linux":
  200. pluginArch = splitPath[5];
  201. pluginConfig = splitPath[6];
  202. if( pluginArch == "x86" )
  203. {
  204. targetsToSet.Add (BuildTarget.StandaloneLinux);
  205. SetStandaloneTarget(pluginImporter, BuildTarget.StandaloneLinux);
  206. }
  207. else if( pluginArch == "x86_64" )
  208. {
  209. targetsToSet.Add (BuildTarget.StandaloneLinux64);
  210. SetStandaloneTarget(pluginImporter, BuildTarget.StandaloneLinux64);
  211. }
  212. else
  213. {
  214. Debug.Log("Architecture not found: " + pluginArch);
  215. }
  216. targetsToSet.Add (BuildTarget.StandaloneLinuxUniversal);
  217. break;
  218. case "Mac":
  219. pluginConfig = splitPath[5];
  220. SetStandaloneTarget(pluginImporter, BuildTarget.StandaloneOSXIntel);
  221. SetStandaloneTarget(pluginImporter, BuildTarget.StandaloneOSXIntel64);
  222. targetsToSet.Add (BuildTarget.StandaloneOSXIntel);
  223. targetsToSet.Add (BuildTarget.StandaloneOSXIntel64);
  224. targetsToSet.Add(BuildTarget.StandaloneOSXUniversal);
  225. editorCPU = "AnyCPU";
  226. editorOS = "OSX";
  227. setEditor = true;
  228. break;
  229. case "Metro":
  230. pluginArch = splitPath[5];
  231. pluginConfig = splitPath[6];
  232. targetsToSet.Add (BuildTarget.WSAPlayer);
  233. if (pluginArch == "Metro_ARM")
  234. {
  235. pluginImporter.SetPlatformData(BuildTarget.WSAPlayer, "SDK", "SDK80");
  236. pluginImporter.SetPlatformData(BuildTarget.WSAPlayer, "CPU", "ARM");
  237. }
  238. else if (pluginArch == "Metro_Win32")
  239. {
  240. pluginImporter.SetPlatformData(BuildTarget.WSAPlayer, "SDK", "SDK80");
  241. pluginImporter.SetPlatformData(BuildTarget.WSAPlayer, "CPU", "X86");
  242. }
  243. else if (pluginArch == "Metro_WindowsPhone81_ARM")
  244. {
  245. pluginImporter.SetPlatformData(BuildTarget.WSAPlayer, "SDK", "PhoneSDK81");
  246. pluginImporter.SetPlatformData(BuildTarget.WSAPlayer, "CPU", "ARM");
  247. }
  248. else if (pluginArch == "Metro_WindowsPhone81_Win32")
  249. {
  250. pluginImporter.SetPlatformData(BuildTarget.WSAPlayer, "SDK", "PhoneSDK81");
  251. pluginImporter.SetPlatformData(BuildTarget.WSAPlayer, "CPU", "X86");
  252. }
  253. break;
  254. case "PS3":
  255. pluginConfig = splitPath[5];
  256. targetsToSet.Add(BuildTarget.PS3);
  257. // Workaround: the PS4 module tags all .prx files as a PS4 plugin. We need to deactivate this.
  258. pluginImporter.SetCompatibleWithPlatform(BuildTarget.PS4, false);
  259. break;
  260. case "PS4":
  261. pluginConfig = splitPath[5];
  262. targetsToSet.Add(BuildTarget.PS4);
  263. break;
  264. case "Vita":
  265. pluginConfig = splitPath[6];
  266. targetsToSet.Add(BuildTarget.PSP2);
  267. break;
  268. case "Windows":
  269. pluginArch = splitPath[5];
  270. pluginConfig = splitPath[6];
  271. if( pluginArch == "x86" )
  272. {
  273. targetsToSet.Add (BuildTarget.StandaloneWindows);
  274. SetStandaloneTarget(pluginImporter, BuildTarget.StandaloneWindows);
  275. editorCPU = "X86";
  276. }
  277. else if( pluginArch == "x86_64" )
  278. {
  279. targetsToSet.Add (BuildTarget.StandaloneWindows64);
  280. SetStandaloneTarget(pluginImporter, BuildTarget.StandaloneWindows64);
  281. editorCPU = "X86_64";
  282. }
  283. else
  284. {
  285. Debug.Log("Architecture not found: " + pluginArch);
  286. }
  287. setEditor = true;
  288. editorOS = "Windows";
  289. break;
  290. case "XBox360":
  291. pluginConfig = splitPath[5];
  292. targetsToSet.Add(BuildTarget.XBOX360);
  293. break;
  294. case "XboxOne":
  295. pluginConfig = splitPath[5];
  296. targetsToSet.Add(BuildTarget.XboxOne);
  297. break;
  298. case "WiiU": // todo: wiiu not in buildtarget...
  299. default:
  300. Debug.Log ("Unknown platform: " + pluginPlatform);
  301. continue;
  302. }
  303. bool AssetChanged = false;
  304. if( pluginImporter.GetCompatibleWithAnyPlatform() )
  305. {
  306. pluginImporter.SetCompatibleWithAnyPlatform(false);
  307. AssetChanged = true;
  308. }
  309. if( pluginConfig != configToActivate )
  310. {
  311. // This is not the configuration we want to activate, make sure it is deactivated
  312. foreach(BuildTarget target in targetsToSet)
  313. {
  314. AssetChanged |= pluginImporter.GetCompatibleWithPlatform(target);
  315. pluginImporter.SetCompatibleWithPlatform(target, false);
  316. }
  317. if( setEditor )
  318. {
  319. AssetChanged |= pluginImporter.GetCompatibleWithEditor();
  320. pluginImporter.SetCompatibleWithEditor(false);
  321. }
  322. }
  323. else
  324. {
  325. // Set this plugin
  326. foreach(BuildTarget target in targetsToSet)
  327. {
  328. AssetChanged |= (pluginImporter.GetCompatibleWithPlatform(target) != Activate);
  329. pluginImporter.SetCompatibleWithPlatform(target, Activate);
  330. }
  331. if( setEditor )
  332. {
  333. AssetChanged |= (pluginImporter.GetCompatibleWithEditor() != Activate);
  334. pluginImporter.SetCompatibleWithEditor(Activate);
  335. pluginImporter.SetEditorData("CPU", editorCPU);
  336. pluginImporter.SetEditorData("OS", editorOS);
  337. }
  338. }
  339. if( AssetChanged )
  340. {
  341. ChangedSomeAssets = true;
  342. AssetDatabase.ImportAsset(pluginImporter.assetPath);
  343. }
  344. }
  345. if( Activate && ChangedSomeAssets )
  346. {
  347. Debug.Log ("AkSoundEngine Plugins successfully activated for " + configToActivate + ".");
  348. }
  349. }
  350. public static void DeactivateAllPlugins()
  351. {
  352. PluginImporter[] importers = PluginImporter.GetAllImporters();
  353. foreach(PluginImporter pluginImporter in importers)
  354. {
  355. pluginImporter.SetCompatibleWithAnyPlatform(false);
  356. AssetDatabase.ImportAsset(pluginImporter.assetPath);
  357. }
  358. }
  359. }
  360. #endif