BuildTargetGroupExtensions.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using UnityEditor;
  6. using UnityEditor.Purchasing;
  7. using UnityEngine;
  8. using UnityEngine.Purchasing;
  9. static class BuildTargetGroupExtensions
  10. {
  11. internal static ReadOnlyCollection<string> ToAppStoreDisplayNames(this BuildTargetGroup value)
  12. {
  13. var stores = value.ToAppStores();
  14. var storeNames = stores.Select(store => store.ToDisplayName()).ToList();
  15. return storeNames.AsReadOnly();
  16. }
  17. internal static ReadOnlyCollection<AppStore> ToAppStores(this BuildTargetGroup value)
  18. {
  19. AppStore[] storesArray;
  20. switch (value)
  21. {
  22. case BuildTargetGroup.Android:
  23. {
  24. storesArray = ToAndroidAppStores(value);
  25. break;
  26. }
  27. case BuildTargetGroup.iOS:
  28. case BuildTargetGroup.tvOS:
  29. storesArray = new[] { AppStore.AppleAppStore };
  30. break;
  31. case BuildTargetGroup.WSA:
  32. storesArray = new[] { AppStore.WinRT };
  33. break;
  34. case BuildTargetGroup.Standalone:
  35. if (Application.platform == RuntimePlatform.OSXEditor)
  36. {
  37. storesArray = new[] { AppStore.MacAppStore };
  38. break;
  39. }
  40. goto default;
  41. default:
  42. storesArray = new[] { AppStore.fake };
  43. break;
  44. }
  45. return Array.AsReadOnly(storesArray);
  46. }
  47. static AppStore[] ToAndroidAppStores(this BuildTargetGroup value)
  48. {
  49. if (value != BuildTargetGroup.Android)
  50. {
  51. return new AppStore[0];
  52. }
  53. var stores = new List<AppStore>();
  54. for (var store = (AppStore)AppStoreMeta.AndroidStoreStart;
  55. store <= (AppStore)AppStoreMeta.AndroidStoreEnd;
  56. ++store)
  57. {
  58. stores.Add(store);
  59. }
  60. return stores.ToArray();
  61. }
  62. internal static string ToPlatformDisplayName(this BuildTargetGroup value)
  63. {
  64. switch (value)
  65. {
  66. case BuildTargetGroup.iOS:
  67. {
  68. // TRICKY: Prefer an "iOS" string on BuildTarget, to avoid the unwanted "BuildTargetGroup.iPhone"
  69. return BuildTarget.iOS.ToString();
  70. }
  71. case BuildTargetGroup.Standalone:
  72. {
  73. switch (EditorUserBuildSettings.activeBuildTarget)
  74. {
  75. case BuildTarget.StandaloneOSX:
  76. return "macOS";
  77. case BuildTarget.StandaloneWindows:
  78. return "Windows";
  79. default:
  80. return BuildTargetGroup.Standalone.ToString();
  81. }
  82. }
  83. default:
  84. return value.ToString();
  85. }
  86. }
  87. }