Есть система снятия навесного с авто. Надо дорабатывать. Машины все добавлены
This commit is contained in:
1 parent
a8238ab49e
commit
3e13180e34
15 files changed
+106236
-141
No files matched your search
@@ -2,8 +2,7 @@ using UnityEngine;
|
||||
|
||||
public enum PartState { Installed, InHand, Dropped }
|
||||
|
||||
[RequireComponent(typeof(Collider))]
|
||||
public class CarPart : MonoBehaviour, IInteractable
|
||||
public class CarPart : MonoBehaviour, IInteractable, ISecondaryInteractable
|
||||
{
|
||||
[Header("Данные")]
|
||||
[SerializeField] private CarPartData partData;
|
||||
@@ -14,6 +13,7 @@ public class CarPart : MonoBehaviour, IInteractable
|
||||
[Tooltip("Поворот детали в руках (например, если бампер берется боком)")]
|
||||
[SerializeField] private Vector3 inHandRotationOffset = Vector3.zero;
|
||||
|
||||
private CarPartAnimator partAnimator;
|
||||
private PartState currentState = PartState.Installed;
|
||||
private Transform originalParent;
|
||||
private Vector3 originalLocalPos;
|
||||
@@ -31,6 +31,7 @@ public class CarPart : MonoBehaviour, IInteractable
|
||||
private void Awake()
|
||||
{
|
||||
partCollider = GetComponent<Collider>();
|
||||
partAnimator = GetComponent<CarPartAnimator>();
|
||||
|
||||
originalParent = transform.parent;
|
||||
originalLocalPos = transform.localPosition;
|
||||
@@ -44,15 +45,58 @@ public class CarPart : MonoBehaviour, IInteractable
|
||||
{
|
||||
if (partData == null) return "Деталь (E)";
|
||||
|
||||
return currentState switch
|
||||
if (currentState == PartState.Installed)
|
||||
{
|
||||
PartState.Installed => $"Снять {partData.partName} (E)",
|
||||
PartState.Dropped => $"Взять {partData.partName} (E)",
|
||||
_ => string.Empty
|
||||
};
|
||||
// Если на детали есть аниматор — выводим подсказку с открытием
|
||||
if (partAnimator != null)
|
||||
{
|
||||
string action = partAnimator.IsOpen ? "Закрыть" : "Открыть";
|
||||
return $"[E] {action} {partData.partName} | [R] Снять";
|
||||
}
|
||||
|
||||
return $"Снять {partData.partName} (E)";
|
||||
}
|
||||
|
||||
if (currentState == PartState.Dropped)
|
||||
{
|
||||
return $"Взять {partData.partName} (E)";
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public void Interact(GameObject interactor)
|
||||
{
|
||||
if (currentState == PartState.Installed)
|
||||
{
|
||||
if (partAnimator != null)
|
||||
{
|
||||
// Нажали E — открываем или закрываем
|
||||
partAnimator.TogglePart();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Обычная деталь (бампер) сразу снимается
|
||||
TakeToHands(interactor);
|
||||
}
|
||||
}
|
||||
else if (currentState == PartState.Dropped)
|
||||
{
|
||||
TakeToHands(interactor);
|
||||
}
|
||||
}
|
||||
|
||||
// Вызывается при нажатии R (вторичное действие)
|
||||
public void SecondaryInteract(GameObject interactor)
|
||||
{
|
||||
if (currentState == PartState.Installed)
|
||||
{
|
||||
TakeToHands(interactor);
|
||||
}
|
||||
}
|
||||
|
||||
// Вынесенный общий метод взятия в руки
|
||||
private void TakeToHands(GameObject interactor)
|
||||
{
|
||||
PlayerHands hands = interactor.GetComponent<PlayerHands>();
|
||||
if (hands == null) hands = interactor.GetComponentInParent<PlayerHands>();
|
||||
@@ -61,16 +105,11 @@ public class CarPart : MonoBehaviour, IInteractable
|
||||
|
||||
if (currentState == PartState.Installed)
|
||||
{
|
||||
// 1. Создаем зону для обратной установки на машине
|
||||
if (partAnimator != null) partAnimator.ResetToClosed();
|
||||
CreateMountZone();
|
||||
// 2. Берем сразу в руки
|
||||
hands.PickUp(this);
|
||||
}
|
||||
else if (currentState == PartState.Dropped)
|
||||
{
|
||||
// Подбираем деталь с земли
|
||||
hands.PickUp(this);
|
||||
}
|
||||
|
||||
hands.PickUp(this);
|
||||
}
|
||||
|
||||
public void OnPickedUp(Transform holdPoint)
|
||||
|
||||
Reference in new issue
Block a user