129 lines
3.4 KiB
C#
129 lines
3.4 KiB
C#
using System;
|
|
using Animation;
|
|
using UnityEngine;
|
|
using UnityEngine.AI;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class PlayerController : MonoBehaviour
|
|
{
|
|
|
|
private AnimatorManager<AnimatorParam> _mAnimator;
|
|
private NavMeshAgent _agent;
|
|
private Movement_Ground _movement;
|
|
|
|
private Status_Player _status;
|
|
private Vector3 _destPos;
|
|
|
|
|
|
|
|
// --- Enum 정의 ---
|
|
enum AnimatorParam
|
|
{
|
|
speed,
|
|
atk_speed,
|
|
attack,
|
|
run,
|
|
}
|
|
|
|
enum PlayerBehavior
|
|
{
|
|
Idle,
|
|
Move,
|
|
Attack,
|
|
Die
|
|
}
|
|
|
|
private PlayerBehavior _behavior = PlayerBehavior.Idle;
|
|
private PlayerBehavior Behavior
|
|
{
|
|
get { return _behavior; }
|
|
set
|
|
{
|
|
_behavior = value;
|
|
switch (_behavior)
|
|
{
|
|
case PlayerBehavior.Die:
|
|
case PlayerBehavior.Idle:
|
|
_mAnimator.SetValue(AnimatorParam.speed, 0);
|
|
break;
|
|
case PlayerBehavior.Move:
|
|
_mAnimator.SetValue(AnimatorParam.attack, false);
|
|
break;
|
|
case PlayerBehavior.Attack:
|
|
_mAnimator.SetValue(AnimatorParam.attack, true);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// --- 초기화 ---
|
|
private void Awake()
|
|
{
|
|
_mAnimator = new AnimatorManager<AnimatorParam>(GetComponent<Animator>());
|
|
_movement = gameObject.AddComponent<Movement_Ground>();
|
|
_status = gameObject.GetComponent<Status_Player>();
|
|
|
|
if (_status != null && _movement != null) _movement.SetSpeed(_status.MoveSpeed);
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
Manager.Input.MouseAction -= OnMouseClicked;
|
|
Manager.Input.MouseAction += OnMouseClicked;
|
|
Manager.Input.KeyAction -= OnKeyboardInput;
|
|
Manager.Input.KeyAction += OnKeyboardInput;
|
|
SetAnimator();
|
|
}
|
|
|
|
void SetAnimator()
|
|
{
|
|
if (_status != null)
|
|
{
|
|
_mAnimator.SetValue(AnimatorParam.atk_speed, _status.AtkSpeed);
|
|
}
|
|
}
|
|
|
|
// --- 매 프레임 실행 ---
|
|
void Update()
|
|
{
|
|
Debug.Log($"{_behavior}");
|
|
if (_agent != null && _movement != null) _mAnimator.SetValue(AnimatorParam.speed, _movement.GetCurrentSpeed());
|
|
|
|
if (_behavior == PlayerBehavior.Move)
|
|
{
|
|
if (!_movement.IsMoving()) Behavior = PlayerBehavior.Idle;
|
|
else _mAnimator.SetValue(AnimatorParam.speed,_movement.GetCurrentSpeed());
|
|
}
|
|
}
|
|
|
|
void OnMouseClicked(Define.MouseEvent evt)
|
|
{
|
|
if (Behavior == PlayerBehavior.Die) return;
|
|
|
|
RaycastHit hit;
|
|
Ray ray = Camera.main.ScreenPointToRay(Mouse.current.position.ReadValue());
|
|
|
|
int layerMask = LayerMask.GetMask("Ground");
|
|
if (!Physics.Raycast(ray, out hit, 100.0f, layerMask))
|
|
return;
|
|
|
|
_destPos = hit.point;
|
|
|
|
switch (evt)
|
|
{
|
|
case Define.MouseEvent.Click:
|
|
case Define.MouseEvent.Down:
|
|
_movement.SetDestination(_destPos);
|
|
Behavior = PlayerBehavior.Move;
|
|
break;
|
|
case Define.MouseEvent.Press:
|
|
if (Behavior == PlayerBehavior.Move) _movement.SetDestination(_destPos);
|
|
break;
|
|
}
|
|
}
|
|
|
|
void OnKeyboardInput()
|
|
{
|
|
// 키보드 입력이 필요할 경우 여기에 로직 구현
|
|
}
|
|
} |