папочка навёл порядок в папках

This commit is contained in:
vladislove committed 2026-07-20 21:07:50 +03:00
1 parent 9374a984e6
commit b407380203
1123 files changed
+2764 -133233

No files matched your search

@@ -0,0 +1,89 @@
using Obstacle;
using UnityEngine;
namespace Player
{
[RequireComponent(typeof(Rigidbody))]
public class PlayerCarController : MonoBehaviour
{
[Header("Скорость движения")]
public float forwardSpeed = 20f;
public float sideSpeed = 15f;
public float horizontalLimit = 4.5f;
[Header("Управление")]
public float swipeSensitivity = 1.5f;
[Header("Визуальный наклон ")]
[Tooltip("На сколько градусов поворачивается нос машины при перестроении")]
public float maxTiltAngle = 15f;
[Tooltip("Как быстро машина выравнивается обратно")]
public float tiltSpeed = 10f;
private Rigidbody _rb;
private bool _isAlive = true;
private float _targetX;
private Vector2 _lastInputPosition;
void Start()
{
_rb = GetComponent<Rigidbody>();
_isAlive = true;
_targetX = transform.position.x;
}
void Update()
{
if (!_isAlive) return;
if (Input.GetMouseButtonDown(0))
{
_lastInputPosition = Input.mousePosition;
}
else if (Input.GetMouseButton(0))
{
float deltaX = Input.mousePosition.x - _lastInputPosition.x;
_lastInputPosition = Input.mousePosition;
// Сдвигаем целевую точку X
_targetX += (deltaX / Screen.width) * swipeSensitivity * 10f;
_targetX = Mathf.Clamp(_targetX, -horizontalLimit, horizontalLimit);
}
}
void FixedUpdate()
{
if (!_isAlive) return;
Vector3 currentPos = _rb.position;
float newX = Mathf.MoveTowards(currentPos.x, _targetX, sideSpeed * Time.fixedDeltaTime);
Vector3 moveTarget = new Vector3(newX, currentPos.y, currentPos.z + forwardSpeed * Time.fixedDeltaTime);
_rb.MovePosition(moveTarget);
float deltaX = newX - currentPos.x;
float direction = deltaX / (sideSpeed * Time.fixedDeltaTime);
// Поворачиваем нос машины в сторону движения
Quaternion targetRotation = Quaternion.Euler(0, direction * maxTiltAngle, 0);
_rb.MoveRotation(Quaternion.Lerp(_rb.rotation, targetRotation, tiltSpeed * Time.fixedDeltaTime));
}
private void OnCollisionEnter(Collision collision)
{
if (!_isAlive) return;
if (collision.gameObject.GetComponent<TrafficCar>() != null ||
collision.gameObject.GetComponent<StaticObstacle>() != null)
{
_isAlive = false;
GameEvents.OnPlayerDied?.Invoke();
}
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 087244143aa340d2a05c776db44651bd
timeCreated: 1783691666
@@ -0,0 +1,156 @@
namespace Player
{
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TruckBedVisuals : MonoBehaviour
{
[Header("Настройки кузова")]
public Transform bedStartPoint;
public GameObject visualBoxPrefab;
[Header("Сетка укладки")]
public int columns = 3;
public int rows = 3;
[Header("Размеры и отступы ")]
public bool uniformScale = true;
public Vector3 boxSize = new Vector3(1f, 1f, 1f);
public Vector3 boxPadding = new Vector3(0.05f, 0.05f, 0.05f);
[Header("Отрисовка в редакторе")]
public int gizmoPreviewLayers = 3;
[Header("Физика выпадения")]
public float dropUpForce = 5f;
public float dropBackForce = 15f;
public float dropTorque = 10f;
private Stack<GameObject> _stackedBoxes = new Stack<GameObject>();
private Collider _carCollider;
private void OnValidate()
{
if (uniformScale)
{
boxSize.y = boxSize.x;
boxSize.z = boxSize.x;
boxPadding.y = boxPadding.x;
boxPadding.z = boxPadding.x;
}
}
void Awake()
{
_carCollider = GetComponent<Collider>();
}
private void OnEnable()
{
GameEvents.OnBoxAddedToTruck += AddBox;
GameEvents.OnBoxLostFromTruck += DropBox;
}
private void OnDisable()
{
GameEvents.OnBoxAddedToTruck -= AddBox;
GameEvents.OnBoxLostFromTruck -= DropBox;
}
private void OnDrawGizmos()
{
if (bedStartPoint == null) return;
Gizmos.color = new Color(0f, 1f, 0f, 0.5f);
Vector3 step = boxSize + boxPadding;
// Сохраняем старую матрицу и применяем трансформацию якоря кузова.
// Теперь сетка будет крутиться и двигаться вместе с машиной!
Matrix4x4 oldMatrix = Gizmos.matrix;
Gizmos.matrix = bedStartPoint.localToWorldMatrix;
for (int layer = 0; layer < gizmoPreviewLayers; layer++)
{
for (int x = 0; x < columns; x++)
{
for (int z = 0; z < rows; z++)
{
Vector3 boxCenter = new Vector3(x * step.x, layer * step.y, -z * step.z);
Gizmos.DrawWireCube(boxCenter, boxSize);
}
}
}
Gizmos.matrix = oldMatrix;
}
private void AddBox()
{
if (visualBoxPrefab == null || bedStartPoint == null) return;
int index = _stackedBoxes.Count;
int layer = index / (columns * rows);
int indexInLayer = index % (columns * rows);
int x = indexInLayer % columns;
int z = indexInLayer / columns;
Vector3 step = boxSize + boxPadding;
Vector3 localPos = new Vector3(x * step.x, layer * step.y, -z * step.z);
GameObject newBox = SimpleObjectPool.Instance.Get(visualBoxPrefab, bedStartPoint.position, bedStartPoint.rotation);
newBox.transform.SetParent(bedStartPoint);
newBox.transform.localPosition = localPos;
newBox.transform.localRotation = Quaternion.identity;
newBox.transform.localScale = boxSize;
Rigidbody rb = newBox.GetComponent<Rigidbody>();
if (rb != null) rb.isKinematic = true;
Collider coll = newBox.GetComponent<Collider>();
if (coll != null) coll.enabled = false;
_stackedBoxes.Push(newBox);
}
private void DropBox()
{
if (_stackedBoxes.Count == 0) return;
GameObject boxToDrop = _stackedBoxes.Pop();
boxToDrop.transform.SetParent(null);
Collider coll = boxToDrop.GetComponent<Collider>();
if (coll != null)
{
coll.enabled = true;
if (_carCollider != null) Physics.IgnoreCollision(coll, _carCollider);
}
Rigidbody rb = boxToDrop.GetComponent<Rigidbody>();
if (rb != null)
{
rb.isKinematic = false;
Rigidbody carRb = GetComponent<Rigidbody>();
if (carRb != null) rb.linearVelocity = carRb.linearVelocity;
Vector3 force = transform.up * dropUpForce - transform.forward * dropBackForce;
rb.AddForce(force, ForceMode.Impulse);
rb.AddTorque(Random.insideUnitSphere * dropTorque, ForceMode.Impulse);
}
StartCoroutine(ReturnBoxToPool(boxToDrop, 3f));
}
IEnumerator ReturnBoxToPool(GameObject box, float delay)
{
yield return new WaitForSeconds(delay);
SimpleObjectPool.Instance.ReturnToPool(visualBoxPrefab, box);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: dc39e6231af5447ca46f490d2aba601a
timeCreated: 1783765082