- Added DownDash ability with cooldown and speed configuration. - Introduced DownDashState to handle down dashing mechanics, including gravity manipulation and animation playback. - Updated PlayerMovement to support DownDash functionality. - Enhanced PlayerStats to manage spring charge consumption and healing. - Modified PlayerCombat and WeaponHitBoxInstance to support new hit confirmation events. - Updated AbilityType to include new form types for character abilities. - Improved Gizmos for better visualization of enemy detection and attack ranges. - Added feedback systems for form switching in PlayerFeedback and IFeedbackPlayer. - Refactored combat and movement states to accommodate new abilities and ensure smooth transitions.
124 lines
4.7 KiB
C#
124 lines
4.7 KiB
C#
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using MoreMountains.Feedbacks;
|
||
|
||
namespace BaseGames.Feedback
|
||
{
|
||
/// <summary>
|
||
/// 玩家反馈播放器:实现 IFeedbackPlayer,将行为语义映射到 MMF_Player 实例。
|
||
/// 挂在玩家 GameObject 上(或子对象 [Feedback] 上)。
|
||
/// 所有 MMF_Player 字段均在 Inspector 中配置 Feel 反馈链。
|
||
/// </summary>
|
||
public class PlayerFeedback : MonoBehaviour, IFeedbackPlayer
|
||
{
|
||
[Header("命中反馈")]
|
||
[SerializeField] private MMF_Player _onHitLight;
|
||
[SerializeField] private MMF_Player _onHitMedium;
|
||
[SerializeField] private MMF_Player _onHitHeavy;
|
||
[SerializeField] private MMF_Player _onParrySuccess;
|
||
|
||
[Header("受伤 / 死亡反馈")]
|
||
[SerializeField] private MMF_Player _onTakeHit;
|
||
[SerializeField] private MMF_Player _onDeath;
|
||
|
||
[Header("恢复反馈")]
|
||
[SerializeField] private MMF_Player _onHeal;
|
||
|
||
[Header("移动 / 动作反馈")]
|
||
[SerializeField] private MMF_Player _onLandImpact;
|
||
[SerializeField] private MMF_Player _onAttackWhoosh;
|
||
[SerializeField] private MMF_Player _onJumpLaunch;
|
||
[SerializeField] private MMF_Player _onFootstep;
|
||
|
||
[Header("脚步声材质检测")]
|
||
[SerializeField] private BaseGames.Audio.FootstepSoundPlayer _footstepSoundPlayer;
|
||
|
||
[Header("形态切换反馈")]
|
||
[Tooltip("索引与 FormType 枚举值对应:0=天魂, 1=地魂, 2=命魂")]
|
||
[SerializeField] private MMF_Player[] _onFormSwitch = new MMF_Player[3];
|
||
|
||
[Header("命名预设(可选)")]
|
||
[SerializeField] private NamedFeedback[] _namedPresets;
|
||
|
||
[Header("音效预设(可选)")]
|
||
[SerializeField] private NamedFeedback[] _sfxPresets;
|
||
|
||
private Dictionary<string, MMF_Player> _presetMap;
|
||
private Dictionary<string, MMF_Player> _sfxMap;
|
||
|
||
private void Awake()
|
||
{
|
||
_presetMap = BuildMap(_namedPresets);
|
||
_sfxMap = BuildMap(_sfxPresets);
|
||
}
|
||
|
||
// ── IFeedbackPlayer ──────────────────────────────────────────────────────
|
||
public void PlayHit(HitWeight weight)
|
||
{
|
||
var player = weight switch
|
||
{
|
||
HitWeight.Light => _onHitLight,
|
||
HitWeight.Medium => _onHitMedium,
|
||
HitWeight.Heavy => _onHitHeavy,
|
||
_ => _onHitLight,
|
||
};
|
||
player?.PlayFeedbacks();
|
||
}
|
||
|
||
public void PlayParrySuccess() => _onParrySuccess?.PlayFeedbacks();
|
||
public void PlayTakeHit() => _onTakeHit?.PlayFeedbacks();
|
||
public void PlayDeath() => _onDeath?.PlayFeedbacks();
|
||
public void PlayHeal() => _onHeal?.PlayFeedbacks();
|
||
public void PlayLandImpact() => _onLandImpact?.PlayFeedbacks();
|
||
public void PlayAttackWhoosh() => _onAttackWhoosh?.PlayFeedbacks();
|
||
public void PlayJumpLaunch() => _onJumpLaunch?.PlayFeedbacks();
|
||
public void PlayFootstep()
|
||
{
|
||
_onFootstep?.PlayFeedbacks();
|
||
_footstepSoundPlayer?.Play();
|
||
}
|
||
|
||
public void TriggerPreset(string presetId)
|
||
{
|
||
if (_presetMap.TryGetValue(presetId, out var p))
|
||
p?.PlayFeedbacks();
|
||
else
|
||
Debug.LogWarning($"[PlayerFeedback] 未找到预设 '{presetId}'。");
|
||
}
|
||
|
||
public void PlaySFXById(string sfxId)
|
||
{
|
||
if (_sfxMap.TryGetValue(sfxId, out var p))
|
||
p?.PlayFeedbacks();
|
||
else
|
||
Debug.LogWarning($"[PlayerFeedback] 未找到 SFX 预设 '{sfxId}'。");
|
||
}
|
||
|
||
public void PlayFormSwitch(int formIndex)
|
||
{
|
||
if (_onFormSwitch != null && formIndex >= 0 && formIndex < _onFormSwitch.Length)
|
||
_onFormSwitch[formIndex]?.PlayFeedbacks();
|
||
}
|
||
|
||
// ── 辅助 ─────────────────────────────────────────────────────────────────
|
||
private static Dictionary<string, MMF_Player> BuildMap(NamedFeedback[] entries)
|
||
{
|
||
var map = new Dictionary<string, MMF_Player>();
|
||
if (entries == null) return map;
|
||
foreach (var e in entries)
|
||
{
|
||
if (!string.IsNullOrEmpty(e.id))
|
||
map[e.id] = e.player;
|
||
}
|
||
return map;
|
||
}
|
||
}
|
||
|
||
[System.Serializable]
|
||
public struct NamedFeedback
|
||
{
|
||
public string id;
|
||
public MMF_Player player;
|
||
}
|
||
}
|