using System; using System.Collections.Generic; using Unity.Services.Mediation.Dashboard.Editor; using Unity.Services.Mediation.Settings.Editor.Layout; using UnityEditor; using UnityEditor.UIElements; using UnityEngine.UIElements; namespace Unity.Services.Mediation.Settings.Editor { /// /// Window listing the available Ad Units defined in the dashboard and their infos for the user's convenience /// class MediationAdUnitsWindow : EditorWindow { public static List AdUnitData => FilteredAdUnitData ?? AdUnitDataSource; static List AdUnitDataSource = new List(); static List FilteredAdUnitData; static SortMode[] SortModes = {SortMode.Ascending, SortMode.Ascending, SortMode.Ascending, SortMode.Ascending}; const string k_AdUnitsTemplate = @"Packages/com.unity.services.mediation/Editor/Settings/Layout/AdUnitsTemplate.uxml"; const string k_AdUnitsStyle = @"Packages/com.unity.services.mediation/Editor/Settings/Layout/AdUnitsStyle.uss"; const string k_AdUnitsWarningTemplate = @"Packages/com.unity.services.mediation/Editor/Settings/Layout/AdUnitsWarningTemplate.uxml"; const string k_AdUnitsErrorTemplate = @"Packages/com.unity.services.mediation/Editor/Settings/Layout/AdUnitsErrorTemplate.uxml"; [MenuItem("Services/" + MediationServiceIdentifier.k_PackageDisplayName + "/Ad Units", priority = 111)] public static void ShowWindow() { EditorGameServiceAnalyticsSender.SendTopMenuAdUnitsEvent(); GetWindow($"{MediationServiceIdentifier.k_PackageDisplayName} - Ad Units", new Type[] { typeof(MediationCodeGeneratorWindow), typeof(SceneView), typeof(EditorWindow)}); } void OnFocus() { if (rootVisualElement.Q(className: "list-view") != null) { RetrieveAdUnitInfo(rootVisualElement); } else { RefreshWindow(); } } void RefreshWindow() { rootVisualElement.Clear(); AdUnitVisualElement.Initialize(); VisualElement root = rootVisualElement; AddStyleSheets(root); VisualTreeAsset adUnitTemplateAsset = AssetDatabase.LoadAssetAtPath(k_AdUnitsTemplate); adUnitTemplateAsset.CloneTree(root); RetrieveAdUnitInfo(root); } void RetrieveAdUnitInfo(VisualElement root) { DashboardClient.GetAdUnitsAsync(adUnits => { // Remove Loading Element root.Q