2024-10-14 11:13:08 +00:00
|
|
|
using BehaviorDesigner.Runtime;
|
|
|
|
using BlueWater.Enemies;
|
|
|
|
using BlueWater.Interfaces;
|
|
|
|
using BlueWater.Players;
|
|
|
|
using BlueWater.Uis;
|
|
|
|
using Pathfinding;
|
|
|
|
using PixelCrushers.DialogueSystem;
|
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace BlueWater.Npcs.Crews
|
|
|
|
{
|
|
|
|
public static class CrewSpineAnimation
|
|
|
|
{
|
|
|
|
public const string Idle = "Idle";
|
|
|
|
public const string Walk = "Run";
|
2024-10-20 17:21:39 +00:00
|
|
|
public const string ServingIdle = "ServingIdle";
|
2024-10-14 11:13:08 +00:00
|
|
|
public const string Serving = "Serving";
|
|
|
|
public const string CleaningFloor = "CleaningFloor";
|
|
|
|
public const string CleaningTable = "CleaningTable";
|
|
|
|
public const string MakingCocktail = "BeerMaker";
|
|
|
|
}
|
|
|
|
|
2024-10-22 12:41:31 +00:00
|
|
|
public abstract class Crew : MonoBehaviour
|
2024-10-14 11:13:08 +00:00
|
|
|
{
|
|
|
|
// Variables
|
|
|
|
|
|
|
|
#region Variables
|
|
|
|
|
|
|
|
// Components
|
|
|
|
[field: SerializeField]
|
|
|
|
public Transform CenterTransform { get; private set; }
|
|
|
|
|
|
|
|
[field: SerializeField]
|
|
|
|
public Rigidbody Rigidbody { get; private set; }
|
|
|
|
|
|
|
|
[field: SerializeField]
|
|
|
|
public CapsuleCollider CharacterCollider { get; private set; }
|
|
|
|
|
|
|
|
[field: SerializeField]
|
|
|
|
public BehaviorTree BehaviorTree { get; private set; }
|
|
|
|
|
|
|
|
[field: SerializeField]
|
|
|
|
public Transform VisualLook { get; private set; }
|
|
|
|
|
|
|
|
[field: SerializeField]
|
|
|
|
public MeshRenderer MeshRenderer { get; private set; }
|
|
|
|
|
|
|
|
[field: SerializeField]
|
|
|
|
public BarkTrigger BarkTrigger { get; private set; }
|
|
|
|
|
|
|
|
[field: SerializeField]
|
|
|
|
public InteractionCanvas InteractionCanvas { get; private set; }
|
|
|
|
|
|
|
|
[field: SerializeField]
|
|
|
|
public BalloonUi BalloonUi { get; private set; }
|
|
|
|
|
|
|
|
// Classes
|
|
|
|
[field: SerializeField, Required]
|
|
|
|
public SpineController SpineController { get; private set; }
|
|
|
|
|
|
|
|
[field: SerializeField, Required]
|
|
|
|
public AiMovement AIMovement { get; private set; }
|
|
|
|
|
|
|
|
public bool IsMoving { get; protected set; }
|
|
|
|
|
|
|
|
private Vector3 _currentDirection = Vector3.right;
|
|
|
|
public Vector3 CurrentDirection
|
|
|
|
{
|
|
|
|
get => _currentDirection;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (value == Vector3.zero) return;
|
|
|
|
|
|
|
|
_currentDirection = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-22 12:41:31 +00:00
|
|
|
public ICrewInteraction CrewInteraction { get; protected set; }
|
|
|
|
public bool IsOnMission { get; protected set; }
|
2024-10-14 11:13:08 +00:00
|
|
|
|
|
|
|
private IAstarAI _astarAi;
|
|
|
|
private Transform _spawnTransform;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
// Unity events
|
|
|
|
|
|
|
|
#region Unity events
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
InitializeComponents();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void Update()
|
|
|
|
{
|
|
|
|
HandleMovement();
|
|
|
|
FlipVisualLook();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
// Initialize methods
|
|
|
|
|
|
|
|
#region Initialize methods
|
|
|
|
|
|
|
|
[Button("컴포넌트 초기화")]
|
|
|
|
protected virtual void InitializeComponents()
|
|
|
|
{
|
|
|
|
CenterTransform = transform;
|
|
|
|
Rigidbody = GetComponent<Rigidbody>();
|
|
|
|
CharacterCollider = GetComponent<CapsuleCollider>();
|
|
|
|
BehaviorTree = GetComponent<BehaviorTree>();
|
|
|
|
VisualLook = transform.Find("VisualLook");
|
|
|
|
MeshRenderer = VisualLook.GetComponent<MeshRenderer>();
|
|
|
|
BarkTrigger = transform.Find("DialogueSystem").GetComponent<BarkTrigger>();
|
|
|
|
InteractionCanvas = transform.GetComponentInChildren<InteractionCanvas>();
|
|
|
|
BalloonUi = InteractionCanvas.transform.GetComponentInChildren<BalloonUi>();
|
|
|
|
|
|
|
|
SpineController = GetComponent<SpineController>();
|
|
|
|
AIMovement = GetComponent<AiMovement>();
|
|
|
|
|
|
|
|
_astarAi = GetComponent<IAstarAI>();
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void Initialize()
|
|
|
|
{
|
|
|
|
BehaviorTree.EnableBehavior();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
// Methods
|
|
|
|
|
|
|
|
#region Methods
|
|
|
|
|
|
|
|
private void HandleMovement()
|
|
|
|
{
|
|
|
|
if (!_astarAi.canMove || _astarAi.isStopped)
|
|
|
|
{
|
|
|
|
IsMoving = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CurrentDirection = _astarAi.velocity.normalized;
|
|
|
|
IsMoving = _astarAi.velocity != Vector3.zero || _astarAi.velocity != Vector3.positiveInfinity;
|
|
|
|
}
|
|
|
|
|
|
|
|
private 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Bark(string conversation, BarkOrder barkOrder = BarkOrder.Random)
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(conversation)) return;
|
|
|
|
|
|
|
|
BarkTrigger.barkOrder = barkOrder;
|
|
|
|
BarkTrigger.conversation = conversation;
|
|
|
|
BarkTrigger.OnUse();
|
|
|
|
}
|
|
|
|
|
2024-10-15 18:01:16 +00:00
|
|
|
public virtual void OnMission(ICrewInteraction crewInteraction)
|
|
|
|
{
|
|
|
|
CrewInteraction = crewInteraction;
|
2024-10-22 12:41:31 +00:00
|
|
|
CrewInteraction.OnInteractionCompleted += ResetMission;
|
2024-10-15 18:01:16 +00:00
|
|
|
IsOnMission = true;
|
|
|
|
}
|
|
|
|
|
2024-10-22 12:41:31 +00:00
|
|
|
public abstract void ResetMission();
|
|
|
|
public abstract bool IsCompletedMission();
|
2024-10-15 18:01:16 +00:00
|
|
|
|
|
|
|
public virtual bool CanInteractionPosition()
|
|
|
|
{
|
2024-11-30 11:53:38 +00:00
|
|
|
if (CrewInteraction == null || CrewInteraction.CenterTransform == null) return false;
|
2024-10-15 18:01:16 +00:00
|
|
|
|
|
|
|
return AIMovement.HasReachedDestination() ||
|
|
|
|
Vector3.Distance(CrewInteraction.CenterTransform.position, transform.position) <=
|
|
|
|
CrewInteraction.InteractionRadius;
|
|
|
|
}
|
|
|
|
|
2024-10-14 11:13:08 +00:00
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|