True Weather - Unity Asset Store - Nephasto

'True Weather' gives you information about the weather conditions and the geolocation of the users of your games.

🕹️ Demo  🛒 Store

Setting

In order to start using ‘True Weather’ the first thing you should do is create a new object in your scene and add the component ‘TrueWeather’. There should be only one instance of that component.

Once added, you will see something like this in the editor:

 

In ‘Units’ (1) you can change the metric system in which the units will be.

If ‘Try GPS first’ (2) is activated, the geolocation service will first attempt to use the GPS hardware of the device. This is usually only available on mobile devices and the application will need permissions to use it. If this option is used and to save battery, the configuration is used with less precision (~500 meters) and is only active during detection.

If this option is not activated, or is not available, the web service provided by ipap.co. This service does not require registration for less than 1000 consultations per day. We recommend you register and look his payment service when your game is public. When you register, they will give you a key that you must put in ‘API Key’ (3).

To obtain the meteorological data, the web service provided by openweathermap.com will be used. This service does require you to register, even for your free service. You must register for the ‘Current weather data’ service in the API section:

 

With the free service you can make up to 60 queries every hour. When you register, they will give you a key that you must put in ‘API Key’ (4).

Are you interested in using another similar service? Do not hesitate to contact us.

Use

All code is inside the namespace ‘Nephasto.TrueWeatherAsset’ and main component is ‘TrueWeather’. So if you want to use it you must first import its namespace:

1
 using Nephasto.TrueWeatherAsset;

 

If you already created an object with the ‘TrueWeather’ component, to access it:

1
 TrueWeather trueWeather = FindObjectOfType<TrueWeather>();

 

To detect the current time you will first have to call the function ‘Detect()’. As this information may take some time to be available, you can pass an Action as a parameter to know when it is ready. For example, if you want that when the information is available, your ‘ShowWeatherInfo()’ function is called:

1
2
3
4
5
6
7
 trueWeather.Detect((success, errorMsg) =>
 {
   if (success == true)
     ShowWeatherInfo();
   else
     Debug.LogError($"Error: {errorMsg}");
 });

 

Once the ‘Detect()’ function returns you successfully, you can check the information using the properties ‘Location’ (geolocation) and ‘Weather’ (meteorological information):

1
2
3
4
5
6
7
8
9
 float latitude = trueWeather.Location.Latitude;
 float longitude = trueWeather.Location.Longitude;

 string description = trueWeather.Weather.Description;
 float temperature = trueWeather.Weather.Temperature;
 float pressure = trueWeather.Weather.Presure;
 float humifity = trueWeather.Weather.Humidity;
 DateTime sunrise = trueWeather.Weather.Sunrise;
 DateTime sunset = trueWeather.Weather.Sunset;

 

All this information will be available until the next time you call ‘Detect()’. If instead of the meteorological data you want a description of the weather, you can consult ‘trueWeather.Weather.ID’ which will return an identifier that depends on the service used. While using the ‘OpenWeatherMap’ service, the identifier corresponds to the values you can see in the file ‘OpenWeatherMapIDs.cs':

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
 public enum OpenWeatherMapIDs
 {
   // Thunderstorm.
   ThunderstormLightRain = 200,
   ThunderstormRain = 201,
   ThunderstormHeavyRain = 202,
   LightThunderstorm = 210,
   Thunderstorm = 211,
   HeavyThunderstorm = 212,
   RaggedThunderstorm = 221,
   ThunderstormWithLightDrizzle = 230,
   ThunderstormWithDrizzle = 231,
   ThunderstormWithHeavyDrizzle = 232,
    
   // Drizzle. 
   LightDrizzle = 300,
   Drizzle = 301,
   HeavyDrizzle = 302,
   LightDrizzleRain = 310,
   DrizzleRain = 311,
   HeavyDrizzleRain = 312,
   ShowerRainAndDrizzle = 313,
   HeavyShowerRainAndDrizzle = 314,
   ShowerDrizzle = 312,
    
   // Rain. 
   LightRain = 500,
   ModerateRain = 501,
   HeavyRain = 502,
   VeryHeavyRain = 503,
   ExtremeRain = 504,
   FreezingRain = 511,
   LightShowerRain = 520,
   ShowerRain = 521,
   HeavyShowerRain = 522,
   RaggedShowerRain = 531,
    
   // Snow. 
   LightSnow = 600,
   Snow = 601,
   HeavySnow = 602,
   Sleet = 611,
   LightShowerSleet = 612,
   ShowerSleet = 613,
   LightRainAndSnow = 615,
   RainAndSnow = 616,
   LightShowerSnow = 620,
   ShowerSnow = 621,
   HeavyShowerSnow = 622,
    
   // Atmosphere. 
   Mist = 701,
   Smoke = 711,
   Haze = 721,
   DustWhirls = 731,
   Fog = 741,
   Sand = 751,
   Dust = 761,
   VolcanicAsh = 762,
   Squalls = 771,
   Tornado = 781,
    
   // Clear. 
   Clear = 800,
    
   // Clouds. 
   FewClouds = 801,
   ScatteredClouds = 802,
   BrokenClouds = 803,
   OvercastClouds = 804,
 }

 

Optionally, and if you have used the ipap.co service (not the GPS device), you can access the extra information provided by this service:

1
2
3
4
5
6
7
8
9
 if (trueWeather.Location is IPAPILocation)
 {
   IPAPILocation ipAPILocation = (IPAPILocation)trueWeather.Location;

   string ip = ipAPILocation.IPAdress;
   string country = ipAPILocation.Country;
   string region = ipAPILocation.Region;
   string city = ipAPILocation.City;
 }

 

All the code are well commented, I recommend reading it if you want more information.

Any questions or suggestions you have, I will be happy to answer you in

hello@nephasto.com