using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; namespace Assets.Scripts.UI.Prefab.Login { public static class DayOptions { private static List SetOptions(int day) { var op = new Dropdown.OptionDataList(); for (int m = 1; m <= day; m++) { op.options.Add(new Dropdown.OptionData(m.ToString())); } return op.options; } public static Dictionary> dayOption = new Dictionary>() { {28,SetOptions(28) },{29,SetOptions(29) },{30,SetOptions(30) },{31,SetOptions(31) } }; } public class CountryModel { public string country { get;set; } public string abbreviation { get; set; } public string source { get; set; } } public class LoginRegOptions { public List years; public List months; public List days; public List genders; public List countrys; public List units; public int countryDefaultValue; private List countryList; public LoginRegOptions() { years = new List(); for (int y = 1970; y <= 2021; y++) { years.Add(new Dropdown.OptionData(y.ToString())); } months = new List(); for (int m = 1; m <= 12; m++) { months.Add(new Dropdown.OptionData(m.ToString())); } days = new List(); genders = new List() {new Dropdown.OptionData("Male"), new Dropdown.OptionData("FeMale") }; var countryJson = Resources.Load("UI/flags-mini").text; countryList = JsonConvert.DeserializeObject>(countryJson); countrys = countryList.Select(x => new Dropdown.OptionData(x.country)).ToList(); countryDefaultValue = countryList.FindIndex(x => x.country == "中国"); units = new List() { new Dropdown.OptionData("Metric"), new Dropdown.OptionData("Imperial") }; } public Texture GetCountryImage(int index) { var c = countryList[index]; if (c == null) return null; return Resources.Load(c.source); } public Texture GetCountryImage(string code) { return GetCountryImage(GetCountryIndexByCode(code)); } public int GetCountryIndexByCode(string code) { var c = countryList.FindIndex(x => x.abbreviation.ToLower() == code.ToLower()); if (c == -1) return countryDefaultValue; return c; } public List GetDayOptions(int year,int month) { int day = DateTime.DaysInMonth(year, month); return DayOptions.dayOption[day]; } } }