2025-07-08 10:46:31 +00:00
|
|
|
|
using System;
|
|
|
|
|
using Superlazy;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public static class SpeedUtil
|
|
|
|
|
{
|
|
|
|
|
public static float Speed { get; set; } = 1.0f;
|
|
|
|
|
private static bool speedMode = false;
|
|
|
|
|
|
|
|
|
|
private static readonly float slowSpeed = 0.0005f;
|
|
|
|
|
|
|
|
|
|
private static bool slow = false;
|
|
|
|
|
private static float slowTime = 0;
|
|
|
|
|
private static float slowDelay = 0;
|
|
|
|
|
|
|
|
|
|
private static bool cutInSlow = false;
|
|
|
|
|
private static float cutInSlowDelay = 0;
|
|
|
|
|
|
|
|
|
|
public static void EnableSpeedMode(bool enable)
|
|
|
|
|
{
|
|
|
|
|
if (enable)
|
|
|
|
|
{
|
|
|
|
|
speedMode = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
speedMode = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UpdateSpeed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Pause(bool pause)
|
|
|
|
|
{
|
|
|
|
|
if (pause)
|
|
|
|
|
{
|
|
|
|
|
Time.timeScale = 0.000000001f;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Time.timeScale = 1;
|
|
|
|
|
slowTime = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UpdateSpeed();// 현재 필요는 없지만 pause 체크 방식을 별도 변수로 뽑는다거나 할수 있어 일관성 있게 처리함
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void SetSpeed(float speed)
|
|
|
|
|
{
|
|
|
|
|
SpeedUtil.Speed = speed;
|
|
|
|
|
|
|
|
|
|
UpdateSpeed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static void SetSlow(float slowDelay = 0.0f, float slowTime = 0)
|
|
|
|
|
{
|
|
|
|
|
slow = true;
|
|
|
|
|
|
|
|
|
|
SpeedUtil.slowDelay = slowDelay - Time.unscaledDeltaTime;
|
|
|
|
|
SpeedUtil.slowTime = slowTime - Time.unscaledDeltaTime;
|
|
|
|
|
|
|
|
|
|
UpdateSpeed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void UpdateSpeed()
|
|
|
|
|
{
|
|
|
|
|
if (Time.timeScale <= 0.0001f) return; // if paused
|
|
|
|
|
|
|
|
|
|
if (cutInSlow)
|
|
|
|
|
{
|
|
|
|
|
if (cutInSlowDelay <= 0)
|
|
|
|
|
{
|
|
|
|
|
Time.timeScale = slowSpeed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (slow)
|
|
|
|
|
{
|
|
|
|
|
if (slowDelay <= 0 && slowTime > 0)
|
|
|
|
|
{
|
|
|
|
|
Time.timeScale = slowSpeed * Speed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (speedMode)
|
|
|
|
|
{
|
|
|
|
|
Time.timeScale = Speed;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Time.timeScale = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Update()
|
|
|
|
|
{
|
|
|
|
|
if (cutInSlowDelay > 0)
|
|
|
|
|
{
|
|
|
|
|
cutInSlowDelay -= Time.unscaledDeltaTime;
|
|
|
|
|
|
|
|
|
|
if (cutInSlowDelay <= 0)
|
|
|
|
|
{
|
|
|
|
|
UpdateSpeed();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (slowDelay > 0)
|
|
|
|
|
{
|
|
|
|
|
slowDelay -= Time.unscaledDeltaTime;
|
|
|
|
|
|
|
|
|
|
if (slowDelay < 0)
|
|
|
|
|
{
|
|
|
|
|
UpdateSpeed();
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (slowTime > 0)
|
|
|
|
|
{
|
|
|
|
|
slowTime -= Time.unscaledDeltaTime;
|
|
|
|
|
|
|
|
|
|
if (slowTime <= 0)
|
|
|
|
|
{
|
|
|
|
|
slow = false;
|
|
|
|
|
UpdateSpeed();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void SetCutInSlow(bool slow, float delay = 0)
|
|
|
|
|
{
|
|
|
|
|
cutInSlow = slow;
|
|
|
|
|
cutInSlowDelay = delay - Time.unscaledDeltaTime;
|
|
|
|
|
|
|
|
|
|
UpdateSpeed();
|
|
|
|
|
}
|
|
|
|
|
}
|