説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

AdsService.cs 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #if SERVICES_SDK_CORE_ENABLED
  2. using System;
  3. using Unity.Services.Core.Editor;
  4. using UnityEditor;
  5. using UnityEditor.Advertisements;
  6. namespace UnityEngine.Advertisements.Editor
  7. {
  8. class AdsService : IEditorGameService
  9. {
  10. public event Action GameIdsUpdated;
  11. public AdsService()
  12. {
  13. ((EditorGameServiceFlagEnabler)Enabler).ServiceFlagRequestComplete += FetchMissingGameIdsIfPossible;
  14. }
  15. void FetchMissingGameIdsIfPossible()
  16. {
  17. if (!AdvertisementSettings.enabled
  18. || string.IsNullOrEmpty(CloudProjectSettings.projectId))
  19. {
  20. return;
  21. }
  22. var iosGameId = AdvertisementSettings.GetGameId(RuntimePlatform.IPhonePlayer);
  23. var androidGameId = AdvertisementSettings.GetGameId(RuntimePlatform.Android);
  24. if (string.IsNullOrEmpty(iosGameId)
  25. || string.IsNullOrEmpty(androidGameId))
  26. {
  27. new RequestGameIds().SendWithRetry(OnRequestGameIdsCompletedSuccess, OnRequestGameIdsCompletedError);
  28. }
  29. }
  30. void OnRequestGameIdsCompletedSuccess(RequestGameIds.Response response)
  31. {
  32. SetGameIds(response);
  33. }
  34. void OnRequestGameIdsCompletedError(Exception exception)
  35. {
  36. Debug.LogException(exception);
  37. }
  38. void SetGameIds(RequestGameIds.Response gameIds)
  39. {
  40. AdvertisementSettings.SetGameId(RuntimePlatform.IPhonePlayer, gameIds.iOSGameKey);
  41. AdvertisementSettings.SetGameId(RuntimePlatform.Android, gameIds.androidGameKey);
  42. GameIdsUpdated?.Invoke();
  43. }
  44. ~AdsService()
  45. {
  46. if (Enabler is EditorGameServiceFlagEnabler adsServiceEnabler)
  47. {
  48. adsServiceEnabler.ServiceFlagRequestComplete -= FetchMissingGameIdsIfPossible;
  49. }
  50. }
  51. public string Name => "Ads";
  52. public IEditorGameServiceIdentifier Identifier => new AdsServiceIdentifier();
  53. public bool RequiresCoppaCompliance => true;
  54. public bool HasDashboard => true;
  55. public string GetFormattedDashboardUrl()
  56. {
  57. #if ENABLE_EDITOR_GAME_SERVICES
  58. return AdsDashboardUrls.GetOverviewUrl();
  59. #else
  60. return string.Empty;
  61. #endif
  62. }
  63. public IEditorGameServiceEnabler Enabler { get; } = new AdsServiceEnabler();
  64. }
  65. }
  66. #endif