-Add LevelSpecificPlayerSFX prefabs for levels 1-1 and 1-2 -Configure checkpoints to activate sound effects, including pitch, volume, and audio editing -Rename the checkpoint effect object to Checkpoint VFX -Update the audio manager, the default value of the music target volume is 0.2 -Add SoundEffect structure to support sound parameter configuration -Optimize audio source creation and crossfade logic -Remove the old music control components and use the new audio management method
66 lines
2.1 KiB
C#
66 lines
2.1 KiB
C#
using System;
|
|
using RR.Common.Audio;
|
|
using RR.Common.Managers;
|
|
using RR.Game2D.Behaviour;
|
|
using RR.Game2D.Behaviour.ScriptableObjects;
|
|
using RR.Game2D.Core.Managers;
|
|
using UnityEngine;
|
|
|
|
namespace RR.Game2D.Animations
|
|
{
|
|
public class PlayerAnimationEvents : MonoBehaviour
|
|
{
|
|
private SFXAsset _stepSounds;
|
|
private SFXAsset _hurtSounds;
|
|
private SFXAsset _jumpSounds;
|
|
private Rigidbody2D _rb;
|
|
|
|
private void OnEnable() => LevelPlayerSFX.Instance.SFXChanged += UpdateSFX;
|
|
|
|
private void OnDisable() => LevelPlayerSFX.Instance.SFXChanged -= UpdateSFX;
|
|
|
|
private void Awake()
|
|
{
|
|
PlayerController controller = GetComponent<PlayerController>();
|
|
|
|
UpdateSFX();
|
|
|
|
_rb = GetComponent<Rigidbody2D>();
|
|
}
|
|
|
|
private void UpdateSFX()
|
|
{
|
|
PlayerController controller = GetComponent<PlayerController>();
|
|
_stepSounds = controller.stepSounds;
|
|
_hurtSounds = controller.hurtSounds;
|
|
_jumpSounds = controller.jumpSounds;
|
|
}
|
|
|
|
public void OnDeathBegin()
|
|
{
|
|
if (_hurtSounds && _hurtSounds.soundEffects.Length > 0)
|
|
GameManager.Instance.Audio.PlayRandomSfxAt(_hurtSounds.soundEffects, transform.position);
|
|
}
|
|
|
|
public void OnDeathEnd()
|
|
{
|
|
Animator animator = GetComponent<Animator>();
|
|
animator.ResetTrigger("Death");
|
|
gameObject.layer = LayerMask.NameToLayer("Default");
|
|
_rb.constraints = RigidbodyConstraints2D.FreezeRotation;
|
|
GameManager.Instance.RespawnPlayer();
|
|
}
|
|
|
|
public void Step()
|
|
{
|
|
if (_stepSounds && _stepSounds.soundEffects.Length > 0)
|
|
GameManager.Instance.Audio.PlayRandomSfxAt(_stepSounds.soundEffects, transform.position);
|
|
}
|
|
|
|
public void Jump()
|
|
{
|
|
if (_jumpSounds && _jumpSounds.soundEffects.Length > 0)
|
|
GameManager.Instance.Audio.PlayRandomSfxAt(_jumpSounds.soundEffects, transform.position);
|
|
}
|
|
}
|
|
} |