diff --git a/Assets/Scripts/PlacementSystem/CameraSlotClickDetect.cs b/Assets/Scripts/PlacementSystem/CameraSlotClickDetect.cs index 90378c5..bb24fe4 100644 --- a/Assets/Scripts/PlacementSystem/CameraSlotClickDetect.cs +++ b/Assets/Scripts/PlacementSystem/CameraSlotClickDetect.cs @@ -23,6 +23,7 @@ public class CameraSlotClickDetect : MonoBehaviour if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask)) { var slotInfo = hit.collider.gameObject.GetComponentInParent(); + slotInfo.OnClick(); Debug.Log($"Hit PlacementSlot! At ({slotInfo.x}, {slotInfo.y})"); } diff --git a/Assets/Scripts/PlacementSystem/GridManager.cs b/Assets/Scripts/PlacementSystem/GridManager.cs index f902747..73609a3 100644 --- a/Assets/Scripts/PlacementSystem/GridManager.cs +++ b/Assets/Scripts/PlacementSystem/GridManager.cs @@ -7,14 +7,19 @@ public class GridManager : MonoBehaviour { [SerializeField] private Vector2Int GridSize; [SerializeField] private float Gap = 0.1f; + [SerializeField] private GridType gridType = GridType.Primary; [Space(10)] [SerializeField] private GameObject TowerSlotPrefab; [DoNotSerialize] public List SpawnedSlots = new(); + [DoNotSerialize] public string[,] GridStates; + private void OnEnable() { TowerPlacementManager.OnSpawnGridRequested += SpawnSlots; + + GridStates = new string[GridSize.x, GridSize.y]; } private void OnDisable() @@ -39,8 +44,17 @@ public class GridManager : MonoBehaviour infoHolder.x = x; infoHolder.y = y; + infoHolder.OnSlotClicked += sender.OnSlotClicked; + SpawnedSlots.Add(spawned); } } } +} + +public enum GridType +{ + Primary, + Wall, + Celling } \ No newline at end of file diff --git a/Assets/Scripts/PlacementSystem/PlacementManager.cs b/Assets/Scripts/PlacementSystem/PlacementManager.cs index bdc46cd..9095ef8 100644 --- a/Assets/Scripts/PlacementSystem/PlacementManager.cs +++ b/Assets/Scripts/PlacementSystem/PlacementManager.cs @@ -10,9 +10,11 @@ public class TowerPlacementManager : MonoBehaviour /// Sender /// public static event Action OnSpawnGridRequested; - public static TowerPlacementManager Singleton; + // Section: Selection + private SlotManager CurrentSelected; + private void Start() { if (Singleton != this) @@ -24,6 +26,24 @@ public class TowerPlacementManager : MonoBehaviour public void OnSlotClicked(SlotManager slot, GridManager grid, int x, int y) { + slot.gameObject.GetComponentInChildren().material.color = Color.blue; + OnSelectSlot(slot); + } + // 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; } } diff --git a/Assets/Scripts/PlacementSystem/SlotManager.cs b/Assets/Scripts/PlacementSystem/SlotManager.cs index 1cf3f1a..9cb1121 100644 --- a/Assets/Scripts/PlacementSystem/SlotManager.cs +++ b/Assets/Scripts/PlacementSystem/SlotManager.cs @@ -12,5 +12,10 @@ public class SlotManager : MonoBehaviour /// /// (Sender, spawnerRef, X, Y) /// - public static event Action OnSlotClicked; + public event Action OnSlotClicked; + + public void OnClick() + { + OnSlotClicked?.Invoke(this, spawnerRef, x, y); + } }