58 lines
1.7 KiB
C#
58 lines
1.7 KiB
C#
|
using System.Collections;
|
||
|
using BlueWater.Uis;
|
||
|
using BlueWater.Utility;
|
||
|
using Sirenix.OdinInspector;
|
||
|
using UnityEngine;
|
||
|
|
||
|
namespace BlueWater.Maps
|
||
|
{
|
||
|
public class MapPortal : MonoBehaviour
|
||
|
{
|
||
|
[SerializeField]
|
||
|
private Collider _collider;
|
||
|
|
||
|
[SerializeField, Required]
|
||
|
private Transform _targetTransform;
|
||
|
|
||
|
[SerializeField]
|
||
|
private Vector2 _fadeInOutTime = new(1f, 1f);
|
||
|
|
||
|
[SerializeField]
|
||
|
private float _delayAfterFadeIn = 0.5f;
|
||
|
|
||
|
[SerializeField]
|
||
|
private Color _fadeColor = new(0f, 0f, 0f, 0f);
|
||
|
|
||
|
private Coroutine _portalCoroutineInstance;
|
||
|
|
||
|
private void Awake()
|
||
|
{
|
||
|
InitializeComponents();
|
||
|
}
|
||
|
|
||
|
[Button("컴포넌트 초기화")]
|
||
|
private void InitializeComponents()
|
||
|
{
|
||
|
_collider = GetComponent<Collider>();
|
||
|
}
|
||
|
|
||
|
private void OnTriggerEnter(Collider other)
|
||
|
{
|
||
|
if (!other.CompareTag("Player") || !_targetTransform) return;
|
||
|
|
||
|
Utils.StartUniqueCoroutine(this, ref _portalCoroutineInstance, PortalCoroutine(other));
|
||
|
}
|
||
|
|
||
|
private IEnumerator PortalCoroutine(Collider other)
|
||
|
{
|
||
|
PlayerInputKeyManager.Instance.DisableCurrentPlayerInput();
|
||
|
CombatUiManager.Instance.FadeInOut(_fadeInOutTime.x, _fadeInOutTime.y, _fadeColor, _delayAfterFadeIn);
|
||
|
yield return new WaitForSeconds(_fadeInOutTime.x);
|
||
|
|
||
|
other.transform.position = _targetTransform.position;
|
||
|
yield return new WaitForSeconds(_delayAfterFadeIn + _fadeInOutTime.y);
|
||
|
|
||
|
PlayerInputKeyManager.Instance.EnableCurrentPlayerInput();
|
||
|
}
|
||
|
}
|
||
|
}
|