-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
45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
using System;
|
|
using RR.Game2D.Behaviour;
|
|
using RR.Game2D.Behaviour.ScriptableObjects;
|
|
using RR.Game2D.Core.Managers;
|
|
using UnityEngine;
|
|
|
|
namespace RR.Common.Audio
|
|
{
|
|
public class LevelPlayerSFX : MonoBehaviour
|
|
{
|
|
public static LevelPlayerSFX Instance {get; private set; }
|
|
|
|
[SerializeField] private SFXAsset levelStepSounds;
|
|
|
|
public event Action SFXChanged;
|
|
|
|
private void OnEnable() => GameManager.Instance.PlayerSpawned += OnPlayerSpawned;
|
|
|
|
private void OnDisable() => GameManager.Instance.PlayerSpawned -= OnPlayerSpawned;
|
|
|
|
private void Awake()
|
|
{
|
|
if (Instance != null && Instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
|
|
Instance = this;
|
|
DontDestroyOnLoad(gameObject);
|
|
}
|
|
|
|
private void OnPlayerSpawned(GameObject obj)
|
|
{
|
|
PlayerController playerController = obj.GetComponent<PlayerController>();
|
|
|
|
if (playerController == null) return;
|
|
if (levelStepSounds != null)
|
|
{
|
|
playerController.stepSounds = levelStepSounds;
|
|
SFXChanged?.Invoke();
|
|
}
|
|
}
|
|
}
|
|
} |