Slots now selectable
This commit is contained in:
parent
15cb065999
commit
6acb4293e0
|
@ -23,6 +23,7 @@ public class CameraSlotClickDetect : MonoBehaviour
|
|||
if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask))
|
||||
{
|
||||
var slotInfo = hit.collider.gameObject.GetComponentInParent<SlotManager>();
|
||||
slotInfo.OnClick();
|
||||
|
||||
Debug.Log($"Hit PlacementSlot! At ({slotInfo.x}, {slotInfo.y})");
|
||||
}
|
||||
|
|
|
@ -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<GameObject> 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
|
||||
}
|
|
@ -10,9 +10,11 @@ public class TowerPlacementManager : MonoBehaviour
|
|||
/// Sender
|
||||
/// </summary>
|
||||
public static event Action<TowerPlacementManager> 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<Renderer>().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<Renderer>().material.color = Color.blue;
|
||||
}
|
||||
|
||||
// Called when another slot is getting selected
|
||||
public void OnDeselectSlot(SlotManager prevSlot, SlotManager newSlot)
|
||||
{
|
||||
prevSlot.gameObject.GetComponentInChildren<Renderer>().material.color = Color.white;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,5 +12,10 @@ public class SlotManager : MonoBehaviour
|
|||
/// <summary>
|
||||
/// (Sender, spawnerRef, X, Y)
|
||||
/// </summary>
|
||||
public static event Action<SlotManager, GridManager, int, int> OnSlotClicked;
|
||||
public event Action<SlotManager, GridManager, int, int> OnSlotClicked;
|
||||
|
||||
public void OnClick()
|
||||
{
|
||||
OnSlotClicked?.Invoke(this, spawnerRef, x, y);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue