액션 및 인터랙션 정의 및 기존 인터랙션 및 채광 코드 구조 개선
This commit is contained in:
54
Assets/Scripts/Player/PlayerActionHandler.cs
Normal file
54
Assets/Scripts/Player/PlayerActionHandler.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class PlayerActionHandler : NetworkBehaviour
|
||||
{
|
||||
private bool _isBusy;
|
||||
public bool IsBusy => _isBusy;
|
||||
private Animator _animator;
|
||||
|
||||
void Awake() => _animator = GetComponent<Animator>();
|
||||
|
||||
// [통로 1] 인터랙션 실행 (대상 중심)
|
||||
public void PerformInteraction(IInteractable target)
|
||||
{
|
||||
if (_isBusy || target == null) return;
|
||||
|
||||
// 대상으로부터 정보를 가져옴
|
||||
var provider = (target as MonoBehaviour).GetComponent<IActionProvider>();
|
||||
ActionDescriptor desc = provider?.GetActionDescriptor();
|
||||
|
||||
StartCoroutine(InteractionRoutine(desc, target));
|
||||
}
|
||||
|
||||
// [통로 2] 액션 실행 (행동 중심)
|
||||
public void PerformAction(PlayerActionData actionData, GameObject target = null)
|
||||
{
|
||||
if (_isBusy || actionData == null) return;
|
||||
|
||||
StartCoroutine(ActionRoutine(actionData, target));
|
||||
}
|
||||
|
||||
private IEnumerator InteractionRoutine(ActionDescriptor desc, IInteractable target)
|
||||
{
|
||||
_isBusy = true;
|
||||
if (desc != null) _animator.SetTrigger(desc.animTrigger);
|
||||
|
||||
target.Interact(gameObject); // 로직 실행
|
||||
|
||||
yield return new WaitForSeconds(desc?.duration ?? 0.1f);
|
||||
_isBusy = false;
|
||||
}
|
||||
|
||||
private IEnumerator ActionRoutine(PlayerActionData data, GameObject target)
|
||||
{
|
||||
_isBusy = true;
|
||||
_animator.SetTrigger(data.animTrigger);
|
||||
|
||||
data.ExecuteEffect(gameObject, target); // 로직 실행
|
||||
|
||||
yield return new WaitForSeconds(data.duration);
|
||||
_isBusy = false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user