First Commit

This commit is contained in:
bybohka committed 2026-11-19 23:24:44 +03:00
commit eed6b79efc
2836 files changed
+948481

No files matched your search

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 37ba02caa32943f69ac40c67217aec57
timeCreated: 1789943104
@@ -0,0 +1,103 @@
using System.Collections;
using UnityEngine;
/// <summary>
/// Открытие дверей, капота и багажника.
/// Режим 1 (как раньше): вращение вокруг собственного пивота детали на openRotation.
/// Режим 2 (useHinge): вращение вокруг петли hingePoint/hingeAxis в координатах родителя —
/// используется автонастройкой для моделей, у которых пивот детали стоит в центре машины.
/// </summary>
[RequireComponent(typeof(CarPart))]
public class CarPartAnimator : MonoBehaviour
{
[Header("Настройки открытия")]
[SerializeField] private Vector3 openRotation; // Например: (0, 0, 60) для капота
[SerializeField] private float speed = 5f;
[Header("Петля (автонастройка)")]
[SerializeField] private bool useHinge;
[SerializeField] private Vector3 hingePoint;
[SerializeField] private Vector3 hingeAxis = Vector3.right;
[SerializeField] private float openAngle = -55f;
public bool IsOpen => isOpen;
private Quaternion closedRot;
private Quaternion openRot;
private Vector3 closedPos;
private bool isOpen = false;
private float openAmount;
private Coroutine animationCoroutine;
private void Awake()
{
closedRot = transform.localRotation;
closedPos = transform.localPosition;
// Конвертируем введенные углы Эйлера в Кватернион
openRot = closedRot * Quaternion.Euler(openRotation);
}
/// <summary>Настройка петли из Editor-автонастройки (координаты родителя детали).</summary>
public void ConfigureHinge(Vector3 pointInParent, Vector3 axisInParent, float angle, float animSpeed = 4f)
{
useHinge = true;
hingePoint = pointInParent;
hingeAxis = axisInParent.sqrMagnitude > 0.0001f ? axisInParent.normalized : Vector3.right;
openAngle = angle;
speed = animSpeed;
}
public void TogglePart()
{
isOpen = !isOpen;
// Если деталь уже двигалась, останавливаем старую корутину, чтобы не было конфликтов
if (animationCoroutine != null)
StopCoroutine(animationCoroutine);
animationCoroutine = useHinge
? StartCoroutine(AnimateHinge(isOpen ? 1f : 0f))
: StartCoroutine(AnimatePart(isOpen ? openRot : closedRot));
}
public void ResetToClosed()
{
isOpen = false;
openAmount = 0f;
if (animationCoroutine != null) StopCoroutine(animationCoroutine);
transform.localRotation = closedRot;
if (useHinge) transform.localPosition = closedPos;
}
private IEnumerator AnimatePart(Quaternion targetRot)
{
// Пока угол между текущим и целевым вращением больше 0.1 градуса
while (Quaternion.Angle(transform.localRotation, targetRot) > 0.1f)
{
// Плавно вращаем деталь
transform.localRotation = Quaternion.Lerp(transform.localRotation, targetRot, Time.deltaTime * speed);
yield return null; // Ждем следующего кадра
}
// Принудительно доводим до идеального угла в конце
transform.localRotation = targetRot;
}
private IEnumerator AnimateHinge(float target)
{
while (Mathf.Abs(openAmount - target) > 0.001f)
{
openAmount = Mathf.MoveTowards(openAmount, target, Time.deltaTime * speed * 0.35f);
ApplyHinge(Mathf.SmoothStep(0f, 1f, openAmount));
yield return null;
}
openAmount = target;
ApplyHinge(target);
}
private void ApplyHinge(float t)
{
Quaternion q = Quaternion.AngleAxis(openAngle * t, hingeAxis);
transform.localRotation = q * closedRot;
transform.localPosition = hingePoint + q * (closedPos - hingePoint);
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9aac6d89a0a64dc6ba41ec26a0117e79
timeCreated: 1789943180
@@ -0,0 +1,149 @@
using UnityEngine;
/// <summary>
/// Посадка/высадка игрока (клавиша F), управление машиной и внешняя камера CarOrbitCamera.
/// Двигатель заводится при первом нажатии газа (если исправны АКБ и свечи).
/// </summary>
public class VehicleInteraction : MonoBehaviour, IInteractable
{
[Header("Setup")]
[SerializeField] private Transform exitPoint;
[SerializeField] private UIManager uiManager;
/// <summary>Машина, в которой сейчас сидит игрок (null — игрок пешком).</summary>
public static VehicleInteraction Current { get; private set; }
private CarOrbitCamera globalCarCamera;
private CarController carController;
private GameObject playerInstance;
[HideInInspector] public bool isPlayerInside;
private int enteredFrame = -1;
public CarController Controller => carController;
public Transform ExitPoint => exitPoint;
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void ResetStatics() => Current = null;
private void Awake()
{
carController = GetComponent<CarController>();
if (carController == null) carController = GetComponentInChildren<CarController>();
if (carController == null) carController = GetComponentInParent<CarController>();
if (uiManager == null) uiManager = FindAnyObjectByType<UIManager>();
globalCarCamera = FindAnyObjectByType<CarOrbitCamera>(FindObjectsInactive.Include);
if (exitPoint == null)
{
foreach (Transform t in GetComponentsInChildren<Transform>(true))
{
string n = t.name.Replace(" ", "").ToLowerInvariant();
if (n == "exitpoint") { exitPoint = t; break; }
}
}
}
public void Interact(GameObject interactor)
{
if (!isPlayerInside) EnterVehicle(interactor);
}
public string GetPrompt() => "[F] Сесть в машину";
private void EnterVehicle(GameObject player)
{
if (player == null) return;
// Нельзя садиться за руль с деталью или канистрой в руках — кладем её на землю
PlayerHands hands = player.GetComponentInChildren<PlayerHands>();
if (hands != null) hands.DropEverything();
isPlayerInside = true;
enteredFrame = Time.frameCount;
Current = this;
playerInstance = player;
playerInstance.SetActive(false);
if (globalCarCamera == null) globalCarCamera = FindAnyObjectByType<CarOrbitCamera>(FindObjectsInactive.Include);
if (globalCarCamera != null)
{
globalCarCamera.SetTarget(transform);
globalCarCamera.gameObject.SetActive(true);
}
if (carController != null) carController.SetDriver(true);
if (uiManager != null)
{
uiManager.HidePrompt();
uiManager.ToggleDashboard(true);
}
GameHUD.Notify("[W] — завести и ехать, [Space] — ручник, [L] — фары, [F] — выйти", GameUI.Muted);
}
public void ExitVehicle()
{
if (!isPlayerInside) return;
isPlayerInside = false;
if (Current == this) Current = null;
if (carController != null) carController.SetDriver(false);
if (globalCarCamera != null)
{
globalCarCamera.SetTarget(null);
globalCarCamera.gameObject.SetActive(false);
}
if (uiManager != null) uiManager.ToggleDashboard(false);
if (playerInstance == null) return;
CharacterController charController = playerInstance.GetComponent<CharacterController>();
if (charController != null) charController.enabled = false;
Vector3 pos = exitPoint != null
? exitPoint.position
: transform.position - transform.right * 1.8f + Vector3.up * 0.5f;
if (Physics.Raycast(pos + Vector3.up * 1.5f, Vector3.down, out RaycastHit hit, 4f, ~0, QueryTriggerInteraction.Ignore)
&& !hit.collider.transform.IsChildOf(transform))
pos.y = hit.point.y + 1.0f;
playerInstance.transform.position = pos;
playerInstance.transform.rotation = Quaternion.Euler(0f, transform.eulerAngles.y, 0f);
if (charController != null) charController.enabled = true;
playerInstance.SetActive(true);
playerInstance = null;
}
private void Update()
{
if (!isPlayerInside) return;
if (GameInputLock.IsLocked)
{
if (carController != null) carController.ProcessInput(0f, 0f, true);
return;
}
if (carController != null)
{
float vertical = Input.GetAxis("Vertical");
float horizontal = Input.GetAxis("Horizontal");
bool isBraking = Input.GetKey(KeyCode.Space);
carController.ProcessInput(vertical, horizontal, isBraking);
if (uiManager != null) uiManager.UpdateSpeed(carController.SpeedKmH);
}
if (Time.frameCount != enteredFrame && (Input.GetKeyDown(KeyCode.F) || Input.GetKeyDown(KeyCode.E)))
ExitVehicle();
}
private void OnDisable()
{
if (isPlayerInside) ExitVehicle();
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: bf303cb78d154d429f7c0c90338cec80
timeCreated: 1789819810