3DTD/Assets/Scripts/PlacementSystem/PlacementManager.cs

50 lines
1.4 KiB
C#
Raw Normal View History

2024-04-20 01:51:12 +02:00
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class TowerPlacementManager : MonoBehaviour
{
/// <summary>
/// Sender
/// </summary>
public static event Action<TowerPlacementManager> OnSpawnGridRequested;
public static TowerPlacementManager Singleton;
2024-04-20 15:38:21 +02:00
// Section: Selection
private SlotManager CurrentSelected;
2024-04-20 01:51:12 +02:00
private void Start()
{
if (Singleton != this)
Destroy(Singleton);
Singleton = this;
OnSpawnGridRequested?.Invoke(this);
}
public void OnSlotClicked(SlotManager slot, GridManager grid, int x, int y)
{
2024-04-20 15:38:21 +02:00
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;
}
2024-04-20 01:51:12 +02:00
2024-04-20 15:38:21 +02:00
// Called when another slot is getting selected
public void OnDeselectSlot(SlotManager prevSlot, SlotManager newSlot)
{
prevSlot.gameObject.GetComponentInChildren<Renderer>().material.color = Color.white;
2024-04-20 01:51:12 +02:00
}
}