2024-06-24 09:54:47 +00:00
|
|
|
using System.Collections;
|
2024-06-23 20:37:15 +00:00
|
|
|
using BlueWater.Audios;
|
2024-06-29 15:59:31 +00:00
|
|
|
using BlueWater.Items;
|
2024-06-23 20:37:15 +00:00
|
|
|
using BlueWater.Players;
|
2024-06-24 09:54:47 +00:00
|
|
|
using BlueWater.Utility;
|
2024-06-23 20:37:15 +00:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace BlueWater
|
|
|
|
{
|
|
|
|
public class SpineDamageableProps : DamageableProps
|
|
|
|
{
|
|
|
|
[SerializeField]
|
|
|
|
private SpineController _spineController;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private string _idleAnimationName;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private string _touchAnimationName;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private string _dieAnimationName;
|
|
|
|
|
2024-06-24 09:54:47 +00:00
|
|
|
private Coroutine _touchCoroutineInstance;
|
|
|
|
|
2024-06-23 20:37:15 +00:00
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
_spineController = GetComponent<SpineController>();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnEnable()
|
|
|
|
{
|
|
|
|
base.OnEnable();
|
|
|
|
_spineController.PlayAnimation(_idleAnimationName, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
|
|
{
|
|
|
|
if (!other.CompareTag("Player") || CurrentHealthPoint <= 0) return;
|
|
|
|
|
2024-06-24 09:54:47 +00:00
|
|
|
Utils.StartUniqueCoroutine(this, ref _touchCoroutineInstance, TouchCoroutine());
|
2024-06-23 20:37:15 +00:00
|
|
|
}
|
2024-06-24 09:54:47 +00:00
|
|
|
|
|
|
|
private IEnumerator TouchCoroutine()
|
2024-06-23 20:37:15 +00:00
|
|
|
{
|
2024-06-24 09:54:47 +00:00
|
|
|
var touchTrack = _spineController.PlayAnimation(_touchAnimationName, false);
|
|
|
|
while (!touchTrack.IsComplete)
|
|
|
|
{
|
|
|
|
if (CurrentHealthPoint == 0) yield break;
|
|
|
|
|
|
|
|
yield return null;
|
|
|
|
}
|
2024-06-23 20:37:15 +00:00
|
|
|
_spineController.PlayAnimation(_idleAnimationName, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Die()
|
|
|
|
{
|
|
|
|
if (!string.IsNullOrEmpty(DieSfxName))
|
|
|
|
{
|
|
|
|
AudioManager.Instance.PlaySfx(DieSfxName);
|
|
|
|
}
|
|
|
|
|
|
|
|
_spineController.PlayAnimation(_dieAnimationName, false);
|
2024-06-29 15:59:31 +00:00
|
|
|
|
2024-08-22 10:39:15 +00:00
|
|
|
if (!string.IsNullOrEmpty(CharacterIdx))
|
2024-06-29 15:59:31 +00:00
|
|
|
{
|
|
|
|
ItemManager.Instance.ItemDropRandomPosition(CharacterIdx, transform.position, 0f);
|
|
|
|
}
|
2024-06-23 20:37:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|