新Feedback系统
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using Cielonos.MainGame.Effects.Feedback;
|
||||
using Lean.Pool;
|
||||
using MoreMountains.Feedbacks;
|
||||
using MoreMountains.FeedbacksForThirdParty;
|
||||
using SLSUtilities.Feedback;
|
||||
using SLSUtilities.FeelAssistance;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -9,18 +11,114 @@ namespace Cielonos.MainGame.Characters
|
||||
{
|
||||
public partial class FeedbackSubcontroller : SubcontrollerBase<CharacterBase>
|
||||
{
|
||||
// === 旧系统(Feel)—— 保留向后兼容 ===
|
||||
public Dictionary<string, FeedbackUnit> feedbacks;
|
||||
public FeedbackUnit this[string feedbackName] => feedbacks?.GetValueOrDefault(feedbackName, null);
|
||||
|
||||
// === 新系统(Feedback System)===
|
||||
public FeedbackDataCollection feedbackDataCollection;
|
||||
|
||||
private CharacterFeedbackTimeProvider _timeProvider;
|
||||
private readonly List<FeedbackPlayer> _activePlayers = new List<FeedbackPlayer>(8);
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
if (owner != null)
|
||||
{
|
||||
_timeProvider = new CharacterFeedbackTimeProvider(owner);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过新系统播放一个 FeedbackData。
|
||||
/// </summary>
|
||||
public FeedbackPlayer PlayFeedback(FeedbackData data, bool stopPrevious = false)
|
||||
{
|
||||
if (data == null) return null;
|
||||
|
||||
if (stopPrevious)
|
||||
{
|
||||
StopFeedback(data);
|
||||
}
|
||||
|
||||
var player = new FeedbackPlayer(data, _timeProvider, owner?.transform);
|
||||
player.Play();
|
||||
_activePlayers.Add(player);
|
||||
return player;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过名称从 FeedbackDataCollection 中查找并播放。
|
||||
/// </summary>
|
||||
public FeedbackPlayer PlayFeedback(string name, bool stopPrevious = false)
|
||||
{
|
||||
if (feedbackDataCollection == null)
|
||||
{
|
||||
Debug.LogWarning($"[FeedbackSubcontroller] feedbackDataCollection is null on {owner?.name}.");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!feedbackDataCollection.TryGet(name, out FeedbackData data))
|
||||
{
|
||||
Debug.LogWarning($"[FeedbackSubcontroller] FeedbackData '{name}' not found on {owner?.name}.");
|
||||
return null;
|
||||
}
|
||||
|
||||
return PlayFeedback(data, stopPrevious);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 停止指定 FeedbackData 的所有活跃播放器。
|
||||
/// </summary>
|
||||
public void StopFeedback(FeedbackData data)
|
||||
{
|
||||
for (int i = _activePlayers.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (_activePlayers[i].Data == data)
|
||||
{
|
||||
_activePlayers[i].Stop();
|
||||
_activePlayers.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 停止所有活跃的新系统播放器。
|
||||
/// </summary>
|
||||
public void StopAllFeedbacks()
|
||||
{
|
||||
for (int i = _activePlayers.Count - 1; i >= 0; i--)
|
||||
{
|
||||
_activePlayers[i].Stop();
|
||||
}
|
||||
_activePlayers.Clear();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (feedbacks == null) return;
|
||||
|
||||
foreach (var feedbackUnit in feedbacks.Values)
|
||||
// 旧系统驱动
|
||||
if (feedbacks != null)
|
||||
{
|
||||
float timeScaleMultiplier = owner.selfTimeSm.TimeScale;
|
||||
feedbackUnit.feedback.ExternalTimeScale = timeScaleMultiplier;
|
||||
feedbackUnit.Update();
|
||||
foreach (var feedbackUnit in feedbacks.Values)
|
||||
{
|
||||
float timeScaleMultiplier = owner.selfTimeSm.TimeScale;
|
||||
feedbackUnit.feedback.ExternalTimeScale = timeScaleMultiplier;
|
||||
feedbackUnit.Update();
|
||||
}
|
||||
}
|
||||
|
||||
// 新系统驱动
|
||||
float dt = Time.unscaledDeltaTime;
|
||||
for (int i = _activePlayers.Count - 1; i >= 0; i--)
|
||||
{
|
||||
FeedbackPlayer player = _activePlayers[i];
|
||||
player.Tick(dt);
|
||||
|
||||
if (player.IsCompleted || !player.IsActive)
|
||||
{
|
||||
_activePlayers.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user