天津23维预案
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

97 lines
4.1 KiB

using UnityEngine;
using System.Collections;
using AX.TrackRecord;
using UnityEngine.UI;
using DevelopEngine;
using AX.MessageSystem;
public class WeatherManager : SingletonMono<WeatherManager> {
public Transform WeatherImage;
private WeatherAttribute weatherAttri;
public WeatherAttribute WeatherAttribute
{
set
{
weatherAttri = value;
SetWeatherSprite(weatherAttri.TheWeathertext);
transform.Find("FengXiangText").GetComponent<Text>().text = weatherAttri.TheWindDirection;
transform.Find("TemperatureText").GetComponent<Text>().text = weatherAttri.TheTemperature + "℃";
transform.Find("FengLiText").GetComponent<Text>().text = weatherAttri.TheWindPower;
//温度赋值
InputField text = WeatherImage.Find("InputField").GetComponent<InputField>();
text.text = weatherAttri.TheTemperature.ToString();
//天气赋值
Dropdown WeatherDropdown = WeatherImage.Find("WeatherDropdown").GetComponent<Dropdown>();
//WeatherDropdown.GetComponent<TianQiControl>().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<Dropdown>();
//FengXiangDropdown.GetComponent<FengXiangControl>().SetAttri();
FengXiangDropdown.value = GetID(FengXiangDropdown, weatherAttri.TheWindDirection);
FengXiangDropdown.captionText.text = FengXiangDropdown.options[FengXiangDropdown.value].text;
//风力赋值
Dropdown FengLiDropdown = WeatherImage.Find("FengLiDropdown").GetComponent<Dropdown>();
//FengLiDropdown.GetComponent<FengLiControl>().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>().text;
//天气赋值
Dropdown WeatherDropdown = WeatherImage.Find("WeatherDropdown").GetComponent<Dropdown>();
weatherAttri.TheWeathertext = WeatherDropdown.captionText.text;
//风向赋值
Dropdown FengXiangDropdown = WeatherImage.Find("FengXiangDropdown").GetComponent<Dropdown>();
weatherAttri.TheWindDirection = FengXiangDropdown.captionText.text;
//风力赋值
Dropdown FengLiDropdown = WeatherImage.Find("FengLiDropdown").GetComponent<Dropdown>();
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<Image>();
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;
}
}
}