using UnityEngine; using System.Collections; using AX.TrackRecord; using UnityEngine.UI; using DevelopEngine; using AX.MessageSystem; public class WeatherManager : SingletonMono { public Transform WeatherImage; private WeatherAttribute weatherAttri; public WeatherAttribute WeatherAttribute { set { weatherAttri = value; SetWeatherSprite(weatherAttri.TheWeathertext); transform.Find("FengXiangText").GetComponent().text = weatherAttri.TheWindDirection; transform.Find("TemperatureText").GetComponent().text = weatherAttri.TheTemperature + "℃"; transform.Find("FengLiText").GetComponent().text = weatherAttri.TheWindPower; //温度赋值 InputField text = WeatherImage.Find("InputField").GetComponent(); text.text = weatherAttri.TheTemperature.ToString(); //天气赋值 Dropdown WeatherDropdown = WeatherImage.Find("WeatherDropdown").GetComponent(); //WeatherDropdown.GetComponent().SetAttri(); WeatherDropdown.value = GetID(WeatherDropdown, weatherAttri.TheWeathertext); WeatherDropdown.captionText.text = WeatherDropdown.options[WeatherDropdown.value].text; TOD_WeatherManager.Instance.SetWeather(WeatherDropdown.captionText.text); //风向赋值 Dropdown FengXiangDropdown = WeatherImage.Find("FengXiangDropdown").GetComponent(); //FengXiangDropdown.GetComponent().SetAttri(); FengXiangDropdown.value = GetID(FengXiangDropdown, weatherAttri.TheWindDirection); FengXiangDropdown.captionText.text = FengXiangDropdown.options[FengXiangDropdown.value].text; //风力赋值 Dropdown FengLiDropdown = WeatherImage.Find("FengLiDropdown").GetComponent(); //FengLiDropdown.GetComponent().SetAttri(); FengLiDropdown.value = GetID(FengLiDropdown, weatherAttri.TheWindPower); FengLiDropdown.captionText.text = FengLiDropdown.options[FengLiDropdown.value].text; } get { weatherAttri = new WeatherAttribute(); //温度赋值 weatherAttri.TheTemperature = WeatherImage.Find("InputField/Text").GetComponent().text; //天气赋值 Dropdown WeatherDropdown = WeatherImage.Find("WeatherDropdown").GetComponent(); weatherAttri.TheWeathertext = WeatherDropdown.captionText.text; //风向赋值 Dropdown FengXiangDropdown = WeatherImage.Find("FengXiangDropdown").GetComponent(); weatherAttri.TheWindDirection = FengXiangDropdown.captionText.text; //风力赋值 Dropdown FengLiDropdown = WeatherImage.Find("FengLiDropdown").GetComponent(); weatherAttri.TheWindPower = FengLiDropdown.captionText.text; return weatherAttri; } } private int GetID(Dropdown WeatherDropdown, string d_v) { int id = 0; id = WeatherDropdown.options.FindIndex(o => { return (o.text == d_v); }); return id; } private void SetWeatherSprite(string WeatherText) { var S_W = transform.Find("WeatherImage").GetComponent(); switch (WeatherText) { case "晴": S_W.sprite = Resources.Load("Weather/Qing", typeof(Sprite)) as Sprite; break; case "阴": S_W.sprite = Resources.Load("Weather/Yin", typeof(Sprite)) as Sprite; break; case "雨": S_W.sprite = Resources.Load("Weather/Yu", typeof(Sprite)) as Sprite; break; case "雪": S_W.sprite = Resources.Load("Weather/Xue", typeof(Sprite)) as Sprite; break; default: break; } } }