Система со сменой колес дорабавтываю. Есть задатки системы объявлений и встречи с продавцом
This commit is contained in:
1 parent
2ce853999d
commit
27ad7eac11
25 files changed
+37130
-34404
No files matched your search
@@ -4,7 +4,7 @@ using UnityEngine;
|
||||
public class WheelBolt : MonoBehaviour, IInteractable
|
||||
{
|
||||
[Header("Настройки вылета и скорости")]
|
||||
[SerializeField] private float pullOutDistance = 0.06f;
|
||||
[SerializeField] private float pullOutDistance = 0.05f;
|
||||
[SerializeField] private float workDuration = 0.5f;
|
||||
|
||||
private CarPart parentWheel;
|
||||
@@ -20,16 +20,23 @@ public class WheelBolt : MonoBehaviour, IInteractable
|
||||
|
||||
private Vector3 localMeshCenter;
|
||||
private Vector3 boltCenterInParent;
|
||||
private Vector3 parentOutwardDir;
|
||||
private Vector3 parentOutwardDir = Vector3.right;
|
||||
|
||||
private float tightness = 1f;
|
||||
private bool isTightened = true;
|
||||
private bool isHoveredThisFrame = false;
|
||||
private bool waitForRelease = false;
|
||||
|
||||
// Глобальная блокировка до отпускания кнопки, чтобы болт НИКОГДА не крутился туда-сюда по кругу
|
||||
private static bool waitForKeyRelease = false;
|
||||
|
||||
public bool IsTightened => isTightened;
|
||||
public bool IsAvailableForAim => parentWheel == null || parentWheel.State == PartState.Installed;
|
||||
public Vector3 WorldBoltCenter => transform.TransformPoint(localMeshCenter);
|
||||
|
||||
// ВАЖНО: Координата для прицела берется от неподвижного гнезда на ступице,
|
||||
// чтобы во время выдвижения болта он не выскакивал из-под прицела!
|
||||
public Vector3 WorldBoltCenter => transform.parent != null
|
||||
? transform.parent.TransformPoint(boltCenterInParent)
|
||||
: transform.TransformPoint(localMeshCenter);
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -48,21 +55,33 @@ public class WheelBolt : MonoBehaviour, IInteractable
|
||||
|
||||
boltCollider.isTrigger = true;
|
||||
boltCollider.center = localMeshCenter;
|
||||
boltCollider.radius = 0.045f;
|
||||
boltCollider.radius = 0.055f;
|
||||
|
||||
boltCenterInParent = tightenedLocalPos + tightenedLocalRot * Vector3.Scale(localMeshCenter, baseLocalScale);
|
||||
CalculateOutwardDirection();
|
||||
|
||||
if (meshRenderer != null)
|
||||
originalMaterial = meshRenderer.sharedMaterial;
|
||||
|
||||
if (parentWheel != null && parentWheel.Data != null)
|
||||
ghostMaterial = parentWheel.Data.ghostMaterial;
|
||||
|
||||
// Если в CarPartData забыли назначить Ghost Material — создаем запасной полупрозрачный материал
|
||||
if (ghostMaterial == null)
|
||||
{
|
||||
Shader sh = Shader.Find("Universal Render Pipeline/Unlit") ?? Shader.Find("Sprites/Default");
|
||||
if (sh != null)
|
||||
{
|
||||
ghostMaterial = new Material(sh);
|
||||
ghostMaterial.color = new Color(0.2f, 0.95f, 0.35f, 0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
RecalculateOutwardDirection();
|
||||
}
|
||||
|
||||
private void CalculateOutwardDirection()
|
||||
public void RecalculateOutwardDirection()
|
||||
{
|
||||
Vector3 worldBoltPos = transform.TransformPoint(localMeshCenter);
|
||||
Vector3 worldBoltPos = WorldBoltCenter;
|
||||
VehicleInteraction car = GetComponentInParent<VehicleInteraction>();
|
||||
Transform carRoot = car != null ? car.transform : transform.root;
|
||||
|
||||
@@ -74,10 +93,32 @@ public class WheelBolt : MonoBehaviour, IInteractable
|
||||
parentOutwardDir = transform.parent != null
|
||||
? transform.parent.InverseTransformDirection(worldOutDir).normalized
|
||||
: Vector3.right * sideSign;
|
||||
|
||||
UpdateBoltTransform(1f);
|
||||
}
|
||||
|
||||
public void SetTightenedImmediate(bool state)
|
||||
{
|
||||
isTightened = state;
|
||||
tightness = state ? 1f : 0f;
|
||||
UpdateBoltTransform(1f);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Снимаем блокировку сразу, как только игрок отпустил ЛКМ и клавишу E
|
||||
if (waitForKeyRelease && !Input.GetMouseButton(0) && !Input.GetKey(KeyCode.E))
|
||||
{
|
||||
waitForKeyRelease = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (parentWheel == null)
|
||||
parentWheel = GetComponentInParent<CarPart>();
|
||||
|
||||
// Пока колесо в руках или лежит на земле — болты полностью скрыты
|
||||
if (parentWheel != null && parentWheel.State != PartState.Installed)
|
||||
{
|
||||
if (meshRenderer != null && meshRenderer.enabled) meshRenderer.enabled = false;
|
||||
@@ -95,16 +136,23 @@ public class WheelBolt : MonoBehaviour, IInteractable
|
||||
bool hasWrench = toolManager != null && toolManager.currentTool == ToolType.Wrench;
|
||||
bool isAnimating = tightness > 0.01f && tightness < 0.99f;
|
||||
|
||||
// Визуально увеличиваем КОНКРЕТНЫЙ выбранный болт под прицелом, чтобы игрок видел, куда навелся
|
||||
float scaleMult = (isHoveredThisFrame && hasWrench) ? 1.25f : 1.0f;
|
||||
// Если игрок отпустил кнопку на полпути или увел взгляд — возвращаем болт в крайнее положение
|
||||
if (!isHoveredThisFrame || (!Input.GetMouseButton(0) && !Input.GetKey(KeyCode.E)))
|
||||
{
|
||||
tightness = isTightened ? 1f : 0f;
|
||||
isAnimating = false;
|
||||
}
|
||||
|
||||
// Болт под прицелом заметно увеличивается (1.35x), чтобы игрок четко видел выбранный болт
|
||||
float scaleMult = (isHoveredThisFrame && hasWrench) ? 1.35f : 1.0f;
|
||||
UpdateBoltTransform(scaleMult);
|
||||
|
||||
if (meshRenderer != null)
|
||||
{
|
||||
if (isTightened || isAnimating)
|
||||
{
|
||||
// Закрученный болт всегда виден; под прицелом с ключом — подсвечивается
|
||||
meshRenderer.enabled = true;
|
||||
// Подсвечиваем только тот болт, на который сейчас наведен прицел!
|
||||
if (isHoveredThisFrame && hasWrench && ghostMaterial != null)
|
||||
meshRenderer.sharedMaterial = ghostMaterial;
|
||||
else if (originalMaterial != null)
|
||||
@@ -112,9 +160,10 @@ public class WheelBolt : MonoBehaviour, IInteractable
|
||||
}
|
||||
else
|
||||
{
|
||||
// Выкрученный болт: показываем силуэт отверстия при взятом ключе
|
||||
meshRenderer.enabled = hasWrench && isHoveredThisFrame;
|
||||
if (meshRenderer.enabled && ghostMaterial != null)
|
||||
// КЛЮЧЕВОЕ ИСПРАВЛЕНИЕ: когда болты выкручены и игрок взял КЛЮЧ (hasWrench),
|
||||
// ВСЕ 4 места под болты сразу подсвечиваются силуэтом, чтобы игрок видел, куда наводиться!
|
||||
meshRenderer.enabled = hasWrench;
|
||||
if (hasWrench && ghostMaterial != null)
|
||||
meshRenderer.sharedMaterial = ghostMaterial;
|
||||
}
|
||||
}
|
||||
@@ -134,20 +183,14 @@ public class WheelBolt : MonoBehaviour, IInteractable
|
||||
bool hasWrench = toolManager != null && toolManager.currentTool == ToolType.Wrench;
|
||||
if (!hasWrench)
|
||||
{
|
||||
waitForRelease = false;
|
||||
return isTightened
|
||||
? "Колесный болт (Возьмите баллонный ключ [Tab])"
|
||||
: "Отверстие под болт (Возьмите ключ [Tab])";
|
||||
: "Место под болт (Возьмите баллонный ключ [Tab])";
|
||||
}
|
||||
|
||||
bool isHoldingKey = Input.GetMouseButton(0) || Input.GetKey(KeyCode.E);
|
||||
|
||||
if (!isHoldingKey)
|
||||
{
|
||||
waitForRelease = false;
|
||||
tightness = isTightened ? 1f : 0f;
|
||||
}
|
||||
else if (!waitForRelease)
|
||||
if (isHoldingKey && !waitForKeyRelease)
|
||||
{
|
||||
ProcessWrench(Time.deltaTime);
|
||||
}
|
||||
@@ -155,9 +198,15 @@ public class WheelBolt : MonoBehaviour, IInteractable
|
||||
int percent = Mathf.RoundToInt((isTightened ? (1f - tightness) : tightness) * 100f);
|
||||
|
||||
if (isTightened)
|
||||
return (percent > 0 && !waitForRelease) ? $"Откручиваем болт... {percent}%" : "[Удерж. ЛКМ / E] Открутить болт";
|
||||
{
|
||||
if (waitForKeyRelease) return "Болт закручен! Отпустите кнопку";
|
||||
return percent > 0 ? $"Откручиваем болт... {percent}%" : "[Удерж. ЛКМ / E] Открутить болт";
|
||||
}
|
||||
else
|
||||
return (percent > 0 && !waitForRelease) ? $"Закручиваем болт... {percent}%" : "[Удерж. ЛКМ / E] Закрутить болт";
|
||||
{
|
||||
if (waitForKeyRelease) return "Болт выкручен! Отпустите кнопку";
|
||||
return percent > 0 ? $"Закручиваем болт... {percent}%" : "[Удерж. ЛКМ / E] Закрутить болт";
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessWrench(float dt)
|
||||
@@ -171,7 +220,7 @@ public class WheelBolt : MonoBehaviour, IInteractable
|
||||
{
|
||||
tightness = 0f;
|
||||
isTightened = false;
|
||||
waitForRelease = true;
|
||||
waitForKeyRelease = true; // Блокируем до отпускания кнопки!
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -181,14 +230,18 @@ public class WheelBolt : MonoBehaviour, IInteractable
|
||||
{
|
||||
tightness = 1f;
|
||||
isTightened = true;
|
||||
waitForRelease = true;
|
||||
waitForKeyRelease = true; // Блокируем до отпускания кнопки!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateBoltTransform(float scaleMultiplier = 1f)
|
||||
{
|
||||
float outFactor = 1f - Mathf.Clamp01(tightness);
|
||||
// Выкрученный неанимируемый силуэт стоит ровно в гнезде ступицы (outFactor = 0),
|
||||
// чтобы силуэты отверстий не висели в воздухе в 5 см от диска
|
||||
bool isAnimating = tightness > 0.001f && tightness < 0.999f;
|
||||
float outFactor = isAnimating ? (1f - Mathf.Clamp01(tightness)) : 0f;
|
||||
|
||||
Vector3 currentScale = baseLocalScale * scaleMultiplier;
|
||||
|
||||
Quaternion spinRotation = Quaternion.AngleAxis(outFactor * 720f, parentOutwardDir);
|
||||
|
||||
Reference in new issue
Block a user