Finalize cards work
This commit is contained in:
@@ -25,6 +25,9 @@ namespace Minigames.CardSorting.Core
|
||||
private bool _isGarbage;
|
||||
private CardRarity _rarity; // Only relevant for cards
|
||||
|
||||
// Track last hovered box for hover indicator feedback
|
||||
private SortingBox _lastHoveredBox;
|
||||
|
||||
// Events - item emits notifications, conveyor subscribes
|
||||
public event System.Action<SortableItem, SortingBox, bool> OnItemDroppedInBox;
|
||||
public event System.Action<SortableItem> OnItemDroppedOnFloor;
|
||||
@@ -70,30 +73,22 @@ namespace Minigames.CardSorting.Core
|
||||
|
||||
/// <summary>
|
||||
/// Setup item as a card. Prefab is already visually configured.
|
||||
/// State machine auto-starts via Initialization component (calls StartMachine in Start).
|
||||
/// </summary>
|
||||
public void SetupAsCard(CardRarity rarity)
|
||||
{
|
||||
_isGarbage = false;
|
||||
_rarity = rarity;
|
||||
|
||||
if (stateMachine != null && !string.IsNullOrEmpty(initialState))
|
||||
{
|
||||
stateMachine.ChangeState(initialState);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Setup item as garbage. Prefab is already visually configured.
|
||||
/// State machine auto-starts via Initialization component (calls StartMachine in Start).
|
||||
/// </summary>
|
||||
public void SetupAsGarbage()
|
||||
{
|
||||
_isGarbage = true;
|
||||
_rarity = CardRarity.Normal; // Default, not used for garbage
|
||||
|
||||
if (stateMachine != null && !string.IsNullOrEmpty(initialState))
|
||||
{
|
||||
stateMachine.ChangeState(initialState);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDragStartedHook()
|
||||
@@ -129,6 +124,13 @@ namespace Minigames.CardSorting.Core
|
||||
{
|
||||
base.OnDragEndedHook();
|
||||
|
||||
// Hide hover indicator on any previously hovered box
|
||||
if (_lastHoveredBox != null)
|
||||
{
|
||||
_lastHoveredBox.HideHoverIndicator();
|
||||
_lastHoveredBox = null;
|
||||
}
|
||||
|
||||
// Check what type of slot we're over
|
||||
if (CurrentSlot is SortingBox box)
|
||||
{
|
||||
@@ -189,6 +191,7 @@ namespace Minigames.CardSorting.Core
|
||||
UnityEngine.EventSystems.EventSystem.current.RaycastAll(eventData, raycastResults);
|
||||
|
||||
DraggableSlot hoveredSlot = null;
|
||||
SortingBox hoveredBox = null;
|
||||
|
||||
// Find first slot (SortingBox or ConveyorBeltSlot) in raycast results
|
||||
foreach (var result in raycastResults)
|
||||
@@ -198,6 +201,7 @@ namespace Minigames.CardSorting.Core
|
||||
if (box != null)
|
||||
{
|
||||
hoveredSlot = box;
|
||||
hoveredBox = box;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -210,6 +214,26 @@ namespace Minigames.CardSorting.Core
|
||||
}
|
||||
}
|
||||
|
||||
// Update hover indicator on boxes
|
||||
if (hoveredBox != _lastHoveredBox)
|
||||
{
|
||||
// Hide indicator on previously hovered box
|
||||
if (_lastHoveredBox != null)
|
||||
{
|
||||
_lastHoveredBox.HideHoverIndicator();
|
||||
}
|
||||
|
||||
// Show indicator on newly hovered box
|
||||
if (hoveredBox != null)
|
||||
{
|
||||
// Check if this is the correct box for visual feedback
|
||||
bool isCorrectBox = hoveredBox.ValidateItem(this);
|
||||
hoveredBox.ShowHoverIndicator(isCorrectBox);
|
||||
}
|
||||
|
||||
_lastHoveredBox = hoveredBox;
|
||||
}
|
||||
|
||||
// Update current slot (used in OnDragEndedHook)
|
||||
if (hoveredSlot != null && hoveredSlot != CurrentSlot)
|
||||
{
|
||||
|
||||
@@ -40,6 +40,20 @@ namespace Minigames.CardSorting.Core
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// Capture original transform for drag animations
|
||||
// This preserves the prefab's configured scale (e.g., 0.05 for world-space Canvas)
|
||||
var currentScale = transform.localScale;
|
||||
if (currentScale.x < 0.01f && currentScale.y < 0.01f && currentScale.z < 0.01f)
|
||||
{
|
||||
OriginalScale = Vector3.one; // Fallback if scale is ~0
|
||||
}
|
||||
else
|
||||
{
|
||||
OriginalScale = currentScale;
|
||||
}
|
||||
OriginalPosition = transform.localPosition;
|
||||
OriginalRotation = transform.localRotation;
|
||||
|
||||
// Auto-find components if not assigned
|
||||
if (visualTransform == null)
|
||||
{
|
||||
|
||||
@@ -13,8 +13,47 @@ namespace Minigames.CardSorting.Core
|
||||
[Header("Box Configuration")]
|
||||
[SerializeField] private BoxType boxType;
|
||||
|
||||
[Header("Visual Feedback")]
|
||||
[Tooltip("Sprite renderer to show when an item is hovering over this box")]
|
||||
[SerializeField] private SpriteRenderer hoverIndicator;
|
||||
|
||||
public BoxType BoxType => boxType;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// Hide hover indicator on start
|
||||
if (hoverIndicator != null)
|
||||
{
|
||||
hoverIndicator.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show the hover indicator when an item is hovering over this box.
|
||||
/// </summary>
|
||||
/// <param name="isCorrect">If true, tints the indicator green. Otherwise uses default color.</param>
|
||||
public void ShowHoverIndicator(bool isCorrect = false)
|
||||
{
|
||||
if (hoverIndicator != null)
|
||||
{
|
||||
hoverIndicator.enabled = true;
|
||||
|
||||
// Tint green if correct box, white otherwise
|
||||
hoverIndicator.color = isCorrect ? Color.green : Color.white;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hide the hover indicator when an item stops hovering.
|
||||
/// </summary>
|
||||
public void HideHoverIndicator()
|
||||
{
|
||||
if (hoverIndicator != null)
|
||||
{
|
||||
hoverIndicator.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if item belongs in this box.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user