Более менее пашет
This commit is contained in:
1 parent
eed6b79efc
commit
33168b98d1
26 files changed
+443071
-19380
No files matched your search
@@ -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