Более менее пашет
This commit is contained in:
1 parent
eed6b79efc
commit
33168b98d1
26 files changed
+443071
-19380
No files matched your search
@@ -20,6 +20,8 @@ public class GarageWarehouseUI : MonoBehaviour
|
||||
[SerializeField] private KeyCode openKey = KeyCode.K;
|
||||
[SerializeField] private float wheelPrice = 85f;
|
||||
[SerializeField] private float chargePrice = 8f;
|
||||
[Tooltip("Необязательно: укажите свой объект стола выдачи, если хотите переопределить точку из GameEconomyManager")]
|
||||
[SerializeField] private Transform deliveryTableOverride;
|
||||
|
||||
public static GarageWarehouseUI Instance { get; private set; }
|
||||
|
||||
@@ -97,21 +99,252 @@ public class GarageWarehouseUI : MonoBehaviour
|
||||
private Vector3 NextDeliveryPos()
|
||||
{
|
||||
int i = deliveryIndex++;
|
||||
if (customDelivery != null)
|
||||
Transform table = customDelivery != null ? customDelivery : deliveryTableOverride;
|
||||
if (table != null)
|
||||
{
|
||||
int slot = i % 5;
|
||||
return customDelivery.position + customDelivery.right * ((slot - 2) * 0.45f) + Vector3.up * (0.3f + (i / 5 % 3) * 0.35f);
|
||||
return table.position + table.right * ((slot - 2) * 0.45f) + Vector3.up * (0.15f + (i / 5 % 3) * 0.30f);
|
||||
}
|
||||
GameEconomyManager eco = GameEconomyManager.Instance;
|
||||
return eco != null ? eco.GetDeliveryPosition(i % 15) : Vector3.up;
|
||||
}
|
||||
|
||||
// ===================== ПОИСК ОРИГИНАЛЬНЫХ ДЕТАЛЕЙ АВТО =====================
|
||||
|
||||
private List<(Transform root, string title)> CollectTargetCars()
|
||||
{
|
||||
var result = new List<(Transform root, string title)>();
|
||||
var seen = new HashSet<Transform>();
|
||||
|
||||
Vector3 refPos = customDelivery != null
|
||||
? customDelivery.position
|
||||
: (GameEconomyManager.Instance != null && GameEconomyManager.Instance.garageCenter != null
|
||||
? GameEconomyManager.Instance.garageCenter.position
|
||||
: (PlayerPos(out Vector3 pp) ? pp : Vector3.zero));
|
||||
|
||||
var owned = new List<CarOwnership>();
|
||||
foreach (CarOwnership car in CarOwnership.All)
|
||||
if (car != null && car.isOwned) owned.Add(car);
|
||||
owned.Sort((a, b) => Vector3.Distance(a.transform.position, refPos).CompareTo(Vector3.Distance(b.transform.position, refPos)));
|
||||
|
||||
foreach (CarOwnership car in owned)
|
||||
{
|
||||
if (seen.Add(car.transform))
|
||||
result.Add((car.transform, string.IsNullOrEmpty(car.carTitle) ? car.name : car.carTitle));
|
||||
}
|
||||
|
||||
var vehicles = new List<VehicleInteraction>(FindObjectsByType<VehicleInteraction>(FindObjectsSortMode.None));
|
||||
vehicles.Sort((a, b) => Vector3.Distance(a.transform.position, refPos).CompareTo(Vector3.Distance(b.transform.position, refPos)));
|
||||
float garageRad = GameEconomyManager.Instance != null ? GameEconomyManager.Instance.garageRadius : 30f;
|
||||
|
||||
foreach (VehicleInteraction v in vehicles)
|
||||
{
|
||||
if (v == null || seen.Contains(v.transform)) continue;
|
||||
if (result.Count > 0 && Vector3.Distance(v.transform.position, refPos) > garageRad) continue;
|
||||
|
||||
CarOwnership own = v.GetComponent<CarOwnership>();
|
||||
string title = (own != null && !string.IsNullOrEmpty(own.carTitle)) ? own.carTitle : v.gameObject.name.Replace("(Clone)", "").Trim();
|
||||
seen.Add(v.transform);
|
||||
result.Add((v.transform, title));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private EnginePart FindDetailedEngineTemplate(EnginePartType type)
|
||||
{
|
||||
var cars = CollectTargetCars();
|
||||
|
||||
foreach (var (root, _) in cars)
|
||||
{
|
||||
foreach (EnginePart ep in root.GetComponentsInChildren<EnginePart>(true))
|
||||
if (ep.partType == type) return ep;
|
||||
|
||||
foreach (CarPartMountZone z in root.GetComponentsInChildren<CarPartMountZone>(true))
|
||||
{
|
||||
if (z.TargetPart == null) continue;
|
||||
EnginePart ep = z.TargetPart.GetComponent<EnginePart>();
|
||||
if (ep != null && ep.partType == type) return ep;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (EnginePart ep in FindObjectsByType<EnginePart>(FindObjectsInactive.Include, FindObjectsSortMode.None))
|
||||
if (ep.partType == type) return ep;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void SpawnEnginePartForShop(EnginePartType type, Vector3 pos)
|
||||
{
|
||||
EnginePart template = FindDetailedEngineTemplate(type);
|
||||
if (template == null)
|
||||
{
|
||||
EnginePartFactory.CreatePart(type, null, pos, Quaternion.identity, 0.6f, true);
|
||||
return;
|
||||
}
|
||||
|
||||
CloneDetailedPart(template.gameObject, pos);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ставит объект так, чтобы визуальный низ его мешей оказался ровно в точке targetPos (независимо от пивота FBX).
|
||||
/// </summary>
|
||||
private static void PlaceBottomAt(GameObject go, Vector3 targetPos)
|
||||
{
|
||||
if (go == null) return;
|
||||
|
||||
bool hasBounds = false;
|
||||
Bounds worldBounds = default;
|
||||
|
||||
foreach (MeshFilter mf in go.GetComponentsInChildren<MeshFilter>(true))
|
||||
{
|
||||
if (mf.sharedMesh == null || mf.GetComponent<Renderer>() == null) continue;
|
||||
Bounds mb = mf.sharedMesh.bounds;
|
||||
Vector3 e = mb.extents;
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
Vector3 corner = mb.center + new Vector3(
|
||||
i % 2 == 0 ? -e.x : e.x,
|
||||
(i / 2) % 2 == 0 ? -e.y : e.y,
|
||||
i / 4 == 0 ? -e.z : e.z);
|
||||
Vector3 wp = mf.transform.TransformPoint(corner);
|
||||
if (!hasBounds) { worldBounds = new Bounds(wp, Vector3.zero); hasBounds = true; }
|
||||
else worldBounds.Encapsulate(wp);
|
||||
}
|
||||
}
|
||||
|
||||
if (hasBounds)
|
||||
{
|
||||
Vector3 currentBottom = new Vector3(worldBounds.center.x, worldBounds.min.y, worldBounds.center.z);
|
||||
go.transform.position += (targetPos + Vector3.up * 0.05f) - currentBottom;
|
||||
}
|
||||
else
|
||||
{
|
||||
go.transform.position = targetPos + Vector3.up * 0.05f;
|
||||
}
|
||||
|
||||
Rigidbody rb = go.GetComponent<Rigidbody>();
|
||||
if (rb != null)
|
||||
{
|
||||
rb.position = go.transform.position;
|
||||
rb.rotation = go.transform.rotation;
|
||||
rb.linearVelocity = Vector3.zero;
|
||||
rb.angularVelocity = Vector3.zero;
|
||||
}
|
||||
|
||||
Physics.SyncTransforms();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создаёт чистую новую копию детализированной 3D-детали с авто и ставит её точно на стол выдачи.
|
||||
/// </summary>
|
||||
private static GameObject CloneDetailedPart(GameObject template, Vector3 spawnPos)
|
||||
{
|
||||
Vector3 worldScale = template.transform.lossyScale;
|
||||
Quaternion rot = template.transform.rotation;
|
||||
|
||||
GameObject tempHolder = new GameObject("_ShopCloneTemp");
|
||||
tempHolder.SetActive(false);
|
||||
|
||||
GameObject clone = Instantiate(template, tempHolder.transform);
|
||||
clone.SetActive(false);
|
||||
clone.transform.SetParent(null, false);
|
||||
Destroy(tempHolder);
|
||||
|
||||
// Убираем старые Rigidbody, скопированные с детали на полу, чтобы физика не тянула клон назад
|
||||
foreach (Rigidbody oldRb in clone.GetComponentsInChildren<Rigidbody>(true))
|
||||
DestroyImmediate(oldRb);
|
||||
|
||||
clone.name = template.name.Replace("_New", "") + "_New";
|
||||
clone.transform.localScale = worldScale;
|
||||
clone.transform.rotation = rot;
|
||||
clone.transform.position = spawnPos;
|
||||
|
||||
Material dirtMat = PartCatalog.DirtOverlayMaterial;
|
||||
if (dirtMat != null)
|
||||
{
|
||||
foreach (Renderer r in clone.GetComponentsInChildren<Renderer>(true))
|
||||
{
|
||||
Material[] mats = r.sharedMaterials;
|
||||
int count = 0;
|
||||
for (int i = 0; i < mats.Length; i++)
|
||||
if (mats[i] != dirtMat) count++;
|
||||
if (count != mats.Length)
|
||||
{
|
||||
Material[] clean = new Material[count];
|
||||
int k = 0;
|
||||
for (int i = 0; i < mats.Length; i++)
|
||||
if (mats[i] != dirtMat) clean[k++] = mats[i];
|
||||
r.sharedMaterials = clean;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int layer = EnginePartFactory.InteractLayer;
|
||||
if (layer >= 0)
|
||||
{
|
||||
foreach (Transform t in clone.GetComponentsInChildren<Transform>(true))
|
||||
t.gameObject.layer = layer;
|
||||
}
|
||||
|
||||
if (clone.GetComponent<Collider>() == null)
|
||||
{
|
||||
BoxCollider bc = clone.AddComponent<BoxCollider>();
|
||||
Bounds lb = EnginePartFactory.LocalBounds(clone.transform);
|
||||
bc.center = lb.center;
|
||||
bc.size = Vector3.Max(lb.size, Vector3.one * 0.08f);
|
||||
}
|
||||
|
||||
// Выравниваем визуальный низ модели на стол выдачи ДО активации и создания нового Rigidbody
|
||||
PlaceBottomAt(clone, spawnPos);
|
||||
|
||||
clone.SetActive(true);
|
||||
|
||||
CarPartAnimator anim = clone.GetComponent<CarPartAnimator>();
|
||||
if (anim != null) anim.ResetToClosed();
|
||||
|
||||
EnginePart ep = clone.GetComponent<EnginePart>();
|
||||
if (ep != null) ep.SetAsNew();
|
||||
|
||||
CarPartVisuals visuals = clone.GetComponent<CarPartVisuals>();
|
||||
if (visuals != null)
|
||||
{
|
||||
visuals.SetDamage(0f);
|
||||
visuals.SetDirt(0f);
|
||||
visuals.SetHiddenRepaint(false);
|
||||
}
|
||||
|
||||
CarWheelCondition wc = clone.GetComponent<CarWheelCondition>();
|
||||
if (wc != null) wc.ApplyState(CarWheelCondition.TireState.Normal);
|
||||
|
||||
CarPart cp = clone.GetComponent<CarPart>();
|
||||
if (cp != null) cp.InitializeAsLoosePart();
|
||||
|
||||
// Повторно синхронизируем позицию с новым Rigidbody
|
||||
PlaceBottomAt(clone, spawnPos);
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
// ===================== МАГАЗИН =====================
|
||||
|
||||
private void BuildShop()
|
||||
{
|
||||
items.Clear();
|
||||
foreach (EnginePartType t in new[] { EnginePartType.Battery, EnginePartType.SparkPlugs, EnginePartType.AirFilter, EnginePartType.OilFilter, EnginePartType.Radiator, EnginePartType.Alternator })
|
||||
|
||||
var engineTypes = new List<EnginePartType>
|
||||
{
|
||||
EnginePartType.Battery,
|
||||
EnginePartType.SparkPlugs,
|
||||
EnginePartType.AirFilter,
|
||||
EnginePartType.OilFilter,
|
||||
EnginePartType.Radiator,
|
||||
EnginePartType.Alternator
|
||||
};
|
||||
if (FindDetailedEngineTemplate(EnginePartType.FuelFilter) != null)
|
||||
engineTypes.Add(EnginePartType.FuelFilter);
|
||||
|
||||
foreach (EnginePartType t in engineTypes)
|
||||
{
|
||||
EnginePartType type = t;
|
||||
CarPartData d = PartCatalog.Instance.GetEngineData(type);
|
||||
@@ -121,7 +354,7 @@ public class GarageWarehouseUI : MonoBehaviour
|
||||
title = EnginePart.GetDisplayName(type) + " (новый)",
|
||||
category = "Подкапотные агрегаты",
|
||||
price = price,
|
||||
spawn = pos => EnginePartFactory.CreatePart(type, null, pos, Quaternion.identity, 0.6f, true)
|
||||
spawn = pos => SpawnEnginePartForShop(type, pos)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -137,41 +370,52 @@ public class GarageWarehouseUI : MonoBehaviour
|
||||
});
|
||||
}
|
||||
|
||||
// Колеса и кузовные детали для машин игрока в гараже
|
||||
foreach (CarOwnership car in CarOwnership.All)
|
||||
foreach (var (carRoot, carTitle) in CollectTargetCars())
|
||||
{
|
||||
if (car == null || !car.isOwned) continue;
|
||||
|
||||
CarPart wheelTemplate = null;
|
||||
foreach (CarPart p in car.GetComponentsInChildren<CarPart>(true))
|
||||
foreach (CarPart p in carRoot.GetComponentsInChildren<CarPart>(true))
|
||||
{
|
||||
if (!p.IsWheel) continue;
|
||||
if (wheelTemplate == null || (p.State == PartState.Installed && p.gameObject.activeInHierarchy)) wheelTemplate = p;
|
||||
if (wheelTemplate == null || (p.State == PartState.Installed && p.gameObject.activeInHierarchy))
|
||||
wheelTemplate = p;
|
||||
}
|
||||
if (wheelTemplate != null)
|
||||
{
|
||||
CarPart template = wheelTemplate;
|
||||
items.Add(new ShopItem
|
||||
{
|
||||
title = $"Колесо в сборе — {car.carTitle}",
|
||||
title = $"Колесо в сборе — {carTitle}",
|
||||
category = "Колеса",
|
||||
price = wheelPrice,
|
||||
spawn = pos => CarWheelCondition.CreateSpareFrom(template, pos)
|
||||
});
|
||||
}
|
||||
|
||||
foreach (CarPartMountZone z in car.GetComponentsInChildren<CarPartMountZone>(true))
|
||||
HashSet<CarPart> listedBody = new HashSet<CarPart>();
|
||||
foreach (CarPartMountZone z in carRoot.GetComponentsInChildren<CarPartMountZone>(true))
|
||||
{
|
||||
CarPart target = z.TargetPart;
|
||||
if (target == null || target.IsWheel || target.GetComponent<EnginePart>() != null) continue;
|
||||
if (target.gameObject.activeInHierarchy) continue; // Снятая деталь лежит рядом — её можно поставить обратно
|
||||
if (!listedBody.Add(target)) continue;
|
||||
|
||||
CarPart t2 = target;
|
||||
items.Add(new ShopItem
|
||||
{
|
||||
title = $"{t2.DisplayName} — {car.carTitle}",
|
||||
title = $"{t2.DisplayName} (новая) — {carTitle}",
|
||||
category = "Кузовные панели",
|
||||
price = t2.Data != null ? t2.Data.basePrice : 150f,
|
||||
spawn = pos => t2.SpawnAsNewPart(pos)
|
||||
spawn = pos =>
|
||||
{
|
||||
if (!t2.gameObject.activeInHierarchy)
|
||||
{
|
||||
t2.SpawnAsNewPart(pos);
|
||||
PlaceBottomAt(t2.gameObject, pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
CloneDetailedPart(t2.gameObject, pos);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -216,6 +460,7 @@ public class GarageWarehouseUI : MonoBehaviour
|
||||
if (rb == null) rb = go.AddComponent<Rigidbody>();
|
||||
rb.mass = 4f;
|
||||
rb.collisionDetectionMode = CollisionDetectionMode.ContinuousSpeculative;
|
||||
PlaceBottomAt(go, pos);
|
||||
return can;
|
||||
}
|
||||
|
||||
@@ -389,4 +634,4 @@ public class GarageWarehouseUI : MonoBehaviour
|
||||
}
|
||||
GUI.EndScrollView();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
@@ -8,12 +7,12 @@ public class RestorationHUD : MonoBehaviour
|
||||
{
|
||||
public static RestorationHUD Instance { get; private set; }
|
||||
|
||||
[Header("Настройки анимации и расположения")]
|
||||
[SerializeField] private Vector2 hudAnchoredPosition = new Vector2(0f, -140f);
|
||||
[SerializeField] private float fadeSpeed = 12f;
|
||||
[Header("Расположение на экране (от нижнего центра)")]
|
||||
[SerializeField] private Vector2 bottomCenterOffset = new Vector2(0f, 85f);
|
||||
[SerializeField] private float fadeSpeed = 14f;
|
||||
|
||||
private CanvasGroup canvasGroup;
|
||||
private RectTransform rootCard;
|
||||
private RectTransform cardRoot;
|
||||
private TextMeshProUGUI titleText;
|
||||
private TextMeshProUGUI stageBadgeText;
|
||||
private Image stageBadgeBg;
|
||||
@@ -21,15 +20,30 @@ public class RestorationHUD : MonoBehaviour
|
||||
private TextMeshProUGUI progressPercentText;
|
||||
private TextMeshProUGUI hintText;
|
||||
|
||||
// Секция залива жидкостей
|
||||
private GameObject fluidSection;
|
||||
private Image fluidGaugeFill;
|
||||
private TextMeshProUGUI fluidLitersText;
|
||||
private TextMeshProUGUI fluidHintText;
|
||||
|
||||
private bool uiInitialized;
|
||||
private float targetAlpha = 0f;
|
||||
private float hideTimer = 0f;
|
||||
private float currentFillAmount = 0f;
|
||||
private int lastShownFrame = -1;
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
|
||||
private static void EnsureExistsInScene()
|
||||
{
|
||||
if (Instance != null || FindAnyObjectByType<RestorationHUD>() != null) return;
|
||||
|
||||
GameObject canvasObj = new GameObject("RestorationHUD_Canvas");
|
||||
Canvas canvas = canvasObj.AddComponent<Canvas>();
|
||||
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
canvas.sortingOrder = 25;
|
||||
|
||||
CanvasScaler scaler = canvasObj.AddComponent<CanvasScaler>();
|
||||
scaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
|
||||
scaler.referenceResolution = new Vector2(1920f, 1080f);
|
||||
|
||||
GameObject hudObj = new GameObject("RestorationHUD");
|
||||
hudObj.transform.SetParent(canvasObj.transform, false);
|
||||
hudObj.AddComponent<RestorationHUD>();
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -41,43 +55,76 @@ public class RestorationHUD : MonoBehaviour
|
||||
|
||||
private void EnsureUIElementsCreated()
|
||||
{
|
||||
canvasGroup = GetComponent<CanvasGroup>();
|
||||
if (canvasGroup == null) canvasGroup = gameObject.AddComponent<CanvasGroup>();
|
||||
// Инициализируем ровно один раз — иначе каждый кадр будет сбрасываться alpha = 0
|
||||
if (uiInitialized && titleText != null && canvasGroup != null) return;
|
||||
uiInitialized = true;
|
||||
|
||||
// Если RestorationHUD повешен на объект вне Canvas (например, GameSystems) — создаём свой Canvas
|
||||
RectTransform targetParent;
|
||||
if (GetComponentInParent<Canvas>() == null)
|
||||
{
|
||||
GameObject canvasObj = new GameObject("RestorationHUD_Canvas");
|
||||
canvasObj.transform.SetParent(transform, false);
|
||||
Canvas c = canvasObj.AddComponent<Canvas>();
|
||||
c.renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
c.sortingOrder = 25;
|
||||
|
||||
CanvasScaler scaler = canvasObj.AddComponent<CanvasScaler>();
|
||||
scaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
|
||||
scaler.referenceResolution = new Vector2(1920f, 1080f);
|
||||
|
||||
GameObject cardObj = new GameObject("RestorationCard");
|
||||
cardObj.transform.SetParent(canvasObj.transform, false);
|
||||
targetParent = cardObj.AddComponent<RectTransform>();
|
||||
}
|
||||
else
|
||||
{
|
||||
targetParent = GetComponent<RectTransform>();
|
||||
if (targetParent == null) targetParent = gameObject.AddComponent<RectTransform>();
|
||||
}
|
||||
|
||||
cardRoot = targetParent;
|
||||
|
||||
canvasGroup = cardRoot.GetComponent<CanvasGroup>();
|
||||
if (canvasGroup == null) canvasGroup = cardRoot.gameObject.AddComponent<CanvasGroup>();
|
||||
canvasGroup.alpha = 0f;
|
||||
canvasGroup.blocksRaycasts = false;
|
||||
canvasGroup.interactable = false;
|
||||
canvasGroup.ignoreParentGroups = true;
|
||||
|
||||
RectTransform myRect = GetComponent<RectTransform>();
|
||||
if (myRect == null) myRect = gameObject.AddComponent<RectTransform>();
|
||||
|
||||
// Если элементы еще не созданы в иерархии — собираем стильную стеклянную карточку
|
||||
if (titleText == null)
|
||||
{
|
||||
BuildModernHUD(myRect);
|
||||
}
|
||||
BuildModernHUD(cardRoot);
|
||||
else
|
||||
ApplyPosition(cardRoot);
|
||||
}
|
||||
|
||||
private void ApplyPosition(RectTransform rt)
|
||||
{
|
||||
// Нижний центр экрана — выше строки горячих клавиш, не перекрывает центр и подсказки [F]/[E]
|
||||
rt.anchorMin = new Vector2(0.5f, 0f);
|
||||
rt.anchorMax = new Vector2(0.5f, 0f);
|
||||
rt.pivot = new Vector2(0.5f, 0f);
|
||||
rt.anchoredPosition = bottomCenterOffset;
|
||||
rt.sizeDelta = new Vector2(440f, 128f);
|
||||
}
|
||||
|
||||
private void BuildModernHUD(RectTransform parent)
|
||||
{
|
||||
parent.anchorMin = new Vector2(0.5f, 0.5f);
|
||||
parent.anchorMax = new Vector2(0.5f, 0.5f);
|
||||
parent.pivot = new Vector2(0.5f, 0.5f);
|
||||
parent.anchoredPosition = hudAnchoredPosition;
|
||||
parent.sizeDelta = new Vector2(420f, 130f);
|
||||
ApplyPosition(parent);
|
||||
|
||||
// 1. Фоновая плашка с эффектом темного стекла и мягкой обводкой
|
||||
Image cardBg = gameObject.GetComponent<Image>();
|
||||
if (cardBg == null) cardBg = gameObject.AddComponent<Image>();
|
||||
Image cardBg = parent.GetComponent<Image>();
|
||||
if (cardBg == null) cardBg = parent.gameObject.AddComponent<Image>();
|
||||
cardBg.color = Color.white;
|
||||
cardBg.sprite = ProceduralUISprites.GetSlicedRoundedRect(
|
||||
new Color(0.08f, 0.10f, 0.14f, 0.88f),
|
||||
new Color(0.28f, 0.35f, 0.45f, 0.45f),
|
||||
new Color(0.07f, 0.09f, 0.13f, 0.96f),
|
||||
new Color(0.32f, 0.40f, 0.52f, 0.85f),
|
||||
1.5f, 16);
|
||||
cardBg.type = Image.Type.Sliced;
|
||||
cardBg.raycastTarget = false;
|
||||
|
||||
// 2. Верхняя строка: Заголовок детали + Бейдж этапа
|
||||
// Верхняя строка: Название детали + Бейдж этапа
|
||||
GameObject topRow = new GameObject("TopRow");
|
||||
topRow.transform.SetParent(transform, false);
|
||||
topRow.transform.SetParent(parent, false);
|
||||
RectTransform trRt = topRow.AddComponent<RectTransform>();
|
||||
trRt.anchorMin = new Vector2(0f, 1f);
|
||||
trRt.anchorMax = new Vector2(1f, 1f);
|
||||
@@ -85,7 +132,6 @@ public class RestorationHUD : MonoBehaviour
|
||||
trRt.anchoredPosition = new Vector2(0f, -12f);
|
||||
trRt.sizeDelta = new Vector2(-24f, 26f);
|
||||
|
||||
// Название детали
|
||||
GameObject titleObj = new GameObject("TitleText");
|
||||
titleObj.transform.SetParent(topRow.transform, false);
|
||||
RectTransform titleRt = titleObj.AddComponent<RectTransform>();
|
||||
@@ -96,13 +142,12 @@ public class RestorationHUD : MonoBehaviour
|
||||
titleRt.sizeDelta = Vector2.zero;
|
||||
|
||||
titleText = titleObj.AddComponent<TextMeshProUGUI>();
|
||||
titleText.fontSize = 15f;
|
||||
titleText.fontSize = 16f;
|
||||
titleText.fontStyle = FontStyles.Bold;
|
||||
titleText.color = new Color(0.95f, 0.96f, 0.98f);
|
||||
titleText.color = Color.white;
|
||||
titleText.alignment = TextAlignmentOptions.MidlineLeft;
|
||||
titleText.text = "Передняя левая дверь";
|
||||
titleText.text = "Кузов";
|
||||
|
||||
// Бейдж этапа
|
||||
GameObject badgeObj = new GameObject("StageBadge");
|
||||
badgeObj.transform.SetParent(topRow.transform, false);
|
||||
RectTransform badgeRt = badgeObj.AddComponent<RectTransform>();
|
||||
@@ -113,8 +158,9 @@ public class RestorationHUD : MonoBehaviour
|
||||
badgeRt.sizeDelta = Vector2.zero;
|
||||
|
||||
stageBadgeBg = badgeObj.AddComponent<Image>();
|
||||
stageBadgeBg.color = Color.white;
|
||||
stageBadgeBg.sprite = ProceduralUISprites.GetSlicedRoundedRect(
|
||||
new Color(0.85f, 0.35f, 0.12f, 0.9f), null, 0f, 8);
|
||||
new Color(0.85f, 0.35f, 0.12f, 1f), null, 0f, 8);
|
||||
stageBadgeBg.type = Image.Type.Sliced;
|
||||
|
||||
GameObject badgeTextObj = new GameObject("BadgeText");
|
||||
@@ -125,26 +171,27 @@ public class RestorationHUD : MonoBehaviour
|
||||
btRt.sizeDelta = Vector2.zero;
|
||||
|
||||
stageBadgeText = badgeTextObj.AddComponent<TextMeshProUGUI>();
|
||||
stageBadgeText.fontSize = 12f;
|
||||
stageBadgeText.fontSize = 12.5f;
|
||||
stageBadgeText.fontStyle = FontStyles.Bold;
|
||||
stageBadgeText.color = Color.white;
|
||||
stageBadgeText.alignment = TextAlignmentOptions.Center;
|
||||
stageBadgeText.text = "Ржавчина";
|
||||
|
||||
// 3. Полоса прогресса
|
||||
// Полоса прогресса
|
||||
GameObject progressTrack = new GameObject("ProgressTrack");
|
||||
progressTrack.transform.SetParent(transform, false);
|
||||
progressTrack.transform.SetParent(parent, false);
|
||||
RectTransform ptRt = progressTrack.AddComponent<RectTransform>();
|
||||
ptRt.anchorMin = new Vector2(0f, 0.5f);
|
||||
ptRt.anchorMax = new Vector2(1f, 0.5f);
|
||||
ptRt.pivot = new Vector2(0.5f, 0.5f);
|
||||
ptRt.anchoredPosition = new Vector2(0f, 2f);
|
||||
ptRt.sizeDelta = new Vector2(-24f, 16f);
|
||||
ptRt.anchoredPosition = new Vector2(0f, 4f);
|
||||
ptRt.sizeDelta = new Vector2(-24f, 18f);
|
||||
|
||||
Image trackBg = progressTrack.AddComponent<Image>();
|
||||
trackBg.color = Color.white;
|
||||
trackBg.sprite = ProceduralUISprites.GetSlicedRoundedRect(
|
||||
new Color(0.12f, 0.15f, 0.20f, 0.95f),
|
||||
new Color(0.22f, 0.26f, 0.35f, 0.5f), 1f, 8);
|
||||
new Color(0.14f, 0.17f, 0.23f, 1f),
|
||||
new Color(0.28f, 0.34f, 0.44f, 0.85f), 1f, 8);
|
||||
trackBg.type = Image.Type.Sliced;
|
||||
|
||||
GameObject fillObj = new GameObject("ProgressFill");
|
||||
@@ -155,12 +202,12 @@ public class RestorationHUD : MonoBehaviour
|
||||
fillRt.sizeDelta = new Vector2(-4f, -4f);
|
||||
|
||||
progressFill = fillObj.AddComponent<Image>();
|
||||
progressFill.sprite = ProceduralUISprites.GetSlicedRoundedRect(
|
||||
new Color(0.20f, 0.65f, 0.95f, 0.95f), null, 0f, 6);
|
||||
progressFill.sprite = ProceduralUISprites.GetSlicedRoundedRect(Color.white, null, 0f, 6);
|
||||
progressFill.color = new Color(0.20f, 0.65f, 0.95f, 1f);
|
||||
progressFill.type = Image.Type.Filled;
|
||||
progressFill.fillMethod = Image.FillMethod.Horizontal;
|
||||
progressFill.fillOrigin = 0;
|
||||
progressFill.fillAmount = 0.5f;
|
||||
progressFill.fillAmount = 0f;
|
||||
|
||||
GameObject pctObj = new GameObject("PercentText");
|
||||
pctObj.transform.SetParent(progressTrack.transform, false);
|
||||
@@ -170,36 +217,27 @@ public class RestorationHUD : MonoBehaviour
|
||||
pctRt.sizeDelta = Vector2.zero;
|
||||
|
||||
progressPercentText = pctObj.AddComponent<TextMeshProUGUI>();
|
||||
progressPercentText.fontSize = 11f;
|
||||
progressPercentText.fontSize = 12f;
|
||||
progressPercentText.fontStyle = FontStyles.Bold;
|
||||
progressPercentText.color = Color.white;
|
||||
progressPercentText.alignment = TextAlignmentOptions.Center;
|
||||
progressPercentText.text = "50%";
|
||||
progressPercentText.text = "0%";
|
||||
|
||||
// 4. Нижняя подсказка / контекстное действие
|
||||
// Нижняя подсказка
|
||||
GameObject hintObj = new GameObject("HintText");
|
||||
hintObj.transform.SetParent(transform, false);
|
||||
hintObj.transform.SetParent(parent, false);
|
||||
RectTransform hintRt = hintObj.AddComponent<RectTransform>();
|
||||
hintRt.anchorMin = new Vector2(0f, 0f);
|
||||
hintRt.anchorMax = new Vector2(1f, 0f);
|
||||
hintRt.pivot = new Vector2(0.5f, 0f);
|
||||
hintRt.anchoredPosition = new Vector2(0f, 10f);
|
||||
hintRt.sizeDelta = new Vector2(-24f, 32f);
|
||||
hintRt.sizeDelta = new Vector2(-24f, 34f);
|
||||
|
||||
hintText = hintObj.AddComponent<TextMeshProUGUI>();
|
||||
hintText.fontSize = 12.5f;
|
||||
hintText.color = new Color(0.82f, 0.86f, 0.92f);
|
||||
hintText.fontSize = 13f;
|
||||
hintText.color = new Color(0.90f, 0.93f, 0.97f, 1f);
|
||||
hintText.alignment = TextAlignmentOptions.Center;
|
||||
hintText.text = "[Удерж. ЛКМ] Водите инструментом по детали";
|
||||
|
||||
// 5. Секция жидкостей (по умолчанию скрыта)
|
||||
fluidSection = new GameObject("FluidSection");
|
||||
fluidSection.transform.SetParent(transform, false);
|
||||
RectTransform fsRt = fluidSection.AddComponent<RectTransform>();
|
||||
fsRt.anchorMin = Vector2.zero;
|
||||
fsRt.anchorMax = Vector2.one;
|
||||
fsRt.sizeDelta = Vector2.zero;
|
||||
fluidSection.SetActive(false);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
@@ -211,14 +249,10 @@ public class RestorationHUD : MonoBehaviour
|
||||
}
|
||||
|
||||
if (canvasGroup != null)
|
||||
{
|
||||
canvasGroup.alpha = Mathf.Lerp(canvasGroup.alpha, targetAlpha, Time.deltaTime * fadeSpeed);
|
||||
}
|
||||
canvasGroup.alpha = Mathf.MoveTowards(canvasGroup.alpha, targetAlpha, Time.deltaTime * fadeSpeed);
|
||||
|
||||
if (progressFill != null)
|
||||
{
|
||||
progressFill.fillAmount = Mathf.Lerp(progressFill.fillAmount, currentFillAmount, Time.deltaTime * 15f);
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowRestorationProgress(
|
||||
@@ -229,6 +263,7 @@ public class RestorationHUD : MonoBehaviour
|
||||
bool isCorrectTool)
|
||||
{
|
||||
EnsureUIElementsCreated();
|
||||
lastShownFrame = Time.frameCount;
|
||||
targetAlpha = 1f;
|
||||
hideTimer = 0.25f;
|
||||
|
||||
@@ -237,20 +272,14 @@ public class RestorationHUD : MonoBehaviour
|
||||
|
||||
int percent = Mathf.RoundToInt(currentFillAmount * 100f);
|
||||
if (progressPercentText != null)
|
||||
{
|
||||
if (stage == RepairStage.Healthy || stage == RepairStage.Repaired)
|
||||
progressPercentText.text = "100%";
|
||||
else
|
||||
progressPercentText.text = $"{percent}%";
|
||||
}
|
||||
progressPercentText.text = (stage == RepairStage.Healthy || stage == RepairStage.Repaired) ? "100%" : $"{percent}%";
|
||||
|
||||
// Обновляем бейдж этапа и цвета
|
||||
SetupStageBadge(stage);
|
||||
|
||||
if (hintText != null)
|
||||
{
|
||||
hintText.text = contextualHint;
|
||||
hintText.color = isCorrectTool ? new Color(0.85f, 0.92f, 1.0f) : new Color(1.0f, 0.65f, 0.35f);
|
||||
hintText.color = isCorrectTool ? new Color(0.90f, 0.95f, 1f, 1f) : new Color(1f, 0.72f, 0.35f, 1f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,27 +294,27 @@ public class RestorationHUD : MonoBehaviour
|
||||
{
|
||||
case RepairStage.Healthy:
|
||||
badgeName = "Заводская";
|
||||
badgeColor = new Color(0.18f, 0.72f, 0.38f);
|
||||
badgeColor = new Color(0.18f, 0.72f, 0.38f, 1f);
|
||||
break;
|
||||
case RepairStage.Rusted:
|
||||
badgeName = "Ржавчина";
|
||||
badgeColor = new Color(0.92f, 0.38f, 0.12f);
|
||||
badgeColor = new Color(0.92f, 0.38f, 0.12f, 1f);
|
||||
break;
|
||||
case RepairStage.Cleaned:
|
||||
badgeName = "Зачищено";
|
||||
badgeColor = new Color(0.55f, 0.62f, 0.70f);
|
||||
badgeColor = new Color(0.50f, 0.58f, 0.68f, 1f);
|
||||
break;
|
||||
case RepairStage.Puttied:
|
||||
badgeName = "Шпаклёвка";
|
||||
badgeColor = new Color(0.82f, 0.70f, 0.35f);
|
||||
badgeColor = new Color(0.82f, 0.70f, 0.32f, 1f);
|
||||
break;
|
||||
case RepairStage.Sanded:
|
||||
badgeName = "Шлифовка";
|
||||
badgeColor = new Color(0.20f, 0.68f, 0.42f);
|
||||
badgeColor = new Color(0.20f, 0.68f, 0.42f, 1f);
|
||||
break;
|
||||
default:
|
||||
badgeName = "Восстановлено";
|
||||
badgeColor = new Color(0.15f, 0.75f, 0.95f);
|
||||
badgeColor = new Color(0.15f, 0.75f, 0.95f, 1f);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -303,6 +332,7 @@ public class RestorationHUD : MonoBehaviour
|
||||
Color fluidColor)
|
||||
{
|
||||
EnsureUIElementsCreated();
|
||||
lastShownFrame = Time.frameCount;
|
||||
targetAlpha = 1f;
|
||||
hideTimer = 0.25f;
|
||||
|
||||
@@ -310,22 +340,17 @@ public class RestorationHUD : MonoBehaviour
|
||||
currentFillAmount = fill01;
|
||||
int percent = Mathf.RoundToInt(fill01 * 100f);
|
||||
|
||||
Color opaqueFluid = new Color(fluidColor.r, fluidColor.g, fluidColor.b, 1f);
|
||||
if (titleText != null) titleText.text = tankTitle;
|
||||
if (stageBadgeText != null)
|
||||
{
|
||||
stageBadgeText.text = "Залив жидкости";
|
||||
stageBadgeBg.color = fluidColor;
|
||||
}
|
||||
|
||||
if (progressFill != null)
|
||||
{
|
||||
progressFill.color = fluidColor;
|
||||
stageBadgeBg.color = opaqueFluid;
|
||||
}
|
||||
|
||||
if (progressFill != null) progressFill.color = opaqueFluid;
|
||||
if (progressPercentText != null)
|
||||
{
|
||||
progressPercentText.text = $"{currentLiters:F1} / {maxLiters:F1} л ({percent}%)";
|
||||
}
|
||||
|
||||
if (hintText != null)
|
||||
{
|
||||
@@ -337,18 +362,20 @@ public class RestorationHUD : MonoBehaviour
|
||||
public void ShowCustomMessage(string message)
|
||||
{
|
||||
EnsureUIElementsCreated();
|
||||
lastShownFrame = Time.frameCount;
|
||||
targetAlpha = 1f;
|
||||
hideTimer = 0.25f;
|
||||
|
||||
if (hintText != null)
|
||||
{
|
||||
hintText.text = message;
|
||||
hintText.color = new Color(1.0f, 0.85f, 0.45f);
|
||||
hintText.color = new Color(1f, 0.85f, 0.45f, 1f);
|
||||
}
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
if (Time.frameCount == lastShownFrame) return;
|
||||
targetAlpha = 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user