Danil Iarosh 5bafc385da feat(audio): increase SFX pool size and preload audio data
- Increased SFX pool size from 8 to 16 in AudioManager
- Enabled preloadAudioData for multiple SFX files
- Removed unused VisualScripting import from Checkpoint script
- Reordered using statements in several scripts for consistency
- Added CoinCollectible component to Coin prefab with pickup effects
- Updated sorting layers and mesh LOD settings in Coin prefabs
- Fixed typo in Interfaces.cs: optionaAttachPoint to optionalAttachPoint
- Modified AddCoin method to accept count parameter and handle coin overflow
- Moved projectile scripts (BasicProjectile, EnemyBasicProjectile, PhysicsProjectile, PickableProjectile)
- Cleaned up unused namespaces and imports across various scripts
2025-10-30 16:39:15 +03:00

74 lines
2.6 KiB
C#

using System;
using UnityEngine;
using UnityEngine.VFX;
using RR.Common.Audio;
using RR.Game2D.Core.Managers;
namespace RR.Game2D.Entities
{
[RequireComponent(typeof(Collider2D))]
public class Checkpoint : MonoBehaviour
{
public string checkpointId;
public Vector2 spawnForward = Vector2.right;
[SerializeField] private string playerTag = "Player";
[Header("FX (необязательно)")]
public VisualEffect activateVfx;
public SoundEffect activateSfx;
private bool _activated;
private Collider2D _col;
private void Awake()
{
_col = GetComponent<Collider2D>();
_col.isTrigger = true;
if (String.IsNullOrWhiteSpace(checkpointId))
checkpointId = gameObject.name;
if (!activateVfx.enabled) activateVfx.enabled = true;
activateVfx.Stop();
}
private void OnTriggerEnter2D(Collider2D other)
{
if (_activated) return;
// Определяем объект-источник (учтём Rigidbody, если он есть)
var source = other.attachedRigidbody ? other.attachedRigidbody.gameObject : other.gameObject;
if (!source.CompareTag(playerTag)) return;
_activated = true;
if (CheckpointSystem.Instance)
CheckpointSystem.Instance.SetActive(this);
if (activateVfx)
{
activateVfx.transform.position = _col.bounds.center;
activateVfx.Play();
}
if (activateSfx.sound != null) GameManager.Instance.Audio.PlaySfxAt(activateSfx.sound,
_col.bounds.center,
activateSfx.volume,
activateSfx.pitch);
}
private void OnTriggerExit2D(Collider2D other)
{
var source = other.attachedRigidbody ? other.attachedRigidbody.gameObject : other.gameObject;
if (!source.CompareTag(playerTag)) return;
if (activateVfx) activateVfx.Stop();
}
public Vector3 GetSpawnPosition() => transform.position;
public Vector2 GetForward() => spawnForward.sqrMagnitude > 0.0001f ? spawnForward.normalized : Vector2.right;
// Для визуалки можно сделать метод Highlight(bool on) и менять спрайт/свет
}
}