From d405c9df12c4808bfe6bb3e916efdaf811b409c4 Mon Sep 17 00:00:00 2001 From: "DESKTOP-SAJ6RKV\\Administrator" Date: Sun, 4 May 2025 16:21:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E5=9B=BE=E7=89=87=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HotFix/GameLogic/Actor/ActorHItem.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Actor/ActorHItem.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Actor/ActorHItem.cs index 1ac6fb92..918c02ac 100644 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Actor/ActorHItem.cs +++ b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Actor/ActorHItem.cs @@ -104,6 +104,7 @@ namespace GameLogic if (oneNum == 0) { m_imgValue.fillAmount = 0.1f; + AlignCarWithFillAmount(); return; } @@ -114,6 +115,30 @@ namespace GameLogic percent = 1; } m_imgValue.fillAmount = percent; + AlignCarWithFillAmount(); + } + + private void AlignCarWithFillAmount() + { + if (m_imgValue == null || m_rectCar == null) + return; + + // 获取 m_imgValue 的 RectTransform + RectTransform imgRectTransform = m_imgValue.GetComponent(); + + if (imgRectTransform == null) + return; + + // 获取 m_imgValue 的宽度 + float imgWidth = imgRectTransform.rect.width; + + // 计算裁剪后的 X 坐标 + float targetX = imgWidth * m_imgValue.fillAmount; + + // 更新 m_rectCar 的位置 + Vector3 localPosition = m_rectCar.localPosition; + localPosition.x = targetX - (imgWidth / 2); // 调整为相对于中心点的位置 + m_rectCar.localPosition = localPosition; } } }