94 lines
2.4 KiB
C#
94 lines
2.4 KiB
C#
using BlueWater.Interfaces;
|
|
using BlueWater.Players;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
|
|
namespace BlueWater.Enemies.Bosses
|
|
{
|
|
public abstract class SpineBoss : Boss, ICurrentDirection
|
|
{
|
|
// Variables
|
|
#region Variables
|
|
|
|
// Components
|
|
[field: Title("스파인 보스 컴포넌트")]
|
|
[field: SerializeField]
|
|
public MeshRenderer MeshRenderer { get; private set; }
|
|
|
|
// Classes
|
|
[field: SerializeField]
|
|
public SpineController SpineController { get; private set; }
|
|
|
|
public bool IsMoving { get; private set; }
|
|
|
|
private Vector3 _currentDirection = Vector3.right;
|
|
public Vector3 CurrentDirection
|
|
{
|
|
get => _currentDirection;
|
|
set
|
|
{
|
|
if (value == Vector3.zero) return;
|
|
|
|
_currentDirection = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
// Unity events
|
|
#region Unity events
|
|
|
|
protected override void Update()
|
|
{
|
|
base.Update();
|
|
|
|
HandleMovement();
|
|
FlipVisualLook();
|
|
}
|
|
|
|
#endregion
|
|
|
|
// Initialize methods
|
|
#region Initialize methods
|
|
|
|
[Button("컴포넌트 초기화")]
|
|
protected override void InitializeComponents()
|
|
{
|
|
base.InitializeComponents();
|
|
|
|
MeshRenderer = VisualLook.GetComponent<MeshRenderer>();
|
|
SpineController = GetComponent<SpineController>();
|
|
}
|
|
|
|
#endregion
|
|
|
|
// Methods
|
|
#region Methods
|
|
|
|
protected virtual void FlipVisualLook()
|
|
{
|
|
var localScale = VisualLook.localScale;
|
|
localScale.x = CurrentDirection.x switch
|
|
{
|
|
> 0.01f => -Mathf.Abs(localScale.x),
|
|
< -0.01f => Mathf.Abs(localScale.x),
|
|
_ => localScale.x
|
|
};
|
|
VisualLook.localScale = localScale;
|
|
}
|
|
|
|
protected virtual void HandleMovement()
|
|
{
|
|
if (!AstarAi.canMove || AstarAi.isStopped)
|
|
{
|
|
IsMoving = false;
|
|
return;
|
|
}
|
|
|
|
CurrentDirection = AstarAi.velocity.normalized;
|
|
IsMoving = AstarAi.velocity != Vector3.zero || AstarAi.velocity != Vector3.positiveInfinity;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |