98 lines
2.0 KiB
C#
98 lines
2.0 KiB
C#
using Obvious.Soap;
|
|
using QFSW.QC;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering.HighDefinition;
|
|
|
|
public class DirectionalLightsController : MonoBehaviour, IBatchUpdate
|
|
{
|
|
[SerializeField]
|
|
private UpdateManager.UpdateMode _updateMode = UpdateManager.UpdateMode.Always;
|
|
|
|
public FloatVariable DayTime;
|
|
|
|
public IntVariable Day;
|
|
|
|
public float TimeScale = 1f;
|
|
|
|
[SerializeField]
|
|
private HDAdditionalLightData _HDLight;
|
|
|
|
[SerializeField]
|
|
private int _distantShadowsUpdateInterval = 2;
|
|
|
|
public IntVariable LightQualityLevel;
|
|
|
|
[Range(0f, 1f)]
|
|
public float sunRotationDisplacement;
|
|
|
|
private int _cascadeToUpdate;
|
|
|
|
private int _distantShadowsUpdateTimer;
|
|
|
|
private void Awake()
|
|
{
|
|
SetShadowQualityLevel(LightQualityLevel.Value);
|
|
_HDLight.shadowUpdateMode = ShadowUpdateMode.OnDemand;
|
|
}
|
|
|
|
public void SetShadowQualityLevel(int level)
|
|
{
|
|
_HDLight.SetShadowResolutionLevel(level);
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
UpdateManager.RegisterSlicedUpdate(this, _updateMode);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
UpdateManager.DeregisterSlicedUpdate(this);
|
|
}
|
|
|
|
public void BatchUpdate()
|
|
{
|
|
if (!(TimeScale <= 0f))
|
|
{
|
|
float value = DayTime.Value;
|
|
value += Time.deltaTime * TimeScale;
|
|
if (value >= 24f)
|
|
{
|
|
value -= 24f;
|
|
Day.Value++;
|
|
}
|
|
DayTime.Value = value;
|
|
UpdateShadowMap();
|
|
}
|
|
}
|
|
|
|
private void UpdateShadowMap()
|
|
{
|
|
_HDLight.RequestSubShadowMapRendering(0);
|
|
_distantShadowsUpdateTimer++;
|
|
if (_distantShadowsUpdateTimer >= _distantShadowsUpdateInterval)
|
|
{
|
|
_cascadeToUpdate++;
|
|
_HDLight.RequestSubShadowMapRendering(_cascadeToUpdate);
|
|
_distantShadowsUpdateTimer = 0;
|
|
if (_cascadeToUpdate >= 3)
|
|
{
|
|
_cascadeToUpdate = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
[Command("SetDayTime", Platform.AllPlatforms, MonoTargetType.Single)]
|
|
[CommandDescription("Set Value beetween 0 - 24")]
|
|
public void SetDayTime(float time)
|
|
{
|
|
DayTime.Value = Mathf.Clamp(time, 0f, 24f);
|
|
}
|
|
|
|
[Command("SetTimeScale", Platform.AllPlatforms, MonoTargetType.Single)]
|
|
public void SetTimeScale(float value)
|
|
{
|
|
TimeScale = value;
|
|
}
|
|
}
|