55 lines
3.7 KiB
C#
55 lines
3.7 KiB
C#
|
|
using UnityEngine; // 유니티 기능을 불러올거에요 -> UnityEngine을
|
|||
|
|
using UnityEngine.AI; // 내비게이션 기능을 불러올거에요 -> UnityEngine.AI를
|
|||
|
|
using System.Collections; // 코루틴을 사용할거에요 -> System.Collections를
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 화상, 독, 슬로우 등의 상태이상을 전담 처리하는 클래스
|
|||
|
|
/// </summary>
|
|||
|
|
public class StatusEffectProcessor // 클래스를 선언할거에요 -> 상태이상 로직을 담당하는 클래스를
|
|||
|
|
{
|
|||
|
|
private readonly MonoBehaviour _owner; // 변수를 선언할거에요 -> 코루틴 실행 주체를
|
|||
|
|
private readonly IDamageable _damageable; // 변수를 선언할거에요 -> 데미지 인터페이스를
|
|||
|
|
private readonly NavMeshAgent _agent; // 변수를 선언할거에요 -> 이동 에이전트를
|
|||
|
|
private readonly Animator _animator; // 변수를 선언할거에요 -> 애니메이터를
|
|||
|
|
|
|||
|
|
public StatusEffectProcessor(MonoBehaviour owner, IDamageable damageable, NavMeshAgent agent, Animator animator) // 생성자를 만들거에요 -> 의존성 주입을 위한
|
|||
|
|
{
|
|||
|
|
_owner = owner; // 값을 저장할거에요 -> 주인을
|
|||
|
|
_damageable = damageable; // 값을 저장할거에요 -> 데미지 대상을
|
|||
|
|
_agent = agent; // 값을 저장할거에요 -> 에이전트를
|
|||
|
|
_animator = animator; // 값을 저장할거에요 -> 애니메이터를
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void ApplyBurn(float damage, float duration) => _owner.StartCoroutine(BurnRoutine(damage, duration)); // 함수를 선언할거에요 -> 화상 코루틴 시작을
|
|||
|
|
public void ApplySlow(float amount, float duration) => _owner.StartCoroutine(SlowRoutine(amount, duration)); // 함수를 선언할거에요 -> 슬로우 코루틴 시작을
|
|||
|
|
public void ApplyShock(float damage, float duration) { _damageable.TakeDamage(damage); _owner.StartCoroutine(StunRoutine(duration)); } // 함수를 선언할거에요 -> 충격과 스턴 시작을
|
|||
|
|
|
|||
|
|
private IEnumerator BurnRoutine(float damage, float duration) // 코루틴 함수를 정의할거에요 -> 화상 로직을
|
|||
|
|
{
|
|||
|
|
float elapsed = 0f; // 변수를 초기화할거에요 -> 경과 시간을
|
|||
|
|
while (elapsed < duration) // 반복할거에요 -> 지속 시간 동안
|
|||
|
|
{
|
|||
|
|
_damageable.TakeDamage(damage * 0.5f); // 실행할거에요 -> 0.5초치 데미지를
|
|||
|
|
yield return new WaitForSeconds(0.5f); // 기다릴거에요 -> 0.5초를
|
|||
|
|
elapsed += 0.5f; // 값을 더할거에요 -> 경과 시간에
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private IEnumerator SlowRoutine(float amount, float duration) // 코루틴 함수를 정의할거에요 -> 슬로우 로직을
|
|||
|
|
{
|
|||
|
|
if (_agent == null) yield break; // 조건이 맞으면 종료할거에요 -> 에이전트가 없으면
|
|||
|
|
float orgSpeed = _agent.speed; // 값을 저장할거에요 -> 원래 속도를
|
|||
|
|
_agent.speed *= (1f - Mathf.Clamp01(amount / 100f)); // 값을 바꿀거에요 -> 속도를 줄여서
|
|||
|
|
yield return new WaitForSeconds(duration); // 기다릴거에요 -> 지속 시간만큼
|
|||
|
|
_agent.speed = orgSpeed; // 값을 복구할거에요 -> 원래 속도로
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private IEnumerator StunRoutine(float duration) // 코루틴 함수를 정의할거에요 -> 스턴 로직을
|
|||
|
|
{
|
|||
|
|
if (_agent != null) _agent.isStopped = true; // 명령을 내릴거에요 -> 이동 정지를
|
|||
|
|
if (_animator != null) _animator.speed = 0; // 값을 바꿀거에요 -> 애니 속도를 0으로
|
|||
|
|
yield return new WaitForSeconds(duration); // 기다릴거에요 -> 스턴 시간만큼
|
|||
|
|
if (_agent != null && _agent.isOnNavMesh) _agent.isStopped = false; // 명령을 내릴거에요 -> 이동 재개를
|
|||
|
|
if (_animator != null) _animator.speed = 1; // 값을 바꿀거에요 -> 애니 속도 복구를
|
|||
|
|
}
|
|||
|
|
}
|