2023-09-13 05:07:40 +00:00
// Distant Lands 2022.
using UnityEngine ;
2024-01-03 06:34:33 +00:00
using System.Collections.Generic ;
using UnityEngine.Serialization ;
2023-09-13 05:07:40 +00:00
#if UNITY_EDITOR
using UnityEditor ;
#endif
namespace DistantLands.Cozy.Data
{
[System.Serializable]
[CreateAssetMenu(menuName = "Distant Lands/Cozy/Climate Profile", order = 361)]
public class ClimateProfile : ScriptableObject
{
[Tooltip("The global temprature during the year. the x-axis is the current day over the days in the year and the y axis is the temprature in farenheit.")]
2024-01-03 06:34:33 +00:00
[FormerlySerializedAs("tempratureOverYear")]
public AnimationCurve temperatureOverYear ;
2023-09-13 05:07:40 +00:00
[Tooltip("The global precipitation during the year. the x-axis is the current day over the days in the year and the y axis is the precipitation.")]
2024-01-03 06:34:33 +00:00
public AnimationCurve humidityOverYear ;
2023-09-13 05:07:40 +00:00
[Tooltip("The local temprature during the day. the x-axis is the current ticks over 360 and the y axis is the temprature change in farenheit from the global temprature.")]
2024-01-03 06:34:33 +00:00
[FormerlySerializedAs("tempratureOverDay")]
public AnimationCurve temperatureOverDay ;
2023-09-13 05:07:40 +00:00
[Tooltip("The local precipitation during the day. the x-axis is the current ticks over 360 and the y axis is the precipitation change from the global precipitation.")]
2024-01-03 06:34:33 +00:00
public AnimationCurve humidityOverDay ;
2023-09-13 05:07:40 +00:00
[Tooltip("Adds an offset to the global temprature. Useful for adding biomes or climate change by location or elevation")]
2024-01-03 06:34:33 +00:00
public float temperatureFilter ;
2023-09-13 05:07:40 +00:00
[Tooltip("Adds an offset to the global precipitation. Useful for adding biomes or climate change by location or elevation")]
2024-01-03 06:34:33 +00:00
public float humidityFilter ;
2023-09-13 05:07:40 +00:00
2024-01-03 06:34:33 +00:00
public float GetTemperature ( )
2023-09-13 05:07:40 +00:00
{
CozyWeather weather = CozyWeather . instance ;
2024-01-03 06:34:33 +00:00
float i = ( temperatureOverYear . Evaluate ( weather . yearPercentage ) * temperatureOverDay . Evaluate ( weather . modifiedDayPercentage ) ) + temperatureFilter ;
2023-09-13 05:07:40 +00:00
return i ;
}
2024-01-03 06:34:33 +00:00
public float GetTemperature ( CozyWeather weather )
2023-09-13 05:07:40 +00:00
{
2024-01-03 06:34:33 +00:00
float i = ( temperatureOverYear . Evaluate ( weather . yearPercentage ) * temperatureOverDay . Evaluate ( weather . modifiedDayPercentage ) ) + temperatureFilter ;
2023-09-13 05:07:40 +00:00
return i ;
}
2024-01-03 06:34:33 +00:00
public float GetTemperature ( CozyWeather weather , float inTime )
2023-09-13 05:07:40 +00:00
{
2024-01-03 06:34:33 +00:00
if ( ! weather . timeModule )
return GetTemperature ( weather ) ;
2023-09-13 05:07:40 +00:00
2024-01-03 06:34:33 +00:00
float nextDays = inTime ;
2023-09-13 05:07:40 +00:00
2024-01-03 06:34:33 +00:00
float i = ( temperatureOverYear . Evaluate ( ( weather . timeModule . DayAndTime ( ) + nextDays ) / weather . timeModule . GetDaysPerYear ( ) ) * temperatureOverDay . Evaluate ( weather . timeModule . modifiedDayPercentage ) ) + temperatureFilter ;
2023-09-13 05:07:40 +00:00
return i ;
}
public float GetHumidity ( )
{
CozyWeather weather = CozyWeather . instance ;
2024-01-03 06:34:33 +00:00
float i = ( humidityOverYear . Evaluate ( weather . yearPercentage ) * humidityOverDay . Evaluate ( weather . modifiedDayPercentage ) ) + humidityFilter ;
2023-09-13 05:07:40 +00:00
return i ;
}
public float GetHumidity ( CozyWeather weather )
{
2024-01-03 06:34:33 +00:00
if ( weather = = null )
weather = CozyWeather . instance ;
float i = ( humidityOverYear . Evaluate ( weather . yearPercentage ) * humidityOverDay . Evaluate ( weather . modifiedDayPercentage ) ) + humidityFilter ;
2023-09-13 05:07:40 +00:00
return i ;
}
2024-01-03 06:34:33 +00:00
public float GetHumidity ( CozyWeather weather , float inTime )
2023-09-13 05:07:40 +00:00
{
2024-01-03 06:34:33 +00:00
if ( ! weather . timeModule )
return GetHumidity ( weather ) ;
2023-09-13 05:07:40 +00:00
2024-01-03 06:34:33 +00:00
float nextDays = inTime ;
float i = ( humidityOverYear . Evaluate ( ( weather . timeModule . DayAndTime ( ) + nextDays ) / weather . perennialProfile . daysPerYear ) * humidityOverDay . Evaluate ( weather . timeModule . modifiedDayPercentage ) ) + humidityFilter ;
2023-09-13 05:07:40 +00:00
return i ;
}
}
#if UNITY_EDITOR
[CustomEditor(typeof(ClimateProfile))]
[CanEditMultipleObjects]
public class E_ClimateProfile : Editor
{
SerializedProperty tempratureOverYear ;
SerializedProperty precipitationOverYear ;
SerializedProperty tempratureOverDay ;
SerializedProperty precipitationOverDay ;
SerializedProperty tempratureFilter ;
SerializedProperty precipitationFilter ;
ClimateProfile prof ;
void OnEnable ( )
{
2024-01-03 06:34:33 +00:00
tempratureOverYear = serializedObject . FindProperty ( "temperatureOverYear" ) ;
precipitationOverYear = serializedObject . FindProperty ( "humidityOverYear" ) ;
tempratureOverDay = serializedObject . FindProperty ( "temperatureOverDay" ) ;
precipitationOverDay = serializedObject . FindProperty ( "humidityOverDay" ) ;
tempratureFilter = serializedObject . FindProperty ( "temperatureFilter" ) ;
precipitationFilter = serializedObject . FindProperty ( "humidityFilter" ) ;
2023-09-13 05:07:40 +00:00
prof = ( ClimateProfile ) target ;
}
public override void OnInspectorGUI ( )
{
serializedObject . Update ( ) ;
Undo . RecordObject ( prof , prof . name + " Profile Changes" ) ;
EditorGUILayout . LabelField ( "Global Curves" , EditorStyles . boldLabel ) ;
EditorGUILayout . PropertyField ( tempratureOverYear ) ;
EditorGUILayout . PropertyField ( precipitationOverYear ) ;
EditorGUILayout . PropertyField ( tempratureOverDay ) ;
EditorGUILayout . PropertyField ( precipitationOverDay ) ;
EditorGUILayout . Space ( 20 ) ;
EditorGUILayout . LabelField ( "Global Filters" , EditorStyles . boldLabel ) ;
EditorGUILayout . PropertyField ( tempratureFilter ) ;
EditorGUILayout . PropertyField ( precipitationFilter ) ;
EditorGUILayout . Space ( ) ;
EditorUtility . SetDirty ( prof ) ;
serializedObject . ApplyModifiedProperties ( ) ;
}
}
#endif
}