35 lines
1.0 KiB
GDScript
35 lines
1.0 KiB
GDScript
## TimeManager — 时间缩放与 GameTick 计数器(Autoload: TimeManager)
|
||
## 权威来源:implementation_plan.md §2.1 Layer-0
|
||
##
|
||
## - time_scale: 全局时间缩放(慢动作 / 冻结时间 Core 效果)
|
||
## - game_tick: 物理帧计数器(每 _physics_process 递增 1)— 不受 time_scale 影响
|
||
extends Node
|
||
|
||
var time_scale: float = 1.0
|
||
var game_tick: int = 0
|
||
|
||
func _ready() -> void:
|
||
process_mode = Node.PROCESS_MODE_ALWAYS # 暂停时仍持续计数
|
||
|
||
func _physics_process(_delta: float) -> void:
|
||
game_tick += 1
|
||
Engine.time_scale = time_scale
|
||
|
||
## 返回当前帧缩放后 delta(供战斗系统使用)
|
||
func scaled_delta(raw_delta: float) -> float:
|
||
return raw_delta * time_scale
|
||
|
||
## 设置时间缩放(clamp 防止异常値)
|
||
func set_time_scale(scale: float) -> void:
|
||
time_scale = clamp(scale, 0.0, 10.0)
|
||
|
||
## 恢复正常速度
|
||
func reset_time_scale() -> void:
|
||
time_scale = 1.0
|
||
Engine.time_scale = 1.0
|
||
|
||
## 忽略帧计数器(关卡重置)
|
||
func reset() -> void:
|
||
game_tick = 0
|
||
reset_time_scale()
|