- TowerSelectItem 显示问题
- CombatSelectForm 不同分辨率的适配
This commit is contained in:
SepComet
2026-03-09 19:59:11 +08:00
parent af20eeecfa
commit 2d09b01c55
8 changed files with 145 additions and 52 deletions
@@ -33,7 +33,7 @@ namespace GeometryTD.UI
return;
}
_content.anchoredPosition = context.ContentPosition;
_content.anchoredPosition = ResolveContentAnchoredPosition(context.ScreenPosition);
if (_buildArea != null)
{
@@ -107,5 +107,35 @@ namespace GeometryTD.UI
Transform contentTransform = transform.Find("Content");
_content = contentTransform as RectTransform;
}
private Vector2 ResolveContentAnchoredPosition(Vector2 screenPosition)
{
if (_content == null)
{
return Vector2.zero;
}
RectTransform parentRect = _content.parent as RectTransform;
if (parentRect == null)
{
return screenPosition;
}
Canvas canvas = _content.GetComponentInParent<Canvas>();
Canvas rootCanvas = canvas != null ? canvas.rootCanvas : null;
Camera uiCamera = null;
if (rootCanvas != null && rootCanvas.renderMode != RenderMode.ScreenSpaceOverlay)
{
uiCamera = rootCanvas.worldCamera != null ? rootCanvas.worldCamera : Camera.main;
}
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(parentRect, screenPosition, uiCamera,
out Vector2 localPoint))
{
return Vector2.zero;
}
return localPoint;
}
}
}