From 7c78c430bb7d4eb5cd865ed5082d3fa3f8bed192 Mon Sep 17 00:00:00 2001 From: BOT Alex <44818698+MagicBOTAlex@users.noreply.github.com> Date: Sat, 20 Apr 2024 19:22:54 +0200 Subject: [PATCH] Silhouette semi working --- .../PlacementSystem/CameraSlotClickDetect.cs | 2 +- Assets/Scripts/PlacementSystem/GridManager.cs | 2 + .../PlacementSystem/PlacementManager.cs | 37 ++++++++++++++----- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/Assets/Scripts/PlacementSystem/CameraSlotClickDetect.cs b/Assets/Scripts/PlacementSystem/CameraSlotClickDetect.cs index f505783..717a401 100644 --- a/Assets/Scripts/PlacementSystem/CameraSlotClickDetect.cs +++ b/Assets/Scripts/PlacementSystem/CameraSlotClickDetect.cs @@ -43,10 +43,10 @@ public class CameraSlotClickDetect : MonoBehaviour if (PrevHoveredSlot != null && PrevHoveredSlot != slotInfo) { - slotInfo.OnHovered(); PrevHoveredSlot.OnUnHovered(); } + slotInfo.OnHovered(); PrevHoveredSlot = slotInfo; } else diff --git a/Assets/Scripts/PlacementSystem/GridManager.cs b/Assets/Scripts/PlacementSystem/GridManager.cs index d937eba..329022f 100644 --- a/Assets/Scripts/PlacementSystem/GridManager.cs +++ b/Assets/Scripts/PlacementSystem/GridManager.cs @@ -48,6 +48,8 @@ public class GridManager : MonoBehaviour infoHolder.y = y; infoHolder.OnSlotClicked += sender.OnSlotClicked; + infoHolder.OnSlotHovered += sender.OnSlotHovered; + infoHolder.OnSlotUnHovered += sender.OnSlotUnHovered; SpawnedSlots.Add(spawned); } diff --git a/Assets/Scripts/PlacementSystem/PlacementManager.cs b/Assets/Scripts/PlacementSystem/PlacementManager.cs index 610efce..1590490 100644 --- a/Assets/Scripts/PlacementSystem/PlacementManager.cs +++ b/Assets/Scripts/PlacementSystem/PlacementManager.cs @@ -2,6 +2,7 @@ using System; using System.Collections; using System.Collections.Generic; using System.Linq; +using Unity.Mathematics; using Unity.VisualScripting; using UnityEngine; @@ -13,8 +14,11 @@ public class TowerPlacementManager : MonoBehaviour public static event Action OnSpawnGridRequested; public static TowerPlacementManager Singleton; - // Section: Selection - private SlotManager CurrentSelected; + // Section: Mouse + private SlotManager CurrentSelectedSlot; + private SlotManager CurrentHovered; + + private GameObject SilhouettedObject; // Section: Debug public GameObject DebugTowerPrefab; @@ -28,8 +32,6 @@ public class TowerPlacementManager : MonoBehaviour Singleton = this; OnSpawnGridRequested?.Invoke(this); - - ToSilhouette(DebugTowerPrefab); } public void OnSlotClicked(SlotManager slot, GridManager grid, int x, int y) @@ -44,9 +46,9 @@ public class TowerPlacementManager : MonoBehaviour public void OnSelectSlot(SlotManager slot) { // Detects if the selected slot is new - if (CurrentSelected != null && CurrentSelected != slot) - OnDeselectSlot(CurrentSelected, slot); - CurrentSelected = slot; + if (CurrentSelectedSlot != null && CurrentSelectedSlot != slot) + OnDeselectSlot(CurrentSelectedSlot, slot); + CurrentSelectedSlot = slot; slot.gameObject.GetComponentInChildren().material.color = Color.blue; } @@ -59,12 +61,29 @@ public class TowerPlacementManager : MonoBehaviour public void SpawnTowerAtSelected(GameObject towerPrefab) { - Instantiate(towerPrefab, CurrentSelected.transform); + Instantiate(towerPrefab, CurrentSelectedSlot.transform); } - public void OnSlotHovered() + public void OnSlotHovered(SlotManager slot, GridManager grid, int x, int y) { + print("Hovered"); + if (SilhouettedObject == null) + SilhouettedObject = ToSilhouette(DebugTowerPrefab); + + //SilhouettedObject.SetActive(true); + SilhouettedObject.transform.parent = slot.TowerSpawnPoint.transform; + SilhouettedObject.transform.localPosition = Vector3.zero; + SilhouettedObject.transform.localRotation = quaternion.identity; + } + + public void OnSlotUnHovered(SlotManager slot, GridManager grid, int x, int y) + { + print("UnHovered"); + + //SilhouettedObject.SetActive(false); + SilhouettedObject.transform.parent = null; + SilhouettedObject.transform.position = Vector3.zero; }