-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
60 lines
1.9 KiB
C#
60 lines
1.9 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.VFX;
|
|
|
|
using RR.Common.Audio;
|
|
using RR.Game2D.Behaviour;
|
|
using RR.Game2D.Entities;
|
|
using RR.Game2D.Core.Managers;
|
|
|
|
namespace RR.Game2D.FX
|
|
{
|
|
[RequireComponent(typeof(VisualEffect))]
|
|
public class CheckPointFX : MonoBehaviour
|
|
{
|
|
[SerializeField] private VisualEffect checkPointVFX;
|
|
[SerializeField] private SoundEffect checkpointSFX;
|
|
// [SerializeField] private Vector2 offset = Vector2.zero;
|
|
//[SerializeField] private Color color = Color.white;
|
|
|
|
private GameObject _player;
|
|
private Rigidbody2D _playerRB;
|
|
private PlayerController _playerController;
|
|
|
|
private void OnEnable()
|
|
{
|
|
throw new NotSupportedException("This script is deprecated, please use Checkpoint instead.");
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
CheckpointSystem.Instance.ActiveChanged -= PlayFX;
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
_player = GameManager.Instance.PlayerObj;
|
|
|
|
if (_player == null) _player = GameObject.FindGameObjectWithTag("Player");
|
|
|
|
_playerRB = _player.GetComponent<Rigidbody2D>();
|
|
_playerController = _player.GetComponent<PlayerController>();
|
|
|
|
checkPointVFX.Stop();
|
|
|
|
CheckpointSystem.Instance.ActiveChanged += PlayFX;
|
|
}
|
|
|
|
private void PlayFX(Checkpoint previous,Checkpoint current)
|
|
{
|
|
if (current == previous) return;
|
|
|
|
transform.position = current.transform.position;
|
|
transform.rotation = current.transform.rotation;
|
|
checkPointVFX.Play();
|
|
GameManager.Instance.Audio.PlaySfxAt(checkpointSFX.sound, transform.position,
|
|
checkpointSFX.volume, checkpointSFX.pitch);
|
|
checkPointVFX.Stop();
|
|
}
|
|
}
|
|
} |