public async Task LoadWeather(string cityName) { //Reseting Weather Text: //Write WeatherData textCity.text = textTemp.text = textDescription.text = "..."; //Fetch WeatherData WeatherData weatherData = await weatherQuery.FetchWeatherData(cityName); if (weatherData == null) { Debug.LogError("WeatherData is null!"); return; } int code = weatherData.weather[0].id; //Assign Weatherscene WeatherScene weatherScene = CodeToWeather(code); weatherWidget.WeatherScene = weatherScene; //Assign Rain //Thunderstrom or Cloudy weatherWidget.ThunderstormRain.enabled = weatherScene == WeatherScene.THUNDERSTORM; weatherWidget.CloudRain.enabled = weatherScene == WeatherScene.PARTLY_CLOUDY || weatherScene == WeatherScene.CLOUDY; //Assign Rain Intensity float rainIntensity = CodeToRainIntensity(code); weatherWidget.ThunderstormRain.RainRate = rainIntensity; weatherWidget.CloudRain.RainRate = rainIntensity; //Assign Snow float snowIntensity = CodeToSnowIntensity(code); weatherWidget.CloudSnow.RainEnabled = snowIntensity > 0; weatherWidget.CloudSnow.RainRate = snowIntensity; //Write WeatherData textCity.text = weatherData.name; textTemp.text = weatherData.main.temp + "°C"; textDescription.text = weatherScene.ToString(); }
//requests current weather from server and implements main weather functionallity public async void LoadWeather(string cityName) { WeatherQuery request = GetComponent <WeatherQuery>(); WeatherData data = await request.FetchWeatherData(cityName); if (data != null) { displayCity.text = cityName; temperature.text = string.Format("{0}°", data.main.temp); currentWeather.text = data.weather[0].main; int weatherId = data.weather[0].id; weatherObject.WeatherScene = CodeToWeather(weatherId); weatherObject.CloudRain.RainRate = CodeToRainIntenseity(weatherId); weatherObject.ThunderstormRain.RainRate = CodeToRainIntenseity(weatherId); weatherObject.CloudSnow.RainRate = CodeToSnowIntensity(weatherId); } else { throw new System.ArgumentNullException(); } }