Made building preview work

This commit is contained in:
2026-03-31 13:30:26 +01:00
parent 40cb81e740
commit c8f704074a

View File

@@ -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<BuildingBase>();
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;
}
}
}