You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/3rd/D2D_Scripts/Utilities/DTime.cs

35 lines
1.0 KiB
C#

using Cysharp.Threading.Tasks;
using D2D.Gameplay;
using DG.Tweening;
using UnityEngine;
namespace D2D.Utilities
{
/// <summary>
/// For time management in game and especially for slow-mos.
/// </summary>
public static class DTime
{
private const float FixedDeltaTimeFactor = .02f;
private const float SlowMoTimeScale = .2f;
private const float SlowMoDuration = 1.5f;
private const float SlowMoLerpDuration = .3f;
public static float TimeScale
{
get => Time.timeScale;
set
{
Time.timeScale = value;
Time.fixedDeltaTime = value * FixedDeltaTimeFactor;
}
}
public static async UniTaskVoid SlowMo()
{
DOVirtual.Float(1f, SlowMoTimeScale, SlowMoLerpDuration, x => TimeScale = x);
await UniTask.Delay((SlowMoDuration * 1000).Round(), true);
DOVirtual.Float(SlowMoTimeScale, 1f , SlowMoLerpDuration, x => TimeScale = x);
}
}
}