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

File diff suppressed because it is too large. Load diff
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 7dd2db054bbbee448a578cfa0a2c57a8
+45
View File
@@ -0,0 +1,45 @@
using UnityEngine;
/// <summary>Касса магазина автохимии на АЗС или ноутбук в гараже: [E] открывает магазин и склад.</summary>
public class ShopCounter : MonoBehaviour, IInteractable
{
[SerializeField] private Transform deliveryPoint;
[SerializeField] private string title = "Магазин автохимии и запчастей";
[SerializeField] private float nearbyRadius = 4f;
public static ShopCounter PlayerNearby { get; private set; }
public Transform DeliveryPoint => deliveryPoint;
private Transform player;
public void Configure(Transform delivery, string newTitle)
{
deliveryPoint = delivery;
title = newTitle;
}
private void Update()
{
if (player == null)
{
PlayerMovement pm = FindAnyObjectByType<PlayerMovement>();
if (pm != null) player = pm.transform;
}
bool near = player != null && player.gameObject.activeInHierarchy && Vector3.Distance(player.position, transform.position) < nearbyRadius;
if (near) PlayerNearby = this;
else if (PlayerNearby == this) PlayerNearby = null;
}
public string GetPrompt() => $"[E] {title} (также клавиша K)";
public void Interact(GameObject interactor)
{
GameEconomyManager eco = GameEconomyManager.Instance;
if (eco != null && !eco.DiplomaFeatures)
{
GameHUD.Notify("Магазин доступен в Дипломной версии", GameUI.Muted);
return;
}
if (GarageWarehouseUI.Instance != null) GarageWarehouseUI.Instance.Open(deliveryPoint);
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 3c2a3b8b58eb4dc4fbf25efea7d339be
+49
View File
@@ -0,0 +1,49 @@
using System.Collections.Generic;
using UnityEngine;
/// <summary>Уличный фонарь: включается ночью (TimeAndWeatherManager), светящийся плафон + опционально источник света.</summary>
public class StreetLamp : MonoBehaviour
{
public static readonly List<StreetLamp> All = new List<StreetLamp>();
public Renderer bulb;
public Light lampLight;
public Material onMaterial;
public Material offMaterial;
private bool isOn;
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void ResetStatics() => All.Clear();
private void OnEnable()
{
if (!All.Contains(this)) All.Add(this);
Apply();
}
private void OnDisable() => All.Remove(this);
public void SetOn(bool on)
{
if (isOn == on) return;
isOn = on;
Apply();
}
private void Apply()
{
if (bulb != null)
{
Material m = isOn ? onMaterial : offMaterial;
if (m != null) bulb.sharedMaterial = m;
}
if (lampLight != null) lampLight.enabled = isOn;
}
public static void SetAll(bool on)
{
foreach (StreetLamp l in All)
if (l != null) l.SetOn(on);
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 6c01f9a43f7f00e41b91b3290d40a815
+116
View File
@@ -0,0 +1,116 @@
using System.Collections;
using UnityEngine;
/// <summary>
/// Такси [T]: если договорились о встрече — довезет к продавцу, иначе — обратно в гараж.
/// Экран плавно затемняется, игрок переносится на место. В карьере поездка стоит денег.
/// </summary>
public class TaxiService : MonoBehaviour
{
[SerializeField] private KeyCode key = KeyCode.T;
[SerializeField] private float price = 10f;
[SerializeField] private float minDistance = 40f;
private float fade;
private bool busy;
private string caption;
private void Update()
{
if (busy || !Input.GetKeyDown(key) || GameInputLock.IsLocked || VehicleInteraction.Current != null) return;
MainMenuAndBootManager menu = MainMenuAndBootManager.Instance;
if (menu != null && !menu.IsPlaying) return;
PlayerMovement pm = FindAnyObjectByType<PlayerMovement>();
if (pm == null) return;
if (!TryGetDestination(pm.transform.position, out Vector3 dest, out Quaternion rot, out string name))
{
GameHUD.Notify("Такси не нужно: вы уже на месте", GameUI.Muted);
return;
}
GameEconomyManager eco = GameEconomyManager.Instance;
if (eco != null && !eco.TrySpend(price, "Такси", null, false)) return;
StartCoroutine(Ride(pm, dest, rot, name));
}
private bool TryGetDestination(Vector3 from, out Vector3 dest, out Quaternion rot, out string name)
{
dest = Vector3.zero;
rot = Quaternion.identity;
name = "";
CarMarketManager market = FindAnyObjectByType<CarMarketManager>();
CarListing meeting = market != null ? market.ActiveMeetingListing : null;
if (meeting != null && meeting.spawnedInstance != null)
{
CarOwnership own = meeting.spawnedInstance.GetComponent<CarOwnership>();
Transform car = meeting.spawnedInstance.transform;
if ((own == null || !own.isOwned) && Vector3.Distance(from, car.position) > minDistance)
{
dest = car.position - car.right * 3.2f + car.forward * 1.5f + Vector3.up * 1.1f;
Vector3 look = car.position - dest;
look.y = 0f;
rot = Quaternion.LookRotation(look);
name = "к продавцу";
return true;
}
}
GameEconomyManager eco = GameEconomyManager.Instance;
if (eco != null && eco.playerSpawnPoint != null && Vector3.Distance(from, eco.playerSpawnPoint.position) > minDistance)
{
dest = eco.playerSpawnPoint.position;
rot = eco.playerSpawnPoint.rotation;
name = "в гараж";
return true;
}
return false;
}
private IEnumerator Ride(PlayerMovement pm, Vector3 dest, Quaternion rot, string name)
{
busy = true;
caption = $"Такси едет {name}...";
GameInputLock.Lock(this);
ProceduralAudioManager.Instance?.Play(SfxId.Starter, null, 0.5f, 1.2f);
for (float t = 0f; t < 0.6f; t += Time.unscaledDeltaTime)
{
fade = t / 0.6f;
yield return null;
}
fade = 1f;
CharacterController cc = pm.GetComponent<CharacterController>();
if (cc != null) cc.enabled = false;
pm.transform.SetPositionAndRotation(dest, rot);
if (cc != null) cc.enabled = true;
PlayerLook look = pm.GetComponentInChildren<PlayerLook>();
if (look != null) look.ResetPitch(8f);
yield return new WaitForSecondsRealtime(0.5f);
for (float t = 0f; t < 0.6f; t += Time.unscaledDeltaTime)
{
fade = 1f - t / 0.6f;
yield return null;
}
fade = 0f;
GameInputLock.Unlock(this);
GameHUD.Notify($"Такси довезло вас {name}", GameUI.Accent);
busy = false;
}
private void OnGUI()
{
if (fade <= 0.001f) return;
GameUI.Begin(-30);
float w = GameUI.VirtualWidth, h = GameUI.VirtualHeight;
GameUI.DrawRect(new Rect(0, 0, w, h), new Color(0.03f, 0.03f, 0.04f, fade));
Color prev = GUI.color;
GUI.color = new Color(1, 1, 1, fade);
GUI.Label(new Rect(0, h * 0.5f - 30, w, 60), caption, new GUIStyle(GameUI.Title) { fontSize = 34 });
GUI.color = prev;
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 5bb75e28df47e5448bfcf75fc2254b9e
@@ -0,0 +1,179 @@
using System;
using UnityEngine;
/// <summary>
/// Смена дня и ночи: 1 реальная минута = 1 игровой час (настраивается). Солнце вращается по времени суток,
/// ночью включаются холодный лунный свет, темно-синее небо и уличные фонари. Часы и день — на HUD.
/// </summary>
public class TimeAndWeatherManager : MonoBehaviour
{
public static TimeAndWeatherManager Instance { get; private set; }
[Header("Время")]
[Tooltip("Игровых минут за одну реальную секунду (1 = 1 реальная минута на игровой час)")]
[SerializeField] private float gameMinutesPerRealSecond = 1f;
[SerializeField] private float startHour = 9f;
[Header("Освещение")]
public Light sun;
[SerializeField] private Color dayLightColor = new Color(1f, 0.96f, 0.88f);
[SerializeField] private Color sunsetColor = new Color(1f, 0.55f, 0.3f);
[SerializeField] private float dayIntensity = 1.25f;
[SerializeField] private Color moonColor = new Color(0.55f, 0.65f, 1f);
[SerializeField] private float moonIntensity = 0.18f;
[Header("Небо и окружение")]
[SerializeField] private Color daySky = new Color(0.55f, 0.66f, 0.82f);
[SerializeField] private Color dayEquator = new Color(0.52f, 0.54f, 0.52f);
[SerializeField] private Color dayGround = new Color(0.25f, 0.24f, 0.22f);
[SerializeField] private Color nightSky = new Color(0.04f, 0.06f, 0.14f);
[SerializeField] private Color nightEquator = new Color(0.04f, 0.05f, 0.09f);
[SerializeField] private Color nightGround = new Color(0.02f, 0.02f, 0.03f);
public float TimeOfDayHours { get; private set; }
public int Day { get; private set; } = 1;
public bool IsNight => TimeOfDayHours >= 20f || TimeOfDayHours < 6f;
public string ClockText
{
get
{
int h = Mathf.FloorToInt(TimeOfDayHours);
int m = Mathf.FloorToInt((TimeOfDayHours - h) * 60f);
return $"{h:00}:{m:00}";
}
}
public event Action<int> OnNewDay;
private Light moon;
private bool lampsOn;
private Material skyMat;
private void Awake()
{
Instance = this;
TimeOfDayHours = startHour;
}
private void OnDestroy()
{
if (Instance == this) Instance = null;
if (skyMat != null) Destroy(skyMat);
}
private void Start()
{
if (sun == null) sun = RenderSettings.sun;
if (sun == null)
{
foreach (Light l in FindObjectsByType<Light>(FindObjectsSortMode.None))
if (l.type == LightType.Directional) { sun = l; break; }
}
GameObject moonObj = new GameObject("Moonlight");
moonObj.transform.SetParent(transform, false);
moon = moonObj.AddComponent<Light>();
moon.type = LightType.Directional;
moon.color = moonColor;
moon.shadows = LightShadows.Soft;
moon.shadowStrength = 0.5f;
moon.enabled = false;
RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Trilight;
if (RenderSettings.skybox != null)
{
skyMat = new Material(RenderSettings.skybox);
RenderSettings.skybox = skyMat;
}
lampsOn = !IsNight;
ApplyLighting();
}
public void SetTime(float hours)
{
TimeOfDayHours = Mathf.Repeat(hours, 24f);
ApplyLighting();
}
private void Update()
{
MainMenuAndBootManager menu = MainMenuAndBootManager.Instance;
if (menu == null || menu.IsPlaying)
{
TimeOfDayHours += Time.deltaTime * gameMinutesPerRealSecond / 60f;
if (TimeOfDayHours >= 24f)
{
TimeOfDayHours -= 24f;
Day++;
OnNewDay?.Invoke(Day);
RefreshMarketForNewDay();
}
}
ApplyLighting();
}
private void RefreshMarketForNewDay()
{
CarMarketManager market = FindAnyObjectByType<CarMarketManager>();
if (market != null && market.ActiveMeetingListing == null)
{
market.GenerateListings();
GameHUD.Notify($"День {Day}: на авторынке появились новые объявления [M]", GameUI.Blue);
}
}
private void ApplyLighting()
{
float t = TimeOfDayHours / 24f;
float sunAngle = t * 360f - 90f; // 06:00 — горизонт, 12:00 — зенит
float altitude = Mathf.Sin(sunAngle * Mathf.Deg2Rad);
float day = Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(-0.08f, 0.25f, altitude));
if (sun != null)
{
sun.transform.rotation = Quaternion.Euler(sunAngle, 160f, 0f);
sun.intensity = dayIntensity * day;
sun.color = Color.Lerp(sunsetColor, dayLightColor, Mathf.InverseLerp(0.05f, 0.5f, altitude));
sun.enabled = day > 0.01f;
sun.shadowStrength = Mathf.Lerp(0.4f, 0.85f, day);
}
if (moon != null)
{
moon.transform.rotation = Quaternion.Euler(sunAngle + 180f, 200f, 0f);
moon.intensity = moonIntensity * (1f - day);
moon.enabled = day < 0.95f;
}
Color sky = Color.Lerp(nightSky, daySky, day);
Color equator = Color.Lerp(nightEquator, dayEquator, day);
Color groundC = Color.Lerp(nightGround, dayGround, day);
RenderSettings.ambientSkyColor = sky;
RenderSettings.ambientEquatorColor = equator;
RenderSettings.ambientGroundColor = groundC;
// URP берет окружающий свет из ambientProbe — задаем его напрямую, чтобы ночь действительно темнела
UnityEngine.Rendering.SphericalHarmonicsL2 sh = new UnityEngine.Rendering.SphericalHarmonicsL2();
sh.AddAmbientLight(equator);
sh.AddDirectionalLight(Vector3.up, sky - equator * 0.5f, 0.6f);
sh.AddDirectionalLight(Vector3.down, groundC, 0.3f);
RenderSettings.ambientProbe = sh;
RenderSettings.reflectionIntensity = Mathf.Lerp(0.12f, 1f, day);
RenderSettings.fogColor = Color.Lerp(new Color(0.03f, 0.04f, 0.08f), new Color(0.62f, 0.68f, 0.76f), day);
if (skyMat != null)
{
if (skyMat.HasProperty("_Exposure")) skyMat.SetFloat("_Exposure", Mathf.Lerp(0.12f, 1.25f, day));
if (skyMat.HasProperty("_SkyTint")) skyMat.SetColor("_SkyTint", Color.Lerp(new Color(0.12f, 0.15f, 0.35f), new Color(0.5f, 0.5f, 0.5f), day));
if (skyMat.HasProperty("_AtmosphereThickness")) skyMat.SetFloat("_AtmosphereThickness", Mathf.Lerp(0.6f, 1f, day));
}
bool night = IsNight || day < 0.2f;
if (night != lampsOn)
{
lampsOn = night;
StreetLamp.SetAll(night);
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0a49507780c525b4191999f01503e0df
+112
View File
@@ -0,0 +1,112 @@
using UnityEngine;
/// <summary>
/// Простой автомобиль городского трафика: кинематически едет по замкнутому маршруту по правой полосе,
/// плавно поворачивает на перекрестках и останавливается перед препятствием (игрок, другая машина).
/// </summary>
[RequireComponent(typeof(Rigidbody))]
public class TrafficCar : MonoBehaviour
{
public Vector3[] waypoints;
public float cruiseSpeedKmH = 40f;
public int startIndex;
private Rigidbody rb;
private int target;
private float speed;
private Transform[] wheels;
private Collider[] ownColliders;
private float halfLength = 2.3f;
private void Awake()
{
rb = GetComponent<Rigidbody>();
rb.isKinematic = true;
rb.interpolation = RigidbodyInterpolation.Interpolate;
ownColliders = GetComponentsInChildren<Collider>();
Bounds b = EngineBayManager.LocalRendererBounds(transform, transform, null);
halfLength = Mathf.Max(1.5f, b.extents.z);
var list = new System.Collections.Generic.List<Transform>();
foreach (Transform t in GetComponentsInChildren<Transform>())
if (t.name.ToLowerInvariant().StartsWith("wheel_") && t.GetComponent<Renderer>() != null) list.Add(t);
wheels = list.ToArray();
}
private void Start()
{
if (waypoints == null || waypoints.Length < 2)
{
enabled = false;
return;
}
target = (startIndex + 1) % waypoints.Length;
speed = cruiseSpeedKmH / 3.6f * 0.5f;
}
private void FixedUpdate()
{
if (waypoints == null || waypoints.Length < 2) return;
Vector3 pos = rb.position;
Vector3 goal = waypoints[target];
goal.y = pos.y;
Vector3 to = goal - pos;
float dist = to.magnitude;
if (dist < 3f)
{
target = (target + 1) % waypoints.Length;
return;
}
// Сбавляем перед поворотом
float desired = cruiseSpeedKmH / 3.6f;
if (dist < 18f) desired *= 0.45f;
// Препятствие впереди — тормозим
if (ObstacleAhead(out float obstacleDist))
desired = obstacleDist < 6f ? 0f : desired * 0.3f;
speed = Mathf.MoveTowards(speed, desired, (desired < speed ? 9f : 3.5f) * Time.fixedDeltaTime);
Quaternion look = Quaternion.LookRotation(to.normalized, Vector3.up);
Quaternion rot = Quaternion.RotateTowards(rb.rotation, look, Mathf.Lerp(25f, 70f, speed / 12f) * Time.fixedDeltaTime);
Vector3 forward = rot * Vector3.forward;
rb.MoveRotation(rot);
rb.MovePosition(pos + forward * speed * Time.fixedDeltaTime);
if (wheels != null)
{
float spin = speed * Time.fixedDeltaTime / 0.33f * Mathf.Rad2Deg;
foreach (Transform w in wheels) w.Rotate(spin, 0f, 0f, Space.Self);
}
}
private bool ObstacleAhead(out float distance)
{
distance = float.MaxValue;
Vector3 origin = rb.position + Vector3.up * 0.8f + transform.forward * (halfLength + 0.3f);
RaycastHit[] hits = Physics.BoxCastAll(origin, new Vector3(0.9f, 0.5f, 0.2f), transform.forward, transform.rotation, 14f, ~0, QueryTriggerInteraction.Ignore);
bool found = false;
foreach (RaycastHit h in hits)
{
if (IsOwn(h.collider)) continue;
if (h.collider.attachedRigidbody == null && h.collider.GetComponentInParent<CharacterController>() == null) continue; // статика (бордюр, дом) — не препятствие на дороге
if (h.distance < distance)
{
distance = h.distance;
found = true;
}
}
return found;
}
private bool IsOwn(Collider c)
{
foreach (Collider o in ownColliders) if (o == c) return true;
return false;
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 5aac9474de7a0b147b5ac361af7b8b3e