Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
- Исправлено поведение игрока при падении с высоты и разворотах (устранен сильный отскок от углов) - Центрирован PolygonCollider2D по оси X на префабе character_defeat_4.prefab (m_Offset.x установлен в 0) - Упрощена форма PolygonCollider2D до симметричного выпуклого шестиугольника - Сохранен бэкап старого префаба игрока в Player_Old.prefab
114 lines
4.3 KiB
C#
114 lines
4.3 KiB
C#
using System.Collections;
|
|
using UnityEngine;
|
|
|
|
using RR.Game2D.Behaviour;
|
|
using RR.Game2D.Behaviour.ScriptableObjects;
|
|
using RR.Game2D.Core.Managers;
|
|
using RR.Game2D.FX;
|
|
using UnityEngine.VFX;
|
|
|
|
namespace RR.Game2D.Animations
|
|
{
|
|
public class EnemyAnimationEvents : MonoBehaviour, CreatureAnimationEvents
|
|
{
|
|
[SerializeField] private VisualEffectAsset deathVFX;
|
|
[SerializeField] private Vector3 deathVFXOffset = Vector3.zero;
|
|
|
|
private SFXAsset _stepSounds;
|
|
private SFXAsset _hurtSounds;
|
|
private Vector3 _vfxSpawnPoint;
|
|
private bool _deathScoreRegistered;
|
|
private Vector3 _creatureSize = Vector3.one;
|
|
|
|
private void Awake()
|
|
{
|
|
// Загружаем и кэшируем звуковые эффекты из контроллера врага
|
|
UpdateSFX();
|
|
Collider2D col = GetComponent<Collider2D>();
|
|
if (col) _creatureSize = col.bounds.size;
|
|
// Учитываем поворот объекта при вычислении смещения
|
|
Vector3 rotatedOffset = transform.rotation * deathVFXOffset;
|
|
_vfxSpawnPoint = (col ? col.bounds.center : transform.position) + rotatedOffset;
|
|
}
|
|
|
|
public void UpdateSFX()
|
|
{
|
|
// Кэшируем ссылки на звуковые эффекты из контроллера врага
|
|
EnemyController controller = GetComponent<EnemyController>();
|
|
if (controller != null && controller.sfxAsset != null)
|
|
{
|
|
_stepSounds = controller.sfxAsset.stepSounds;
|
|
_hurtSounds = controller.sfxAsset.hurtSounds;
|
|
}
|
|
}
|
|
|
|
public void OnDeath() {}
|
|
|
|
public void OnJump() {}
|
|
|
|
public void OnDeathBegin()
|
|
{
|
|
// Проигрываем звук получения урона
|
|
if (_hurtSounds && _hurtSounds.soundEffects.Length > 0)
|
|
GameManager.Instance.Audio.PlayRandomSfxAt(_hurtSounds.soundEffects, transform.position);
|
|
|
|
// Переводим врага на слой "No Collision"
|
|
gameObject.layer = LayerMask.NameToLayer("No Collision");
|
|
|
|
// Получаем компоненты
|
|
Rigidbody2D rb = GetComponent<Rigidbody2D>();
|
|
Collider2D col = GetComponent<Collider2D>();
|
|
EnemyController controller = GetComponent<EnemyController>();
|
|
EnemyFireScript fireScript = GetComponent<EnemyFireScript>();
|
|
|
|
// Отключаем скрипты и коллайдер
|
|
if (controller) controller.enabled = false;
|
|
if (fireScript) fireScript.enabled = false;
|
|
if (col)
|
|
{
|
|
// Учитываем поворот объекта при вычислении смещения
|
|
Vector3 rotatedOffset = transform.rotation * deathVFXOffset;
|
|
_vfxSpawnPoint = col.bounds.center + rotatedOffset;
|
|
|
|
col.enabled = false;
|
|
}
|
|
if (!rb) return;
|
|
|
|
// Останавливаем физику
|
|
rb.linearVelocity = Vector2.zero;
|
|
rb.bodyType = RigidbodyType2D.Kinematic;
|
|
}
|
|
|
|
public void OnDeathEnd()
|
|
{
|
|
if (!_deathScoreRegistered)
|
|
{
|
|
ScoreSystem.Instance?.RegisterEnemyKilled();
|
|
_deathScoreRegistered = true;
|
|
}
|
|
|
|
// Создаем визуальный эффект смерти
|
|
if (deathVFX)
|
|
{
|
|
MvpVFXSpawnSettings spawnSettings = new MvpVFXSpawnSettings
|
|
{
|
|
useScale3D = true,
|
|
scale3D = _creatureSize * 0.5f,
|
|
rotation = transform.rotation
|
|
};
|
|
MvpVFXUtility.Spawn(deathVFX, null, _vfxSpawnPoint, 1f, spawnSettings);
|
|
}
|
|
|
|
// Уничтожаем врага
|
|
Destroy(gameObject);
|
|
}
|
|
|
|
public void OnStep()
|
|
{
|
|
// Проигрываем звук шага
|
|
if (_stepSounds && _stepSounds.soundEffects.Length > 0)
|
|
GameManager.Instance.Audio.PlayRandomSfxAt(_stepSounds.soundEffects, transform.position);
|
|
}
|
|
}
|
|
}
|