Can now destroy buildings

This commit is contained in:
2026-04-13 13:28:45 +01:00
parent b481b27f8b
commit d8253bd275
9 changed files with 439 additions and 27 deletions

View File

@@ -1,4 +1,8 @@
using UnityEngine;
using PashaBibko.Pacore.Attributes;
using JetBrains.Annotations;
using UnityEngine.Scripting;
using Fruitomation.Global;
using UnityEngine;
namespace Fruitomation.Game
{
@@ -7,7 +11,21 @@ namespace Fruitomation.Game
[Header("Building Properties")]
[SerializeField] private Sprite BuildingSprite;
[field: SerializeField] public Vector2Int SizeOnGrid { get; private set; }
private BuildingManager Manager;
public void SetManager(BuildingManager manager) => Manager = manager;
[UsedImplicitly, Preserve, InspectorCallable("Click Building")] public void OnBuildingClicked()
{
Debug.Log($"Building clicked {gameObject.name}");
if (GameStateController.Is(GameState.Editing))
{
Manager.RemoveBuilding(this);
Destroy(gameObject);
}
}
public Sprite Sprite => BuildingSprite;
}
}

View File

@@ -18,7 +18,9 @@ namespace Fruitomation.Game
}
private bool[,] InhabitedCells { get; } = new bool[96, 49];
private List<BuildingInfo> Buildings { get; } = new();
private List<Building> Buildings { get; } = new();
public void RemoveBuilding(Building building) => Buildings.Remove(building);
public bool AddBuildingAt(Vector2Int position, GameObject prefab, bool isFlipped)
{
@@ -29,6 +31,8 @@ namespace Fruitomation.Game
go.GetComponent<Building>(),
go.GetComponent<RectTransform>()
);
info.Building.SetManager(this);
Vector2Int p0 = position * 40;
Vector2Int p1 = p0 + new Vector2Int(20, 100);
@@ -43,8 +47,6 @@ namespace Fruitomation.Game
info.Rect.transform.localScale = new Vector3(isFlipped ? -1f : 1f, 1f, 1f);
Debug.Log(g0);
//
for (int x = g0.x; x < g0.x + info.Building.SizeOnGrid.x; x++)
for (int y = g0.y; y < g0.y + info.Building.SizeOnGrid.y; y++)
@@ -63,7 +65,7 @@ namespace Fruitomation.Game
InhabitedCells[x, y] = true;
}
Buildings.Add(info);
Buildings.Add(info.Building);
return true;
}
}