我说次元斩

This commit is contained in:
SoulliesOfficial
2026-06-13 18:43:40 -04:00
parent 6d7ebc5825
commit a024305799
95 changed files with 138226 additions and 5191 deletions

View File

@@ -26,6 +26,22 @@ namespace SLSUtilities.Feedback
[Title("Editor Settings")]
public string feedbackName;
[Title("Play Limits")]
[LabelText("限制播放频次")]
[Tooltip("如果勾选,将限制此 Feedback 的播放频次。默认每帧最多播放1次")]
public bool limitPlay = true;
[ShowIf("limitPlay")]
[LabelText("最低播放间隔 (秒)")]
[Tooltip("两次播放之间的最低时间间隔(以 unscaledTime 计算)。为 0 代表每帧最多播放 1 次。")]
public float minPlayInterval = 0f;
[System.NonSerialized]
private float _lastPlayTime = -9999f;
[System.NonSerialized]
private int _lastPlayFrame = -1;
/// <summary>
/// 全局默认的时间设置。Clip 可选择覆盖此设置。
/// </summary>
@@ -110,5 +126,34 @@ namespace SLSUtilities.Feedback
FeedbackClip clip = track?.clips.FirstOrDefault(c => c.action.GetType() == typeof(T));
return clip?.action as T;
}
public bool CanPlay()
{
if (!limitPlay) return true;
// 防御性检查:当在 Unity 编辑器中不重新加载域运行游戏,或者重开 Run 导致运行时间倒退时,重置记录
if (Time.unscaledTime < _lastPlayTime)
{
_lastPlayTime = -9999f;
_lastPlayFrame = -1;
}
if (minPlayInterval <= 0f)
{
return Time.frameCount != _lastPlayFrame;
}
else
{
return Time.unscaledTime - _lastPlayTime >= minPlayInterval;
}
}
public void RecordPlay()
{
if (!limitPlay) return;
_lastPlayFrame = Time.frameCount;
_lastPlayTime = Time.unscaledTime;
}
}
}

View File

@@ -40,6 +40,12 @@ namespace SLSUtilities.Feedback
return null;
}
if (!data.CanPlay())
{
return null;
}
data.RecordPlay();
var player = new FeedbackPlayer(data, timeProvider, owner);
player.Play();
_activePlayers.Add(player);