2026-04-12 02:11:15 -04:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using SLSUtilities.General;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
namespace SLSUtilities.Feedback
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 全局 Feedback 播放管理器(Singleton)。
|
|
|
|
|
|
/// 集中驱动所有注册的 FeedbackPlayer,提供 Play / Stop 快捷 API。
|
|
|
|
|
|
/// 适用于不绑定特定角色时间缩放的"全局反馈"(如后处理效果、UI 反馈等)。
|
|
|
|
|
|
/// 需要角色级时间缩放的反馈仍由 FeedbackSubcontroller 手动驱动。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class FeedbackManager : Singleton<FeedbackManager>
|
|
|
|
|
|
{
|
|
|
|
|
|
private const int INITIAL_CAPACITY = 64;
|
|
|
|
|
|
|
|
|
|
|
|
private readonly List<FeedbackPlayer> _activePlayers = new List<FeedbackPlayer>(INITIAL_CAPACITY);
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 当前活跃的 Player 数量。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public int ActiveCount => _activePlayers.Count;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 以全局方式播放一个 FeedbackData,不绑定任何 owner 或 timeProvider。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public FeedbackPlayer Play(FeedbackData data)
|
|
|
|
|
|
{
|
2026-04-29 06:16:07 -04:00
|
|
|
|
return Play(data, DefaultFeedbackTimeProvider.Instance, null);
|
2026-04-12 02:11:15 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 播放一个 FeedbackData,指定时间提供者和 owner。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public FeedbackPlayer Play(FeedbackData data, IFeedbackTimeProvider timeProvider, Transform owner)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (data == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogWarning("[FeedbackManager] Cannot play: FeedbackData is null.");
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-13 18:43:40 -04:00
|
|
|
|
if (!data.CanPlay())
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
data.RecordPlay();
|
|
|
|
|
|
|
2026-04-12 02:11:15 -04:00
|
|
|
|
var player = new FeedbackPlayer(data, timeProvider, owner);
|
|
|
|
|
|
player.Play();
|
|
|
|
|
|
_activePlayers.Add(player);
|
|
|
|
|
|
return player;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 注册一个已有的 FeedbackPlayer 由管理器驱动。
|
|
|
|
|
|
/// 适用于外部创建 Player 后需要交给管理器集中管理的场景。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void Register(FeedbackPlayer player)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (player == null || _activePlayers.Contains(player)) return;
|
|
|
|
|
|
_activePlayers.Add(player);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 停止并移除指定的 FeedbackPlayer。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void Stop(FeedbackPlayer player)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (player == null) return;
|
|
|
|
|
|
|
|
|
|
|
|
player.Stop();
|
|
|
|
|
|
_activePlayers.Remove(player);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 停止所有活跃的 FeedbackPlayer。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void StopAll()
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = _activePlayers.Count - 1; i >= 0; i--)
|
|
|
|
|
|
{
|
|
|
|
|
|
_activePlayers[i].Stop();
|
|
|
|
|
|
}
|
|
|
|
|
|
_activePlayers.Clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
|
|
{
|
2026-04-29 06:16:07 -04:00
|
|
|
|
float dt = Time.deltaTime;
|
2026-04-12 02:11:15 -04:00
|
|
|
|
|
|
|
|
|
|
for (int i = _activePlayers.Count - 1; i >= 0; i--)
|
|
|
|
|
|
{
|
|
|
|
|
|
FeedbackPlayer player = _activePlayers[i];
|
|
|
|
|
|
player.Tick(dt);
|
|
|
|
|
|
|
|
|
|
|
|
if (player.IsCompleted || !player.IsActive)
|
|
|
|
|
|
{
|
|
|
|
|
|
_activePlayers.RemoveAt(i);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|