[Combat] 2D맵 베이스용 Player 테스트 중
This commit is contained in:
parent
12e5fb6ea9
commit
dba82d7d05
16055
BlueWater/Assets/01.Scenes/02.Combat_2D.unity
Normal file
16055
BlueWater/Assets/01.Scenes/02.Combat_2D.unity
Normal file
File diff suppressed because it is too large
Load Diff
7
BlueWater/Assets/01.Scenes/02.Combat_2D.unity.meta
Normal file
7
BlueWater/Assets/01.Scenes/02.Combat_2D.unity.meta
Normal file
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e017f8a5de0968e419c32487a4669f2c
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d89e3b89ea07ecd4185fb2c88d31e698
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,42 @@
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEngine;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace BlueWaterProject
|
||||
{
|
||||
public class CombatAnimator : MonoBehaviour
|
||||
{
|
||||
[Required] public Animator animator;
|
||||
|
||||
private static readonly int IsMovingHash = Animator.StringToHash("isMoving");
|
||||
private static readonly int XDirectionHash = Animator.StringToHash("xDirection");
|
||||
private static readonly int ZDirectionHash = Animator.StringToHash("zDirection");
|
||||
private static readonly int IsDashingHash = Animator.StringToHash("isDashing");
|
||||
|
||||
[Button("셋팅 초기화")]
|
||||
private void InitSetting()
|
||||
{
|
||||
animator = GetComponentInChildren<Animator>();
|
||||
}
|
||||
|
||||
public void SetIsMoving(bool value)
|
||||
{
|
||||
animator.SetBool(IsMovingHash, value);
|
||||
}
|
||||
|
||||
public void SetXDirection(float value)
|
||||
{
|
||||
animator.SetFloat(XDirectionHash, value);
|
||||
}
|
||||
|
||||
public void SetZDirection(float value)
|
||||
{
|
||||
animator.SetFloat(ZDirectionHash, value);
|
||||
}
|
||||
|
||||
public void SetIsDash(bool value)
|
||||
{
|
||||
animator.SetBool(IsDashingHash, value);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 032fb61259732644993e9ef0f4b7eb7c
|
@ -0,0 +1,53 @@
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace BlueWaterProject
|
||||
{
|
||||
public class CombatInput : MonoBehaviour
|
||||
{
|
||||
[Required] public PlayerInput playerInput;
|
||||
|
||||
public delegate void MoveInput(Vector2 movementInput);
|
||||
public event MoveInput OnMoveInputReceived;
|
||||
|
||||
public delegate void DashInput();
|
||||
public event DashInput OnDashInputReceived;
|
||||
|
||||
public delegate void AttackInput(InputAction.CallbackContext context);
|
||||
public event AttackInput OnAttackInputReceived;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
playerInput.actions.FindAction("Attack").performed += OnAttackEvent;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
playerInput.actions.FindAction("Attack").performed -= OnAttackEvent;
|
||||
}
|
||||
|
||||
[Button("셋팅 초기화")]
|
||||
private void InitSetting()
|
||||
{
|
||||
playerInput = GetComponent<PlayerInput>();
|
||||
}
|
||||
|
||||
private void OnMove(InputValue value)
|
||||
{
|
||||
var movementInput = value.Get<Vector2>();
|
||||
OnMoveInputReceived?.Invoke(movementInput);
|
||||
}
|
||||
|
||||
private void OnDash()
|
||||
{
|
||||
OnDashInputReceived?.Invoke();
|
||||
}
|
||||
|
||||
private void OnAttackEvent(InputAction.CallbackContext context)
|
||||
{
|
||||
OnAttackInputReceived?.Invoke(context);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f5c3b32dc7f64e43a9cd93b4ef9a424
|
@ -0,0 +1,144 @@
|
||||
using System.Collections;
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEngine;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace BlueWaterProject
|
||||
{
|
||||
public class CombatMovement : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Rigidbody rb;
|
||||
[SerializeField] private Transform visualLook;
|
||||
[HideInInspector] public CombatAnimator combatAnimator;
|
||||
|
||||
[Range(1f, 10f), Tooltip("이동 속도")]
|
||||
[SerializeField] private float moveSpeed = 7f;
|
||||
|
||||
// Dash
|
||||
[Range(1f, 50f), Tooltip("대쉬 속도")]
|
||||
[SerializeField] private float dashSpeed = 20f;
|
||||
|
||||
[Range(0.1f, 1f), Tooltip("대쉬 시간")]
|
||||
[SerializeField] private float dashTime = 0.2f;
|
||||
|
||||
[Range(0f, 5f), Tooltip("대쉬 쿨타임")]
|
||||
[SerializeField] private float dashCooldown = 0.5f;
|
||||
|
||||
// Ground
|
||||
[Range(0.1f, 10.0f), Tooltip("지면 감지 거리")]
|
||||
[SerializeField] private float groundCheckDistance = 2.0f;
|
||||
|
||||
[SerializeField] private LayerMask groundLayer;
|
||||
|
||||
private Animator Animator => combatAnimator.animator;
|
||||
|
||||
private Vector3 currentMoveDirection;
|
||||
private Vector3 previousMoveDirection = Vector3.back;
|
||||
private float finalSpeed;
|
||||
|
||||
private bool isMoving;
|
||||
private bool enableDash = true;
|
||||
private bool isDashing;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
MoveAnimation();
|
||||
FlipVisualLook();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
//CheckGround();
|
||||
|
||||
if (isDashing) return;
|
||||
|
||||
var finalVelocity = rb.position + currentMoveDirection * (moveSpeed * Time.fixedDeltaTime);
|
||||
rb.MovePosition(finalVelocity);
|
||||
}
|
||||
|
||||
[Button("셋팅 초기화")]
|
||||
private void InitSetting()
|
||||
{
|
||||
rb = GetComponent<Rigidbody>();
|
||||
visualLook = GetComponentInChildren<Transform>();
|
||||
}
|
||||
|
||||
public void InputMovementValue(Vector2 movementInput)
|
||||
{
|
||||
currentMoveDirection = new Vector3(movementInput.x, 0, movementInput.y).normalized;
|
||||
if (currentMoveDirection != Vector3.zero)
|
||||
{
|
||||
previousMoveDirection = currentMoveDirection;
|
||||
}
|
||||
isMoving = currentMoveDirection != Vector3.zero;
|
||||
}
|
||||
|
||||
public void HandleDash()
|
||||
{
|
||||
if (!enableDash || isDashing) return;
|
||||
|
||||
StartCoroutine(nameof(DashCoroutine));
|
||||
}
|
||||
|
||||
private IEnumerator DashCoroutine()
|
||||
{
|
||||
var dashDirection = previousMoveDirection;
|
||||
isDashing = true;
|
||||
enableDash = false;
|
||||
combatAnimator.SetIsDash(true);
|
||||
|
||||
var elapsedTime = 0f;
|
||||
while (!Animator.GetCurrentAnimatorStateInfo(0).IsName("DashState"))
|
||||
{
|
||||
elapsedTime += Time.deltaTime;
|
||||
|
||||
if (elapsedTime >= 1f)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
var animationLength = Animator.GetCurrentAnimatorStateInfo(0).length;
|
||||
Animator.speed = animationLength / dashTime;
|
||||
|
||||
while (Animator.GetCurrentAnimatorStateInfo(0).IsName("DashState") &&
|
||||
Animator.GetCurrentAnimatorStateInfo(0).normalizedTime < 1f)
|
||||
{
|
||||
var finalVelocity = rb.position + dashDirection * (dashSpeed * Time.fixedDeltaTime);
|
||||
rb.MovePosition(finalVelocity);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
Animator.speed = 1f;
|
||||
isDashing = false;
|
||||
combatAnimator.SetIsDash(false);
|
||||
|
||||
StartCoroutine(Utils.CoolDown(dashCooldown, () => enableDash = true));
|
||||
}
|
||||
|
||||
private void MoveAnimation()
|
||||
{
|
||||
combatAnimator.SetIsMoving(isMoving);
|
||||
if (isMoving)
|
||||
{
|
||||
combatAnimator.SetXDirection(previousMoveDirection.x);
|
||||
combatAnimator.SetZDirection(previousMoveDirection.z);
|
||||
}
|
||||
}
|
||||
|
||||
private void FlipVisualLook()
|
||||
{
|
||||
var localScale = visualLook.localScale;
|
||||
localScale.x = previousMoveDirection.x switch
|
||||
{
|
||||
> 0.01f => Mathf.Abs(localScale.x),
|
||||
< -0.01f => -Mathf.Abs(localScale.x),
|
||||
_ => localScale.x
|
||||
};
|
||||
visualLook.localScale = localScale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 58af0a680d0fc284ab994540f528bc38
|
@ -0,0 +1,39 @@
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEngine;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace BlueWaterProject
|
||||
{
|
||||
public class CombatPlayer : MonoBehaviour
|
||||
{
|
||||
[Required, SerializeField] private CombatInput input;
|
||||
[Required, SerializeField] private CombatMovement movement;
|
||||
[Required, SerializeField] private CombatAnimator animator;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
movement.combatAnimator = animator;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
input.OnMoveInputReceived += movement.InputMovementValue;
|
||||
input.OnDashInputReceived += movement.HandleDash;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
input.OnMoveInputReceived -= movement.InputMovementValue;
|
||||
input.OnDashInputReceived -= movement.HandleDash;
|
||||
}
|
||||
|
||||
[Button("셋팅 초기화")]
|
||||
private void InitSetting()
|
||||
{
|
||||
input = GetComponent<CombatInput>();
|
||||
movement = GetComponent<CombatMovement>();
|
||||
animator = GetComponent<CombatAnimator>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5d45fd63a2acdca489edd72c7796e8b9
|
1096
BlueWater/Assets/07.Animation/CombatPlayer2D.controller
Normal file
1096
BlueWater/Assets/07.Animation/CombatPlayer2D.controller
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: adab498215cbf694492ab8263e3f4a31
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 9100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue
Block a user