PlatformUtils.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // <copyright file="PlayGamesHelperObject.cs" company="Google Inc.">
  2. // Copyright (C) 2014 Google Inc.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. // </copyright>
  16. #if (UNITY_ANDROID || (UNITY_IPHONE && !NO_GPGS))
  17. namespace GooglePlayGames.OurUtils
  18. {
  19. using UnityEngine;
  20. using System;
  21. public static class PlatformUtils
  22. {
  23. /// <summary>
  24. /// Check if the Google Play Games platform is supported at runtime.
  25. /// </summary>
  26. /// <value>If the platform is supported.</value>
  27. public static bool Supported
  28. {
  29. get
  30. {
  31. #if UNITY_EDITOR
  32. return false;
  33. #elif UNITY_IOS
  34. return true;
  35. #else
  36. var up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
  37. var ca = up.GetStatic<AndroidJavaObject>("currentActivity");
  38. var packageManager = ca.Call<AndroidJavaObject>("getPackageManager");
  39. AndroidJavaObject launchIntent = null;
  40. //if the app is installed, no errors. Else, doesn't get past next line
  41. try
  42. {
  43. launchIntent = packageManager.Call<AndroidJavaObject>("getLaunchIntentForPackage", "com.google.android.play.games");
  44. }
  45. catch (Exception)
  46. {
  47. return false;
  48. }
  49. return launchIntent != null;
  50. #endif
  51. }
  52. }
  53. }
  54. }
  55. #endif