From c8f704074ae5efed5f40f2bb8ae3f0a33a147353 Mon Sep 17 00:00:00 2001 From: Pasha Date: Tue, 31 Mar 2026 13:30:26 +0100 Subject: [PATCH] Made building preview work --- Assets/Scripts/UI/GameCursor.cs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/Assets/Scripts/UI/GameCursor.cs b/Assets/Scripts/UI/GameCursor.cs index 1884c11..0e7bb4b 100644 --- a/Assets/Scripts/UI/GameCursor.cs +++ b/Assets/Scripts/UI/GameCursor.cs @@ -133,20 +133,29 @@ namespace Fruitomation.UI CursorImage.enabled = false; BuildingPreview.enabled = true; - // - Vector2Int p0 = GridPosition - new Vector2Int(48, 24); - Vector2Int p1 = p0 * 40; - Vector2Int p2 = p1 + new Vector2Int(20, 100); - BuildingPreview.rectTransform.anchoredPosition = p2; - // BuildingBase building = BuildingPrefab.GetComponent(); BuildingPreview.material = new Material(Shader.Find("UI/Default")) { mainTexture = building.Texture }; - + BuildingPreview.rectTransform.sizeDelta = building.SizeOnGrid * 40; + + // + Vector2Int p0 = new + ( + Math.Clamp(GridPosition.x, 0, 96 - building.SizeOnGrid.x), + Math.Clamp(GridPosition.y, 0, 49 - building.SizeOnGrid.y) + ); + Vector2Int p1 = p0 - new Vector2Int(48, 24); + Vector2Int p2 = p1 * 40; + Vector2Int p3 = p2 + new Vector2Int(20, 100); + + Vector2 o0 = building.SizeOnGrid - Vector2.one; + Vector2 o1 = o0 * 20; + Vector2 p4 = p3 + o1; + BuildingPreview.rectTransform.anchoredPosition = p4; } } }