Finalize cards work
This commit is contained in:
@@ -12,6 +12,10 @@ PrefabInstance:
|
||||
propertyPath: m_Name
|
||||
value: SortableCard1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7509179989723220838, guid: 342ae09811d1668448e141153437746d, type: 3}
|
||||
propertyPath: m_Sprite
|
||||
value:
|
||||
objectReference: {fileID: -987280688, guid: 9dc9328453e98284281c453fac246f7c, type: 3}
|
||||
- target: {fileID: 8730990344497138252, guid: 342ae09811d1668448e141153437746d, type: 3}
|
||||
propertyPath: m_Pivot.x
|
||||
value: 0.5
|
||||
|
||||
@@ -320,7 +320,7 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 87ed5616041a4d878f452a8741e1eeab, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: AppleHillsScripts::UI.CardSystem.StateMachine.CardStateMachine
|
||||
defaultState: {fileID: 0}
|
||||
defaultState: {fileID: 6327696013805378735}
|
||||
currentState: {fileID: 0}
|
||||
_unityEventsFolded: 0
|
||||
verbose: 0
|
||||
|
||||
@@ -30,8 +30,9 @@ Transform:
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 6518373398422451678}
|
||||
- {fileID: 5850617675450214222}
|
||||
- {fileID: 9217432009376634151}
|
||||
- {fileID: 6518373398422451678}
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &3934371481972522631
|
||||
@@ -55,6 +56,7 @@ MonoBehaviour:
|
||||
occupantScale: {x: 1, y: 1, z: 1}
|
||||
scaleTransitionDuration: 0.3
|
||||
boxType: 0
|
||||
hoverIndicator: {fileID: 7267684468009174768}
|
||||
--- !u!1 &6923066319076554151
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -89,6 +91,7 @@ Transform:
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!212 &1395181864555928322
|
||||
SpriteRenderer:
|
||||
serializedVersion: 2
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
@@ -131,9 +134,10 @@ SpriteRenderer:
|
||||
m_AutoUVMaxAngle: 89
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_GlobalIlluminationMeshLod: 0
|
||||
m_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingLayerID: -1132846201
|
||||
m_SortingLayer: 1
|
||||
m_SortingOrder: 0
|
||||
m_MaskInteraction: 0
|
||||
m_Sprite: {fileID: -7843813406500067289, guid: bd1c641e7bfe53145820bb64b08f8fc8, type: 3}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_FlipX: 0
|
||||
@@ -143,7 +147,97 @@ SpriteRenderer:
|
||||
m_AdaptiveModeThreshold: 0.5
|
||||
m_SpriteTileMode: 0
|
||||
m_WasSpriteAssigned: 1
|
||||
m_SpriteSortPoint: 0
|
||||
--- !u!1 &8172954141467387620
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 5850617675450214222}
|
||||
- component: {fileID: 7267684468009174768}
|
||||
m_Layer: 0
|
||||
m_Name: Hovered_indicator
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &5850617675450214222
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8172954141467387620}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 1
|
||||
m_Children: []
|
||||
m_Father: {fileID: 5117288307080929430}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!212 &7267684468009174768
|
||||
SpriteRenderer:
|
||||
serializedVersion: 2
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8172954141467387620}
|
||||
m_Enabled: 1
|
||||
m_CastShadows: 0
|
||||
m_ReceiveShadows: 0
|
||||
m_DynamicOccludee: 1
|
||||
m_StaticShadowCaster: 0
|
||||
m_MotionVectors: 1
|
||||
m_LightProbeUsage: 1
|
||||
m_ReflectionProbeUsage: 1
|
||||
m_RayTracingMode: 0
|
||||
m_RayTraceProcedural: 0
|
||||
m_RayTracingAccelStructBuildFlagsOverride: 0
|
||||
m_RayTracingAccelStructBuildFlags: 1
|
||||
m_SmallMeshCulling: 1
|
||||
m_ForceMeshLod: -1
|
||||
m_MeshLodSelectionBias: 0
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 2100000, guid: 9dfc825aed78fcd4ba02077103263b40, type: 2}
|
||||
m_StaticBatchInfo:
|
||||
firstSubMesh: 0
|
||||
subMeshCount: 0
|
||||
m_StaticBatchRoot: {fileID: 0}
|
||||
m_ProbeAnchor: {fileID: 0}
|
||||
m_LightProbeVolumeOverride: {fileID: 0}
|
||||
m_ScaleInLightmap: 1
|
||||
m_ReceiveGI: 1
|
||||
m_PreserveUVs: 0
|
||||
m_IgnoreNormalsForChartDetection: 0
|
||||
m_ImportantGI: 0
|
||||
m_StitchLightmapSeams: 1
|
||||
m_SelectedEditorRenderState: 0
|
||||
m_MinimumChartSize: 4
|
||||
m_AutoUVMaxDistance: 0.5
|
||||
m_AutoUVMaxAngle: 89
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_GlobalIlluminationMeshLod: 0
|
||||
m_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingOrder: 0
|
||||
m_MaskInteraction: 0
|
||||
m_Sprite: {fileID: -8836962644236845764, guid: c5cc7367a37a7944abb3876352b0e0ff, type: 3}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_FlipX: 0
|
||||
m_FlipY: 0
|
||||
m_DrawMode: 0
|
||||
m_Size: {x: 9.61, y: 9.26}
|
||||
m_AdaptiveModeThreshold: 0.5
|
||||
m_SpriteTileMode: 0
|
||||
m_WasSpriteAssigned: 1
|
||||
m_SpriteSortPoint: 0
|
||||
--- !u!1 &8952044779537201808
|
||||
GameObject:
|
||||
|
||||
@@ -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