Compare commits

..

No commits in common. "6806df3fedf690049311f69292e437a924ca3901" and "f5fade285f39c61d3635597fb158c1b6822008a3" have entirely different histories.

3 changed files with 3 additions and 43 deletions

View File

@ -1,6 +1,5 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine; using UnityEngine;
public class CameraSlotClickDetect : MonoBehaviour public class CameraSlotClickDetect : MonoBehaviour
@ -8,19 +7,15 @@ public class CameraSlotClickDetect : MonoBehaviour
public Camera mainCamera; public Camera mainCamera;
public LayerMask layerMask; public LayerMask layerMask;
private SlotManager PrevHoveredSlot;
void Update() void Update()
{ {
if (Input.GetMouseButtonDown(0)) if (Input.GetMouseButtonDown(0))
{ {
ShootClickRay(); ShootRay();
}
} }
ShootHoverRay(); void ShootRay()
}
void ShootClickRay()
{ {
Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition); Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
RaycastHit hit; RaycastHit hit;
@ -29,29 +24,8 @@ public class CameraSlotClickDetect : MonoBehaviour
{ {
var slotInfo = hit.collider.gameObject.GetComponentInParent<SlotManager>(); var slotInfo = hit.collider.gameObject.GetComponentInParent<SlotManager>();
slotInfo.OnClick(); slotInfo.OnClick();
}
}
void ShootHoverRay() Debug.Log($"Hit PlacementSlot! At ({slotInfo.x}, {slotInfo.y})");
{
Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask))
{
var slotInfo = hit.collider.gameObject.GetComponentInParent<SlotManager>();
if (PrevHoveredSlot != null && PrevHoveredSlot != slotInfo)
{
slotInfo.OnHovered();
PrevHoveredSlot.OnUnHovered();
}
PrevHoveredSlot = slotInfo;
}
else
{
PrevHoveredSlot = null;
} }
} }
} }

View File

@ -67,7 +67,6 @@ public class TowerPlacementManager : MonoBehaviour
} }
[Space(10)] [Space(10)]
public Material SilhouetteMaterial; public Material SilhouetteMaterial;
public GameObject ToSilhouette(GameObject obj) public GameObject ToSilhouette(GameObject obj)

View File

@ -16,21 +16,8 @@ public class SlotManager : MonoBehaviour
/// </summary> /// </summary>
public event Action<SlotManager, GridManager, int, int> OnSlotClicked; public event Action<SlotManager, GridManager, int, int> OnSlotClicked;
public event Action<SlotManager, GridManager, int, int> OnSlotHovered;
public event Action<SlotManager, GridManager, int, int> OnSlotUnHovered;
public void OnClick() public void OnClick()
{ {
OnSlotClicked?.Invoke(this, spawnerRef, x, y); OnSlotClicked?.Invoke(this, spawnerRef, x, y);
} }
public void OnHovered()
{
OnSlotHovered?.Invoke(this, spawnerRef, x, y);
}
public void OnUnHovered()
{
OnSlotUnHovered?.Invoke(this, spawnerRef, x, y);
}
} }