NearbyConnectionClientFactory.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // <copyright file="NearbyConnectionClientFactory.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. // Android only feature
  17. #if (UNITY_ANDROID)
  18. namespace GooglePlayGames
  19. {
  20. using UnityEngine;
  21. using System;
  22. using GooglePlayGames.OurUtils;
  23. using GooglePlayGames.BasicApi.Nearby;
  24. using S = GooglePlayGames.Native.Cwrapper.NearbyConnectionsStatus;
  25. public static class NearbyConnectionClientFactory
  26. {
  27. public static void Create(Action<INearbyConnectionClient> callback)
  28. {
  29. if (Application.isEditor)
  30. {
  31. GooglePlayGames.OurUtils.Logger.d("Creating INearbyConnection in editor, using DummyClient.");
  32. callback.Invoke(new GooglePlayGames.BasicApi.Nearby.DummyNearbyConnectionClient());
  33. }
  34. #if (UNITY_ANDROID)
  35. GooglePlayGames.OurUtils.Logger.d("Creating real INearbyConnectionClient");
  36. GooglePlayGames.Native.NativeNearbyConnectionClientFactory.Create(callback);
  37. #elif (UNITY_IPHONE && !NO_GPGS)
  38. GooglePlayGames.OurUtils.Logger.e("Nearby connections not supported in iOS... Using Dummy client");
  39. callback.Invoke(new GooglePlayGames.BasicApi.Nearby.DummyNearbyConnectionClient());
  40. #else
  41. GooglePlayGames.OurUtils.Logger.e("Cannot create IPlayGamesClient for unknown platform, returning DummyClient");
  42. return new GooglePlayGames.BasicApi.DummyClient();
  43. #endif
  44. }
  45. private static InitializationStatus ToStatus(S.InitializationStatus status)
  46. {
  47. switch (status)
  48. {
  49. case S.InitializationStatus.VALID:
  50. return InitializationStatus.Success;
  51. case S.InitializationStatus.ERROR_INTERNAL:
  52. return InitializationStatus.InternalError;
  53. case S.InitializationStatus.ERROR_VERSION_UPDATE_REQUIRED:
  54. return InitializationStatus.VersionUpdateRequired;
  55. default:
  56. GooglePlayGames.OurUtils.Logger.w("Unknown initialization status: " + status);
  57. return InitializationStatus.InternalError;
  58. }
  59. }
  60. }
  61. }
  62. #endif