using System; using System.Linq; using Crowdin.Plugin.Helpers.PluginLocalization; using Crowdin.Plugin.Models; using Crowdin.Plugin.Server_API.Helpers; using Plugin.Server_API.Helpers; using UnityEditor; using UnityEngine; namespace Crowdin.Editor { public class UpdateOptionSelector : IDisposable { private int currentIndex; public string SelectedApiKey => UpdateOptionsHelper.Options[currentIndex].ApiKey; public void DrawLayout() { GUILayout.BeginHorizontal("box"); GUILayout.Label(LocalizationHelper.GetLocalStringByKey(LocalKeys.update_option_selector)); currentIndex = EditorGUILayout.Popup(currentIndex, UpdateOptionsHelper.Options.Select(option => option.Description).ToArray()); GUILayout.EndHorizontal(); } public static UpdateOptionSelector CreateAndLoadSettings() { return new UpdateOptionSelector(SettingsHelper.GetUpdateOptionIndex()); } private UpdateOptionSelector(int currentIndex) { this.currentIndex = currentIndex; } public void SaveSettings() { SettingsHelper.SetUpdateOptionIndex(currentIndex); AssetDatabase.Refresh(); AssetDatabase.SaveAssets(); } public void Dispose() { SaveSettings(); } } }