88 lines
2.7 KiB
C#
88 lines
2.7 KiB
C#
|
using System;
|
||
|
using System.Collections;
|
||
|
using BlueWater.Players;
|
||
|
using BlueWater.Utility;
|
||
|
using Sirenix.OdinInspector;
|
||
|
using UnityEngine;
|
||
|
|
||
|
namespace BlueWater.Maps
|
||
|
{
|
||
|
public class BossMapTrigger : MonoBehaviour
|
||
|
{
|
||
|
public enum BossMapTriggerAnimation
|
||
|
{
|
||
|
Idle,
|
||
|
Animation
|
||
|
}
|
||
|
|
||
|
[SerializeField]
|
||
|
private SpineController _spineController;
|
||
|
|
||
|
public Action OnInteractionActive;
|
||
|
private Coroutine _bossMapTriggerCoroutineInstance;
|
||
|
|
||
|
private void Awake()
|
||
|
{
|
||
|
InitializeComponents();
|
||
|
}
|
||
|
|
||
|
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;
|
||
|
_spineController.PlayAnimation(BossMapTriggerAnimation.Idle.ToString(), true);
|
||
|
}
|
||
|
|
||
|
[Button("컴포넌트 초기화")]
|
||
|
private void InitializeComponents()
|
||
|
{
|
||
|
_spineController = GetComponent<SpineController>();
|
||
|
}
|
||
|
|
||
|
public void ResetTrigger()
|
||
|
{
|
||
|
_spineController.PlayAnimation(BossMapTriggerAnimation.Idle.ToString(), true);
|
||
|
if (_bossMapTriggerCoroutineInstance != null)
|
||
|
{
|
||
|
StopCoroutine(_bossMapTriggerCoroutineInstance);
|
||
|
_bossMapTriggerCoroutineInstance = null;
|
||
|
}
|
||
|
gameObject.SetActive(true);
|
||
|
}
|
||
|
|
||
|
private IEnumerator BossMapTriggerCoroutine()
|
||
|
{
|
||
|
var interactionAnimationName = BossMapTriggerAnimation.Animation.ToString();
|
||
|
_spineController.PlayAnimation(interactionAnimationName, false);
|
||
|
|
||
|
var animationStarted = false;
|
||
|
yield return StartCoroutine(_spineController.WaitForAnimationToRun(interactionAnimationName,
|
||
|
success => animationStarted = success));
|
||
|
|
||
|
if (!animationStarted)
|
||
|
{
|
||
|
yield break;
|
||
|
}
|
||
|
|
||
|
while (_spineController.IsComparingCurrentAnimation(interactionAnimationName)
|
||
|
&& _spineController.GetCurrentAnimationNormalizedTime() <= 1f)
|
||
|
{
|
||
|
yield return null;
|
||
|
}
|
||
|
|
||
|
gameObject.SetActive(false);
|
||
|
OnInteractionActive?.Invoke();
|
||
|
}
|
||
|
}
|
||
|
}
|