fix
- TowerSelectItem 显示问题 - CombatSelectForm 不同分辨率的适配
This commit is contained in:
@@ -20,7 +20,7 @@ namespace GeometryTD.Entity
|
||||
{
|
||||
userData = null;
|
||||
if (tilemap == null || !TryGetPointerWorldPosition(tilemap, mapTransform, out Vector3 worldPosition,
|
||||
out Vector2 contentPosition))
|
||||
out Vector2 screenPosition))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -28,25 +28,25 @@ namespace GeometryTD.Entity
|
||||
Vector3Int clickedCell = tilemap.WorldToCell(worldPosition);
|
||||
CombatSelectClickObjectType clickObjectType = CombatSelectClickObjectType.None;
|
||||
int towerEntityId = 0;
|
||||
Vector2 resolvedContentPosition = contentPosition;
|
||||
Vector2 resolvedScreenPosition = screenPosition;
|
||||
|
||||
if (towerEntityIdByFoundationCell != null &&
|
||||
towerEntityIdByFoundationCell.TryGetValue(clickedCell, out int occupiedTowerEntityId))
|
||||
{
|
||||
clickObjectType = CombatSelectClickObjectType.Tower;
|
||||
towerEntityId = occupiedTowerEntityId;
|
||||
resolvedContentPosition = BuildContentPositionFromCell(tilemap, clickedCell, contentPosition);
|
||||
resolvedScreenPosition = BuildScreenPositionFromCell(tilemap, clickedCell, screenPosition);
|
||||
}
|
||||
else if (isFoundationCell != null && isFoundationCell(clickedCell))
|
||||
{
|
||||
clickObjectType = CombatSelectClickObjectType.Foundation;
|
||||
resolvedContentPosition = BuildContentPositionFromCell(tilemap, clickedCell, contentPosition);
|
||||
resolvedScreenPosition = BuildScreenPositionFromCell(tilemap, clickedCell, screenPosition);
|
||||
}
|
||||
|
||||
userData = new CombatSelectFormUserData
|
||||
{
|
||||
ClickObjectType = clickObjectType,
|
||||
ContentPosition = resolvedContentPosition,
|
||||
ScreenPosition = resolvedScreenPosition,
|
||||
WorldPosition = worldPosition,
|
||||
CellPosition = clickedCell,
|
||||
TowerEntityId = towerEntityId,
|
||||
@@ -59,10 +59,10 @@ namespace GeometryTD.Entity
|
||||
|
||||
private static bool TryGetPointerWorldPosition(Tilemap tilemap, Transform mapTransform,
|
||||
out Vector3 worldPosition,
|
||||
out Vector2 contentPosition)
|
||||
out Vector2 screenPosition)
|
||||
{
|
||||
worldPosition = Vector3.zero;
|
||||
contentPosition = Vector2.zero;
|
||||
screenPosition = Vector2.zero;
|
||||
|
||||
Camera mainCamera = GameEntry.Scene != null ? GameEntry.Scene.MainCamera : Camera.main;
|
||||
if (mainCamera == null)
|
||||
@@ -84,38 +84,37 @@ namespace GeometryTD.Entity
|
||||
}
|
||||
|
||||
worldPosition = ray.GetPoint(enterDistance);
|
||||
contentPosition = BuildContentPosition(Input.mousePosition);
|
||||
contentPosition = new Vector2((int)contentPosition.x, (int)contentPosition.y);
|
||||
contentPosition = new Vector2(contentPosition.x + 0.5f, contentPosition.y + 0.5f);
|
||||
screenPosition = BuildScreenPosition(Input.mousePosition);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static Vector2 BuildContentPosition(Vector3 pointerScreenPosition)
|
||||
private static Vector2 BuildScreenPosition(Vector3 pointerScreenPosition)
|
||||
{
|
||||
return new Vector2(
|
||||
pointerScreenPosition.x - Screen.width * 0.5f,
|
||||
pointerScreenPosition.y - Screen.height * 0.5f);
|
||||
return new Vector2(pointerScreenPosition.x, pointerScreenPosition.y);
|
||||
}
|
||||
|
||||
private static Vector2 BuildContentPositionFromCell(Tilemap tilemap, Vector3Int cellPosition,
|
||||
Vector2 fallbackContentPosition)
|
||||
private static Vector2 BuildScreenPositionFromCell(Tilemap tilemap, Vector3Int cellPosition,
|
||||
Vector2 fallbackScreenPosition)
|
||||
{
|
||||
if (tilemap == null)
|
||||
{
|
||||
return fallbackContentPosition;
|
||||
return fallbackScreenPosition;
|
||||
}
|
||||
|
||||
Camera mainCamera = GameEntry.Scene != null ? GameEntry.Scene.MainCamera : Camera.main;
|
||||
if (mainCamera == null)
|
||||
{
|
||||
return fallbackContentPosition;
|
||||
return fallbackScreenPosition;
|
||||
}
|
||||
|
||||
Vector3 cellCenterWorld = tilemap.GetCellCenterWorld(cellPosition);
|
||||
Vector3 cellScreenPosition = mainCamera.WorldToScreenPoint(cellCenterWorld);
|
||||
Vector2 contentPosition = BuildContentPosition(cellScreenPosition);
|
||||
contentPosition = new Vector2((int)contentPosition.x, (int)contentPosition.y);
|
||||
return new Vector2(contentPosition.x + 0.5f, contentPosition.y + 0.5f);
|
||||
if (cellScreenPosition.z < 0f)
|
||||
{
|
||||
return fallbackScreenPosition;
|
||||
}
|
||||
|
||||
return BuildScreenPosition(cellScreenPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user