using System; using System.Collections.Generic; using Unity.Services.Authentication.Editor.Models; using Unity.Services.Core; using UnityEditor; using UnityEditor.UIElements; using UnityEngine; using UnityEngine.UIElements; namespace Unity.Services.Authentication.Editor { class AuthenticationSettingsElement : VisualElement { const string k_Uxml = "Packages/com.unity.services.authentication/Editor/UXML/AuthenticationProjectSettings.uxml"; const string k_Uss = "Packages/com.unity.services.authentication/Editor/USS/AuthenticationStyleSheet.uss"; IAuthenticationAdminClient m_AdminClient; string m_ProjectId; string m_IdDomainId; // Whether skip the confirmation window for tests/automation. bool m_SkipConfirmation; TextElement m_WaitingTextElement; TextElement m_ErrorTextElement; VisualElement m_AddIdProviderContainer; List m_AddIdProviderTypeChoices; PopupField m_AddIdProviderType; Button m_RefreshButton; Button m_AddButton; VisualElement m_IdProviderListContainer; /// /// The text to show when the settings is waitng for an async operation to finish. /// public TextElement WaitingTextElement => m_WaitingTextElement; /// /// The text to show when there is an error. /// public TextElement ErrorTextElement => m_ErrorTextElement; /// /// The add ID provider choices in the dropdown list. /// public IEnumerable AddIdProviderTypeChoices => m_AddIdProviderTypeChoices; /// /// The add ID provider dropdown list. /// public PopupField AddIdProviderType => m_AddIdProviderType; /// /// The button to refresh the ID provider list. /// public Button RefreshButton => m_RefreshButton; /// /// The button to add a new ID provider. /// public Button AddButton => m_AddButton; /// /// The container to add ID providers. /// public VisualElement IdProviderListContainer => m_IdProviderListContainer; /// /// Event triggered when the starts or finishes waiting for an async operation. /// The first parameter of the callback is the sender. /// The second parameter is true if it starts waiting, and false if it finishes waiting. /// public event Action Waiting; public AuthenticationSettingsElement(IAuthenticationAdminClient adminClient, string projectId, bool skipConfirmation = false) { m_AdminClient = adminClient; m_ProjectId = projectId; m_SkipConfirmation = skipConfirmation; var containerAsset = AssetDatabase.LoadAssetAtPath(k_Uxml); if (containerAsset != null) { var containerUI = containerAsset.CloneTree().contentContainer; var styleSheet = AssetDatabase.LoadAssetAtPath(k_Uss); if (styleSheet != null) { containerUI.styleSheets.Add(styleSheet); } else { throw new Exception("Asset not found: " + k_Uss); } m_WaitingTextElement = containerUI.Q(className: "auth-progress"); m_ErrorTextElement = containerUI.Q(className: "auth-error"); m_RefreshButton = containerUI.Q