Более менее пашет

This commit is contained in:
bybohka committed 2026-11-20 05:08:26 +03:00
1 parent eed6b79efc
commit 33168b98d1
26 files changed
+443071 -19380

No files matched your search

+53 -32
View File
@@ -15,7 +15,6 @@ public class FluidCanister : MonoBehaviour, IInteractable
[Header("Позиционирование в руках")]
[SerializeField] private Vector3 inHandPositionOffset = new Vector3(0.24f, -0.22f, 0.55f);
// Канистра держится справа внизу кадра и не закрывает подкапотное пространство
private static readonly Vector3 HandPos = new Vector3(0.42f, -0.4f, 0.7f);
private const float HandScale = 0.65f;
private Vector3 groundScale;
@@ -40,7 +39,6 @@ public class FluidCanister : MonoBehaviour, IInteractable
public CanisterState State => state;
public float Fill01 => maxCapacityLiters > 0f ? currentLiters / maxCapacityLiters : 0f;
/// <summary>Настройка канистры из кода (магазин автохимии, автонастройка).</summary>
public void Configure(FluidType type, string title, float liters, Color color)
{
fluidType = type;
@@ -157,6 +155,7 @@ public class FluidCanister : MonoBehaviour, IInteractable
hands.SetHeldCanister(this);
Transform anchor = hands.HoldPoint != null && hands.HoldPoint.parent != null ? hands.HoldPoint.parent : hands.transform;
currentHoldPoint = anchor;
capSearchTimer = 0f;
if (rb != null) Destroy(rb);
if (col != null) col.enabled = false;
@@ -203,41 +202,55 @@ public class FluidCanister : MonoBehaviour, IInteractable
return;
}
// Сбросить канистру по клавише G или правой кнопке мыши
if (Input.GetKeyDown(KeyCode.G) || Input.GetMouseButtonDown(1))
{
DropCanister();
return;
}
// Проверяем прицеливание в горловину автомобиля
Camera cam = currentHoldPoint != null ? currentHoldPoint.GetComponentInParent<Camera>() : null;
if (cam == null) cam = Camera.main;
if (cam == null) return;
RefreshBestCap();
Ray ray = new Ray(cam.transform.position, cam.transform.forward);
bool aimingAtValidCap = false;
CarFluidCap targetCap = null;
if (Physics.Raycast(ray, out RaycastHit hit, 2.6f, ~0, QueryTriggerInteraction.Collide))
RaycastHit[] hits = Physics.RaycastAll(ray, 2.8f, ~0, QueryTriggerInteraction.Collide);
System.Array.Sort(hits, (a, b) => a.distance.CompareTo(b.distance));
foreach (RaycastHit h in hits)
{
targetCap = hit.collider.GetComponentInParent<CarFluidCap>();
if (h.collider.transform.root == transform.root) continue;
CarFluidCap cap = h.collider.GetComponentInParent<CarFluidCap>();
if (cap != null && cap.Reservoir != null)
{
targetCap = cap;
break;
}
}
// Запасной захват по радиусу от луча, если крышка мелкая или перекрыта узлами под капотом
if (targetCap == null && bestCap != null && bestCap.Reservoir != null)
{
Vector3 toCap = bestCap.transform.position - ray.origin;
float along = Vector3.Dot(toCap, ray.direction);
if (along > 0.2f && along < 2.8f && Vector3.Cross(ray.direction, toCap).magnitude < 0.22f)
targetCap = bestCap;
}
if (targetCap != null && targetCap.Reservoir != null)
{
aimingAtValidCap = true;
HandlePouringAtCap(targetCap);
}
else
{
StopPouring();
RestorationHUD.Instance?.Hide(); // подсказка поиска горловины выводится в строке прицела
RestorationHUD.Instance?.Hide();
}
UpdateCapMarker(targetCap);
// Плавная анимация наклона канистры при заливании
Quaternion targetRot = isPouring
? Quaternion.Euler(inHandRotationOffset + new Vector3(55f, -15f, -25f))
: Quaternion.Euler(inHandRotationOffset);
@@ -252,6 +265,17 @@ public class FluidCanister : MonoBehaviour, IInteractable
private void HandlePouringAtCap(CarFluidCap cap)
{
if (fluidType == FluidType.EngineOil && cap.Owner != null)
{
OilDrainPlug plug = cap.Owner.GetComponentInChildren<OilDrainPlug>(true);
if (plug != null && plug.IsUnscrewed)
{
StopPouring();
RestorationHUD.Instance?.ShowCustomMessage("(!) Сливная пробка выкручена!\nСначала закрутите пробку под двигателем.");
return;
}
}
if (!cap.IsOpen)
{
StopPouring();
@@ -278,14 +302,10 @@ public class FluidCanister : MonoBehaviour, IInteractable
if (currentLiters <= 0.01f)
{
StopPouring();
RestorationHUD.Instance?.ShowCustomMessage($"(!) Канистра пуста!\nВ канистре закончилась жидкость.");
RestorationHUD.Instance?.ShowCustomMessage("(!) Канистра пуста!\nВ канистре закончилась жидкость.");
return;
}
// Показываем игроку статус заливки в HUD
int carPercent = Mathf.RoundToInt(cap.Reservoir.FillPercent * 100f);
int canPercent = Mathf.RoundToInt((currentLiters / maxCapacityLiters) * 100f);
RestorationHUD.Instance?.ShowFluidPouringHUD(
cap.Reservoir.title,
fluidType,
@@ -294,7 +314,6 @@ public class FluidCanister : MonoBehaviour, IInteractable
currentLiters,
liquidColor);
// Удержание левой кнопки мыши или E для заливания
if (Input.GetMouseButton(0) || Input.GetKey(KeyCode.E))
{
StartPouring();
@@ -342,6 +361,7 @@ public class FluidCanister : MonoBehaviour, IInteractable
StopPouring();
if (capMarker != null) capMarker.SetActive(false);
}
// ===================== ПОДСВЕТКА НУЖНОЙ ГОРЛОВИНЫ =====================
private static GameObject capMarker;
@@ -364,7 +384,7 @@ public class FluidCanister : MonoBehaviour, IInteractable
private string BuildSearchHint()
{
string head = $"{canisterName}: {currentLiters:F1} л";
if (bestCap == null)
if (bestCap == null || bestCap.Reservoir == null)
return $"{head}\nПодойдите к машине с открытым капотом — нужна {FluidHuman(fluidType)} | [G] Поставить";
VehicleInteraction car = bestCap.GetComponentInParent<VehicleInteraction>();
@@ -381,22 +401,24 @@ public class FluidCanister : MonoBehaviour, IInteractable
return $"{head}\nНаведите прицел на {FluidHuman(fluidType)} — отмечено зеленым шаром (сейчас {pct}%)\n[ЛКМ / E] лить | [G] поставить канистру";
}
private void UpdateCapMarker(CarFluidCap aimed)
private void RefreshBestCap()
{
capSearchTimer -= Time.deltaTime;
if (capSearchTimer <= 0f)
{
capSearchTimer = 0.5f;
bestCap = null;
float best = 6f;
foreach (CarFluidCap cap in FindObjectsByType<CarFluidCap>(FindObjectsSortMode.None))
{
if (cap.Reservoir == null || cap.Reservoir.fluidType != fluidType) continue;
float d = Vector3.Distance(cap.transform.position, transform.position);
if (d < best) { best = d; bestCap = cap; }
}
}
if (capSearchTimer > 0f && bestCap != null) return;
capSearchTimer = 0.5f;
bestCap = null;
float best = 6f;
foreach (CarFluidCap cap in FindObjectsByType<CarFluidCap>(FindObjectsSortMode.None))
{
if (cap.Reservoir == null || cap.Reservoir.fluidType != fluidType) continue;
float d = Vector3.Distance(cap.transform.position, transform.position);
if (d < best) { best = d; bestCap = cap; }
}
}
private void UpdateCapMarker(CarFluidCap aimed)
{
if (capMarker == null)
{
capMarker = GameObject.CreatePrimitive(PrimitiveType.Sphere);
@@ -416,5 +438,4 @@ public class FluidCanister : MonoBehaviour, IInteractable
capMarker.transform.localScale = Vector3.one * pulse;
}
}
}
}