+ 전투에서 사용되는 Item 오브젝트의 InteractionUi의 camera를 UiCamera로 연동 + Item의 드랍 방식을 같은 위치에서 랜덤한 위치로 흩뿌리는 방식으로 변경 + 술통, 쓰레기통 상호작용 추가 + 손님이 음료를 요구할 때, 음료 전달 기능 추가 + 가구 Opaque Unlit으로 재질 변경
150 lines
4.2 KiB
C#
150 lines
4.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using BlueWater.Interfaces;
|
|
using BlueWater.Uis;
|
|
using BlueWater.Utility;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
namespace BlueWater.Players.Tycoons
|
|
{
|
|
public class TycoonInput : MonoBehaviour
|
|
{
|
|
// variables
|
|
#region variables
|
|
|
|
// Components
|
|
[SerializeField]
|
|
private PlayerInput _playerInput;
|
|
|
|
[SerializeField]
|
|
protected float InteractionRadius = 2f;
|
|
|
|
private List<IPlayerInteraction> _playerInteractions = new();
|
|
private IPlayerInteraction _closestInteraction;
|
|
private IPlayerInteraction _previousInteraction;
|
|
|
|
// Events
|
|
public event Action<Vector2> OnMoveInputReceived;
|
|
|
|
#endregion
|
|
|
|
#region Unity events
|
|
|
|
private void Awake()
|
|
{
|
|
InitializeComponents();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
_closestInteraction = GetClosestInteraction();
|
|
if (_closestInteraction != null)
|
|
{
|
|
_closestInteraction.ShowInteractionUi();
|
|
if (_previousInteraction != null && _closestInteraction != _previousInteraction)
|
|
{
|
|
_previousInteraction.HideInteractionUi();
|
|
}
|
|
_previousInteraction = _closestInteraction;
|
|
}
|
|
else
|
|
{
|
|
_previousInteraction?.HideInteractionUi();
|
|
_previousInteraction = null;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
// Initialize methods
|
|
#region Initialize methods
|
|
|
|
[Button("컴포넌트 초기화")]
|
|
private void InitializeComponents()
|
|
{
|
|
_playerInput = GetComponent<PlayerInput>();
|
|
}
|
|
|
|
#endregion
|
|
|
|
// Player input methods
|
|
#region Player input methods
|
|
|
|
// Tycoon
|
|
public void OnMove(InputAction.CallbackContext context)
|
|
{
|
|
var movementInput = context.ReadValue<Vector2>();
|
|
OnMoveInputReceived?.Invoke(movementInput);
|
|
}
|
|
|
|
public void OnInteraction(InputAction.CallbackContext context)
|
|
{
|
|
if (context.performed)
|
|
{
|
|
_closestInteraction?.Interaction();
|
|
}
|
|
}
|
|
|
|
public void OnOpenRestaurantUpgrade(InputAction.CallbackContext context)
|
|
{
|
|
if (context.performed)
|
|
{
|
|
TycoonUiManager.Instance.TycoonUpgradeUi.Open(TycoonUiManager.Instance.PopupUiList);
|
|
}
|
|
}
|
|
|
|
// TycoonUi
|
|
public void OnCloseRestaurantUpgrade(InputAction.CallbackContext context)
|
|
{
|
|
if (context.performed)
|
|
{
|
|
if (!TycoonUiManager.Instance.TycoonUpgradeUi.gameObject.activeSelf) return;
|
|
|
|
TycoonUiManager.Instance.TycoonUpgradeUi.Close();
|
|
}
|
|
}
|
|
|
|
public void OnCancel(InputAction.CallbackContext context)
|
|
{
|
|
if (context.performed)
|
|
{
|
|
CombatUiManager.Instance.CloseLastPopup();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
public void RegisterPlayerInteraction(IPlayerInteraction playerInteraction)
|
|
{
|
|
Utils.RegisterList(_playerInteractions, playerInteraction);
|
|
}
|
|
|
|
public void UnregisterPlayerInteraction(IPlayerInteraction playerInteraction)
|
|
{
|
|
Utils.UnregisterList(_playerInteractions, playerInteraction);
|
|
}
|
|
|
|
private IPlayerInteraction GetClosestInteraction()
|
|
{
|
|
IPlayerInteraction closestInteraction = null;
|
|
var closestDistance = float.MaxValue;
|
|
|
|
foreach (var interaction in _playerInteractions)
|
|
{
|
|
var distance = Vector3.Distance(transform.position, interaction.Transform.position);
|
|
if (distance > InteractionRadius || distance >= closestDistance) continue;
|
|
|
|
closestDistance = distance;
|
|
closestInteraction = interaction;
|
|
}
|
|
|
|
return closestInteraction;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |