Runtime.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using UnityEngine;
  2. namespace Unity.Services.Analytics.Platform
  3. {
  4. // Keep the enum values in Caps!
  5. // We stringify the values.
  6. // This enum is defined for all Std events.
  7. // http://go/ihu2c
  8. // JIRA-193 Talk to Jetpack about this.
  9. // Likely this can be compile time to some degree.
  10. // https://docs.unity3d.com/ScriptReference/RuntimePlatform.html
  11. // https://docs.unity3d.com/Manual/PlatformDependentCompilation.html
  12. enum UA2PlatformCode
  13. {
  14. UNKNOWN,
  15. IOS, IOS_MOBILE, IOS_TABLET, IOS_TV,
  16. ANDROID, ANDROID_MOBILE, ANDROID_CONSOLE,
  17. WINDOWS_MOBILE, WINDOWS_TABLET,
  18. BLACKBERRY_MOBILE, BLACKBERRY_TABLET,
  19. FACEBOOK, AMAZON,
  20. WEB,
  21. PC_CLIENT, MAC_CLIENT,
  22. PS3, PS4, PSVITA,
  23. XBOX360, XBOXONE,
  24. WIIU, SWITCH,
  25. }
  26. public static class Runtime
  27. {
  28. /// <summary>
  29. /// Returns the name of the platform this app is running on.
  30. /// </summary>
  31. public static string Name()
  32. {
  33. return GetPlatform().ToString();
  34. }
  35. static UA2PlatformCode GetPlatform()
  36. {
  37. // NOTE: Assumes we're only supporting Unity LTS
  38. switch (Application.platform)
  39. {
  40. case RuntimePlatform.OSXEditor:
  41. case RuntimePlatform.OSXPlayer:
  42. return UA2PlatformCode.MAC_CLIENT;
  43. case RuntimePlatform.WindowsEditor:
  44. case RuntimePlatform.WindowsPlayer:
  45. case RuntimePlatform.LinuxEditor:
  46. case RuntimePlatform.LinuxPlayer:
  47. return UA2PlatformCode.PC_CLIENT;
  48. case RuntimePlatform.IPhonePlayer:
  49. return UA2PlatformCode.IOS;
  50. case RuntimePlatform.Android:
  51. return UA2PlatformCode.ANDROID;
  52. case RuntimePlatform.WebGLPlayer:
  53. return UA2PlatformCode.WEB;
  54. case RuntimePlatform.WSAPlayerX64:
  55. case RuntimePlatform.WSAPlayerX86:
  56. case RuntimePlatform.WSAPlayerARM:
  57. return (SystemInfo.deviceType == DeviceType.Handheld)
  58. ? UA2PlatformCode.WINDOWS_MOBILE
  59. : UA2PlatformCode.PC_CLIENT;
  60. case RuntimePlatform.PS4:
  61. return UA2PlatformCode.PS4;
  62. case RuntimePlatform.XboxOne:
  63. return UA2PlatformCode.XBOXONE;
  64. case RuntimePlatform.tvOS:
  65. return UA2PlatformCode.IOS_TV;
  66. case RuntimePlatform.Switch:
  67. return UA2PlatformCode.SWITCH;
  68. default:
  69. return UA2PlatformCode.UNKNOWN;
  70. }
  71. }
  72. }
  73. }