处理图片位置更新
This commit is contained in:
parent
8283922bf9
commit
d405c9df12
@ -104,6 +104,7 @@ namespace GameLogic
|
|||||||
if (oneNum == 0)
|
if (oneNum == 0)
|
||||||
{
|
{
|
||||||
m_imgValue.fillAmount = 0.1f;
|
m_imgValue.fillAmount = 0.1f;
|
||||||
|
AlignCarWithFillAmount();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,6 +115,30 @@ namespace GameLogic
|
|||||||
percent = 1;
|
percent = 1;
|
||||||
}
|
}
|
||||||
m_imgValue.fillAmount = percent;
|
m_imgValue.fillAmount = percent;
|
||||||
|
AlignCarWithFillAmount();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AlignCarWithFillAmount()
|
||||||
|
{
|
||||||
|
if (m_imgValue == null || m_rectCar == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 获取 m_imgValue 的 RectTransform
|
||||||
|
RectTransform imgRectTransform = m_imgValue.GetComponent<RectTransform>();
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user