101 lines
3.3 KiB
C#
101 lines
3.3 KiB
C#
using UnityEngine;
|
|
|
|
/// <summary>Руки игрока: переноска снятых деталей (CarPart) и канистр с жидкостями (FluidCanister).</summary>
|
|
public class PlayerHands : MonoBehaviour
|
|
{
|
|
[Header("Точка удержания")]
|
|
[Tooltip("Пустой дочерний объект перед камерой игрока")]
|
|
[SerializeField] private Transform holdPoint;
|
|
|
|
[Header("Клавиши управления")]
|
|
[SerializeField] private KeyCode dropKey = KeyCode.G;
|
|
[SerializeField] private KeyCode throwKey = KeyCode.Mouse1; // Правая кнопка мыши
|
|
[SerializeField] private float throwForce = 7f;
|
|
|
|
private CarPart currentPart;
|
|
private FluidCanister currentCanister;
|
|
|
|
public bool IsHolding => currentPart != null;
|
|
public bool IsHoldingCanister => currentCanister != null;
|
|
public bool IsHoldingAnything => currentPart != null || currentCanister != null;
|
|
public CarPart CurrentPart => currentPart;
|
|
public FluidCanister CurrentCanister => currentCanister;
|
|
public Transform HoldPoint => holdPoint;
|
|
|
|
private void Awake()
|
|
{
|
|
if (holdPoint == null)
|
|
{
|
|
Camera cam = GetComponentInChildren<Camera>();
|
|
if (cam != null)
|
|
{
|
|
Transform hp = cam.transform.Find("HoldPoint");
|
|
if (hp == null)
|
|
{
|
|
hp = new GameObject("HoldPoint").transform;
|
|
hp.SetParent(cam.transform, false);
|
|
hp.localPosition = new Vector3(0f, -0.25f, 0.85f);
|
|
}
|
|
holdPoint = hp;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!IsHolding || GameInputLock.IsLocked) return;
|
|
|
|
// Бросить под ноги
|
|
if (Input.GetKeyDown(dropKey))
|
|
{
|
|
DropCurrentPart(Vector3.zero);
|
|
}
|
|
// Бросить вперед с силой
|
|
else if (Input.GetKeyDown(throwKey))
|
|
{
|
|
Vector3 force = holdPoint.forward * throwForce;
|
|
DropCurrentPart(force);
|
|
}
|
|
}
|
|
|
|
public void PickUp(CarPart part)
|
|
{
|
|
if (currentCanister != null) return;
|
|
if (IsHolding)
|
|
{
|
|
// Если уже что-то держим — роняем старую деталь под ноги
|
|
DropCurrentPart(Vector3.zero);
|
|
}
|
|
|
|
currentPart = part;
|
|
currentPart.OnPickedUp(holdPoint);
|
|
ProceduralAudioManager.Instance?.Play(SfxId.Pickup, holdPoint != null ? holdPoint.position : transform.position, 0.5f);
|
|
}
|
|
|
|
public void DropCurrentPart(Vector3 impulse)
|
|
{
|
|
if (!IsHolding) return;
|
|
|
|
CarPart dropped = currentPart;
|
|
currentPart = null; // Освобождаем руки
|
|
dropped.OnDropped(impulse);
|
|
}
|
|
|
|
public void ClearHandAfterInstall()
|
|
{
|
|
currentPart = null;
|
|
}
|
|
|
|
public void SetHeldCanister(FluidCanister canister)
|
|
{
|
|
currentCanister = canister;
|
|
}
|
|
|
|
/// <summary>Положить всё из рук (перед посадкой в машину, при открытии меню).</summary>
|
|
public void DropEverything()
|
|
{
|
|
if (currentCanister != null) currentCanister.DropCanister();
|
|
if (currentPart != null) DropCurrentPart(Vector3.zero);
|
|
}
|
|
}
|