2024-06-21 22:11:53 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
2024-06-24 15:05:05 +00:00
|
|
|
using BlueWater.Audios;
|
2024-06-21 22:11:53 +00:00
|
|
|
using BlueWater.Players;
|
|
|
|
using BlueWater.Utility;
|
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace BlueWater.Maps
|
|
|
|
{
|
|
|
|
public class BossMapTrigger : MonoBehaviour
|
|
|
|
{
|
|
|
|
public enum BossMapTriggerAnimation
|
|
|
|
{
|
|
|
|
Idle,
|
2024-06-24 12:11:56 +00:00
|
|
|
Hold,
|
|
|
|
Repeat
|
2024-06-21 22:11:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private SpineController _spineController;
|
|
|
|
|
|
|
|
public Action OnInteractionActive;
|
|
|
|
private Coroutine _bossMapTriggerCoroutineInstance;
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
InitializeComponents();
|
|
|
|
}
|
|
|
|
|
2024-06-24 12:11:56 +00:00
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
_spineController.PlayAnimation(BossMapTriggerAnimation.Idle.ToString(), false);
|
|
|
|
}
|
|
|
|
|
2024-06-21 22:11:53 +00:00
|
|
|
private void OnTriggerEnter(Collider other)
|
|
|
|
{
|
|
|
|
if (!other.CompareTag("Player")) return;
|
|
|
|
|
|
|
|
Utils.StartUniqueCoroutine(this, ref _bossMapTriggerCoroutineInstance, BossMapTriggerCoroutine());
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnTriggerExit(Collider other)
|
|
|
|
{
|
|
|
|
if (!other.CompareTag("Player")) return;
|
|
|
|
|
|
|
|
if (_bossMapTriggerCoroutineInstance == null) return;
|
|
|
|
|
|
|
|
StopCoroutine(_bossMapTriggerCoroutineInstance);
|
|
|
|
_bossMapTriggerCoroutineInstance = null;
|
2024-06-24 12:11:56 +00:00
|
|
|
_spineController.PlayAnimation(BossMapTriggerAnimation.Idle.ToString(), false);
|
2024-06-21 22:11:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Button("컴포넌트 초기화")]
|
|
|
|
private void InitializeComponents()
|
|
|
|
{
|
|
|
|
_spineController = GetComponent<SpineController>();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ResetTrigger()
|
|
|
|
{
|
2024-06-24 12:11:56 +00:00
|
|
|
_spineController.PlayAnimation(BossMapTriggerAnimation.Idle.ToString(), false);
|
2024-06-21 22:11:53 +00:00
|
|
|
if (_bossMapTriggerCoroutineInstance != null)
|
|
|
|
{
|
|
|
|
StopCoroutine(_bossMapTriggerCoroutineInstance);
|
|
|
|
_bossMapTriggerCoroutineInstance = null;
|
|
|
|
}
|
|
|
|
gameObject.SetActive(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private IEnumerator BossMapTriggerCoroutine()
|
|
|
|
{
|
2024-06-24 15:05:05 +00:00
|
|
|
AudioManager.Instance.PlaySfx("Shining");
|
2024-06-24 12:11:56 +00:00
|
|
|
var animationTrack = _spineController.PlayAnimation( BossMapTriggerAnimation.Hold.ToString(), false);
|
2024-06-23 09:38:19 +00:00
|
|
|
if (animationTrack == null)
|
2024-06-21 22:11:53 +00:00
|
|
|
{
|
2024-06-23 09:38:19 +00:00
|
|
|
Debug.LogError("BossMapTriggerCoroutine animationTrack is null error");
|
2024-06-21 22:11:53 +00:00
|
|
|
yield break;
|
|
|
|
}
|
|
|
|
|
2024-06-23 09:38:19 +00:00
|
|
|
yield return new WaitUntil(() => animationTrack.IsComplete);
|
2024-06-21 22:11:53 +00:00
|
|
|
|
|
|
|
gameObject.SetActive(false);
|
|
|
|
OnInteractionActive?.Invoke();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|