using System; using System.Collections; using System.Collections.Generic; using Unity.VisualScripting; using UnityEngine; public class TowerPlacementManager : MonoBehaviour { /// /// Sender /// public static event Action OnSpawnGridRequested; public static TowerPlacementManager Singleton; // Section: Selection private SlotManager CurrentSelected; // Section: Debug public GameObject DebugTowerPrefab; private void Start() { if (Singleton != this) Destroy(Singleton); Singleton = this; OnSpawnGridRequested?.Invoke(this); } public void OnSlotClicked(SlotManager slot, GridManager grid, int x, int y) { slot.gameObject.GetComponentInChildren().material.color = Color.blue; OnSelectSlot(slot); SpawnTowerAtSelected(DebugTowerPrefab); } // Called when a slot is selected public void OnSelectSlot(SlotManager slot) { // Detects if the selected slot is new if (CurrentSelected != null && CurrentSelected != slot) OnDeselectSlot(CurrentSelected, slot); CurrentSelected = slot; slot.gameObject.GetComponentInChildren().material.color = Color.blue; } // Called when another slot is getting selected public void OnDeselectSlot(SlotManager prevSlot, SlotManager newSlot) { prevSlot.gameObject.GetComponentInChildren().material.color = Color.white; } public void SpawnTowerAtSelected(GameObject towerPrefab) { Instantiate(towerPrefab, CurrentSelected.transform); } }