160 lines
3.8 KiB
C#
160 lines
3.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Obvious.Soap;
|
|
using UnityEngine;
|
|
|
|
public class WeatherController : MonoBehaviourSingleton<WeatherController>
|
|
{
|
|
[Serializable]
|
|
public class DayTimeSetting
|
|
{
|
|
public float Time;
|
|
|
|
public float SunX;
|
|
|
|
public float MoonIntesity;
|
|
|
|
public float SunIntensity;
|
|
|
|
public float ColorTemp;
|
|
|
|
public bool IsSunArise;
|
|
}
|
|
|
|
[SerializeField]
|
|
private ScriptableWeatherVariable weather;
|
|
|
|
[SerializeField]
|
|
private FloatVariable temperature;
|
|
|
|
[SerializeField]
|
|
private FloatVariable windSpeed;
|
|
|
|
[SerializeField]
|
|
private Vector2Variable windDirection;
|
|
|
|
[SerializeField]
|
|
private FloatVariable dayTime;
|
|
|
|
[SerializeField]
|
|
private FloatVariable timeScale;
|
|
|
|
[SerializeField]
|
|
private StringVariable dayTimeConverted;
|
|
|
|
[SerializeField]
|
|
private Light sunLight;
|
|
|
|
[SerializeField]
|
|
private Light moonLight;
|
|
|
|
public DayTimeSetting dayTimeSetting;
|
|
|
|
public float DayChangeTime = 0.35f;
|
|
|
|
public List<DayTimeSetting> dayTimeSettingList;
|
|
|
|
public int currentSettingID;
|
|
|
|
private bool isWaitingForEndDay;
|
|
|
|
private bool isWeatherChange;
|
|
|
|
[SerializeField]
|
|
private AnimationCurve sunLightCurve;
|
|
|
|
[SerializeField]
|
|
private AnimationCurve sunXCurve;
|
|
|
|
[SerializeField]
|
|
private AnimationCurve sunColorTempCurve;
|
|
|
|
[SerializeField]
|
|
private AnimationCurve moonLightCurve;
|
|
|
|
private void OnEnable()
|
|
{
|
|
Initialize();
|
|
windSpeed.OnValueChanged += WindSpeed_OnValueChanged;
|
|
temperature.OnValueChanged += Temperature_OnValueChanged;
|
|
windDirection.OnValueChanged += WindDirection_OnValueChanged;
|
|
weather.OnValueChanged += Weather_OnValueChanged;
|
|
dayTime.OnValueChanged += DayTime_OnValueChanged;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
windSpeed.OnValueChanged -= WindSpeed_OnValueChanged;
|
|
temperature.OnValueChanged -= Temperature_OnValueChanged;
|
|
windDirection.OnValueChanged -= WindDirection_OnValueChanged;
|
|
weather.OnValueChanged -= Weather_OnValueChanged;
|
|
dayTime.OnValueChanged -= DayTime_OnValueChanged;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
dayTime.Value += Time.deltaTime * timeScale.Value;
|
|
if (dayTime.Value >= 24f)
|
|
{
|
|
dayTime.Value -= 24f;
|
|
isWaitingForEndDay = false;
|
|
}
|
|
}
|
|
|
|
private void CreateAnimationCurves()
|
|
{
|
|
sunLightCurve.ClearKeys();
|
|
sunXCurve.ClearKeys();
|
|
sunColorTempCurve.ClearKeys();
|
|
moonLightCurve.ClearKeys();
|
|
foreach (DayTimeSetting dayTimeSetting in dayTimeSettingList)
|
|
{
|
|
sunLightCurve.AddKey(dayTimeSetting.Time, dayTimeSetting.SunIntensity);
|
|
sunXCurve.AddKey(dayTimeSetting.Time, dayTimeSetting.SunX);
|
|
sunColorTempCurve.AddKey(dayTimeSetting.Time, dayTimeSetting.ColorTemp);
|
|
moonLightCurve.AddKey(dayTimeSetting.Time, dayTimeSetting.MoonIntesity);
|
|
sunLightCurve.postWrapMode = WrapMode.Loop;
|
|
sunXCurve.postWrapMode = WrapMode.Loop;
|
|
sunColorTempCurve.postWrapMode = WrapMode.Loop;
|
|
moonLightCurve.postWrapMode = WrapMode.Loop;
|
|
}
|
|
}
|
|
|
|
private void DayTime_OnValueChanged(float obj)
|
|
{
|
|
_ = obj / 24f;
|
|
_ = currentSettingID;
|
|
float num = Mathf.Floor(obj);
|
|
int num2 = (int)Mathf.Floor(60f * (obj % 1f));
|
|
dayTimeConverted.Value = string.Format("{0}:{1}", num, num2.ToString("D2"));
|
|
sunLight.intensity = sunLightCurve.Evaluate(dayTime.Value);
|
|
sunLight.colorTemperature = sunColorTempCurve.Evaluate(dayTime.Value);
|
|
moonLight.intensity = moonLightCurve.Evaluate(dayTime.Value);
|
|
sunLight.transform.localEulerAngles = new Vector3(sunXCurve.Evaluate(dayTime.Value), 0f, 0f);
|
|
}
|
|
|
|
private void Weather_OnValueChanged(WeatherType obj)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private void WindDirection_OnValueChanged(Vector2 obj)
|
|
{
|
|
Vector2.SignedAngle(Vector2.right, obj.normalized);
|
|
Debug.Log($"TEST: {Vector2.SignedAngle(Vector2.right, obj.normalized)}");
|
|
}
|
|
|
|
private void Temperature_OnValueChanged(float obj)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private void WindSpeed_OnValueChanged(float value)
|
|
{
|
|
}
|
|
|
|
private void Initialize()
|
|
{
|
|
}
|
|
}
|