123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- #if SERVICES_SDK_CORE_ENABLED
- using System.Collections.Generic;
- using Unity.Services.Core.Editor;
- using UnityEditor;
- using UnityEngine.UIElements;
-
- namespace UnityEngine.Advertisements.Editor
- {
- class AdsSettingsProvider : EditorGameServiceSettingsProvider
- {
- VisualElement m_Root;
- GettingStartedUi m_GettingStartedUi;
- GameIdsUi m_GameIdsUi;
- VisualElement m_SupportedPlatformsUi;
-
- bool m_HasLoggedAssetStorePackageInstalled;
-
- public AdsSettingsProvider(SettingsScope scopes, IEnumerable<string> keywords = null)
- : base(GetSettingsPath(), scopes, keywords) {}
-
- [SettingsProvider]
- public static SettingsProvider CreateSettingsProvider()
- {
- #if ENABLE_EDITOR_GAME_SERVICES
- return new AdsSettingsProvider(SettingsScope.Project);
- #else
- return null;
- #endif
- }
-
- internal static string GetSettingsPath()
- {
- return GenerateProjectSettingsPath(new AdsServiceIdentifier().GetKey());
- }
-
- AdsService m_Service = (AdsService)EditorGameServiceRegistry.Instance.GetEditorGameService<AdsServiceIdentifier>();
- protected override IEditorGameService EditorGameService => null;
-
- protected override string Title => UiConstants.LocalizedStrings.Ads;
-
- protected override string Description => UiConstants.LocalizedStrings.Description;
-
- protected override VisualElement GenerateServiceDetailUI()
- {
- m_Root = new VisualElement();
- m_GettingStartedUi = new GettingStartedUi();
- m_GameIdsUi = new GameIdsUi();
- m_SupportedPlatformsUi = PlatformSupportUiHelper.GeneratePlatformSupport(UiConstants.SupportedPlatforms);
-
- SetUpStyles();
-
- RefreshDetailUI();
-
- return m_Root;
- }
-
- void SetUpStyles()
- {
- m_Root.AddToClassList(UiConstants.ClassNames.Ads);
-
- var styleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>(UiConstants.StyleSheetPaths.Common);
- if (!(styleSheet is null))
- {
- m_Root.styleSheets.Add(styleSheet);
- }
- }
-
- void RefreshDetailUI()
- {
- if (m_Root is null)
- {
- return;
- }
-
- m_Root.Clear();
-
- m_Root.Add(m_GettingStartedUi);
- m_Root.Add(m_GameIdsUi);
- m_Root.Add(m_SupportedPlatformsUi);
-
- LogOnceAssetStorePackageInstalled();
-
- TranslateAllLabelsIn(m_Root);
- }
-
- void LogOnceAssetStorePackageInstalled()
- {
- if (m_HasLoggedAssetStorePackageInstalled
- || !PluginUtils.AreAssetStorePluginsInstalled())
- {
- return;
- }
-
- Debug.LogWarning(UiConstants.LocalizedStrings.AssetStorePackageInstalledMessage);
-
- m_HasLoggedAssetStorePackageInstalled = true;
- }
-
- static void TranslateAllLabelsIn(VisualElement root)
- {
- root.Query<TextElement>()
- .ForEach(TranslateLabel);
-
- string TranslateLabel(TextElement label)
- {
- label.text = L10n.Tr(label.text);
-
- return label.text;
- }
- }
-
- public override void OnActivate(string searchContext, VisualElement rootElement)
- {
- base.OnActivate(searchContext, rootElement);
- if (m_Service == null) return;
- m_Service.GameIdsUpdated += OnGameIdsUpdated;
- var serviceEnabler = (AdsServiceEnabler)m_Service.Enabler;
- serviceEnabler.ServiceEnabled += RefreshDetailUI;
- serviceEnabler.ServiceDisabled += RefreshDetailUI;
-
- }
-
- public override void OnDeactivate()
- {
- base.OnDeactivate();
- if (m_Service == null) return;
- m_Service.GameIdsUpdated -= OnGameIdsUpdated;
-
- var serviceEnabler = (AdsServiceEnabler)m_Service.Enabler;
- serviceEnabler.ServiceEnabled -= RefreshDetailUI;
- serviceEnabler.ServiceDisabled -= RefreshDetailUI;
- }
-
- void OnGameIdsUpdated()
- {
- if (m_GameIdsUi is null)
- {
- return;
- }
-
- m_GameIdsUi.RefreshGameIds();
-
- Repaint();
- }
- }
- }
- #endif
|