Açıklama Yok
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AdsSettingsProvider.cs 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #if SERVICES_SDK_CORE_ENABLED
  2. using System.Collections.Generic;
  3. using Unity.Services.Core.Editor;
  4. using UnityEditor;
  5. using UnityEngine.UIElements;
  6. namespace UnityEngine.Advertisements.Editor
  7. {
  8. class AdsSettingsProvider : EditorGameServiceSettingsProvider
  9. {
  10. VisualElement m_Root;
  11. GettingStartedUi m_GettingStartedUi;
  12. GameIdsUi m_GameIdsUi;
  13. VisualElement m_SupportedPlatformsUi;
  14. bool m_HasLoggedAssetStorePackageInstalled;
  15. public AdsSettingsProvider(SettingsScope scopes, IEnumerable<string> keywords = null)
  16. : base(GetSettingsPath(), scopes, keywords) {}
  17. [SettingsProvider]
  18. public static SettingsProvider CreateSettingsProvider()
  19. {
  20. #if ENABLE_EDITOR_GAME_SERVICES
  21. return new AdsSettingsProvider(SettingsScope.Project);
  22. #else
  23. return null;
  24. #endif
  25. }
  26. internal static string GetSettingsPath()
  27. {
  28. return GenerateProjectSettingsPath(new AdsServiceIdentifier().GetKey());
  29. }
  30. AdsService m_Service = (AdsService)EditorGameServiceRegistry.Instance.GetEditorGameService<AdsServiceIdentifier>();
  31. protected override IEditorGameService EditorGameService => null;
  32. protected override string Title => UiConstants.LocalizedStrings.Ads;
  33. protected override string Description => UiConstants.LocalizedStrings.Description;
  34. protected override VisualElement GenerateServiceDetailUI()
  35. {
  36. m_Root = new VisualElement();
  37. m_GettingStartedUi = new GettingStartedUi();
  38. m_GameIdsUi = new GameIdsUi();
  39. m_SupportedPlatformsUi = PlatformSupportUiHelper.GeneratePlatformSupport(UiConstants.SupportedPlatforms);
  40. SetUpStyles();
  41. RefreshDetailUI();
  42. return m_Root;
  43. }
  44. void SetUpStyles()
  45. {
  46. m_Root.AddToClassList(UiConstants.ClassNames.Ads);
  47. var styleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>(UiConstants.StyleSheetPaths.Common);
  48. if (!(styleSheet is null))
  49. {
  50. m_Root.styleSheets.Add(styleSheet);
  51. }
  52. }
  53. void RefreshDetailUI()
  54. {
  55. if (m_Root is null)
  56. {
  57. return;
  58. }
  59. m_Root.Clear();
  60. m_Root.Add(m_GettingStartedUi);
  61. m_Root.Add(m_GameIdsUi);
  62. m_Root.Add(m_SupportedPlatformsUi);
  63. LogOnceAssetStorePackageInstalled();
  64. TranslateAllLabelsIn(m_Root);
  65. }
  66. void LogOnceAssetStorePackageInstalled()
  67. {
  68. if (m_HasLoggedAssetStorePackageInstalled
  69. || !PluginUtils.AreAssetStorePluginsInstalled())
  70. {
  71. return;
  72. }
  73. Debug.LogWarning(UiConstants.LocalizedStrings.AssetStorePackageInstalledMessage);
  74. m_HasLoggedAssetStorePackageInstalled = true;
  75. }
  76. static void TranslateAllLabelsIn(VisualElement root)
  77. {
  78. root.Query<TextElement>()
  79. .ForEach(TranslateLabel);
  80. string TranslateLabel(TextElement label)
  81. {
  82. label.text = L10n.Tr(label.text);
  83. return label.text;
  84. }
  85. }
  86. public override void OnActivate(string searchContext, VisualElement rootElement)
  87. {
  88. base.OnActivate(searchContext, rootElement);
  89. if (m_Service == null) return;
  90. m_Service.GameIdsUpdated += OnGameIdsUpdated;
  91. var serviceEnabler = (AdsServiceEnabler)m_Service.Enabler;
  92. serviceEnabler.ServiceEnabled += RefreshDetailUI;
  93. serviceEnabler.ServiceDisabled += RefreshDetailUI;
  94. }
  95. public override void OnDeactivate()
  96. {
  97. base.OnDeactivate();
  98. if (m_Service == null) return;
  99. m_Service.GameIdsUpdated -= OnGameIdsUpdated;
  100. var serviceEnabler = (AdsServiceEnabler)m_Service.Enabler;
  101. serviceEnabler.ServiceEnabled -= RefreshDetailUI;
  102. serviceEnabler.ServiceDisabled -= RefreshDetailUI;
  103. }
  104. void OnGameIdsUpdated()
  105. {
  106. if (m_GameIdsUi is null)
  107. {
  108. return;
  109. }
  110. m_GameIdsUi.RefreshGameIds();
  111. Repaint();
  112. }
  113. }
  114. }
  115. #endif