7.7 KiB
7.7 KiB
Card Prefab Setup Guide
Quick Reference: Building the New Card Prefab
This guide shows you how to create a Card prefab compatible with the new state-based system.
Prerequisites
Before starting, make sure you have:
- All Card state scripts compiled without errors
- CardDisplay.cs working
- Card.cs, CardContext.cs, CardAnimator.cs ready
- PixelPlacement StateMachine (AppleMachine) available
Step 1: Create the Root GameObject
- Create empty GameObject named "Card"
- Add component:
Card.cs(fromUI.CardSystem.StateMachine) - Add component:
RectTransform(if not already present) - Add component:
CanvasGroup(optional, for fade effects) - Add component:
AspectRatioFitter(optional, to maintain card proportions)
Card.cs Settings:
- Initial State:
IdleState
Step 2: Add CardContext Component
- On the same "Card" GameObject, add:
CardContext.cs - This component holds:
- Card data reference
- IsNew flag
- IsClickable flag
- RootTransform reference (auto-assigned)
CardContext.cs Settings:
- Root Transform: (leave empty, auto-assigned in Awake)
Step 3: Add CardAnimator Component
- On the same "Card" GameObject, add:
CardAnimator.cs - This component will handle all animations
CardAnimator.cs Settings:
- Card Display: (assign in Step 4)
- Visual Root: (assign the Card GameObject itself)
Step 4: Create CardDisplay Child
- Create child GameObject under "Card" named "CardDisplay"
- Add component:
CardDisplay.cs - Add UI elements as children:
- CardImage (Image) - main card artwork
- FrameImage (Image) - rarity frame
- OverlayImage (Image) - rarity overlay effects
- BackgroundImage (Image) - zone background
- ZoneShapeImage (Image) - zone symbol/shape
- CardNameText (TextMeshProUGUI) - card name
CardDisplay.cs Settings:
- Assign all the UI element references above
- Visual Config: Assign your CardVisualConfig ScriptableObject
Layout Tips:
- Use anchors to stretch images to fill the card
- Layer order (back to front): Background → Zone Shape → Card Image → Frame → Overlay
- Make sure all images have "Raycast Target" enabled for click detection
Step 5: Create CardBack Child (for flip animation)
- Create child GameObject under "Card" named "CardBack"
- Add component:
Image - Assign your card back sprite
- Position/scale to match CardDisplay size
Settings:
- Make sure it's initially hidden (will be shown by FlippingState)
Step 6: Create StateMachine Child
- Create child GameObject under "Card" named "StateMachine"
- Add component:
AppleMachine(from Pixelplacement)
AppleMachine Settings:
- Starting State:
IdleState - Debug: Enable if you want state transition logging
Step 7: Create State Children
Under "StateMachine", create these child GameObjects:
7a. IdleState
- GameObject name: "IdleState"
- Add component:
CardIdleState.cs - Settings:
- Hover Lift Distance:
20 - Hover Duration:
0.3
- Hover Lift Distance:
7b. FlippingState
- GameObject name: "FlippingState"
- Add component:
CardFlippingState.cs - Settings:
- Flip Duration:
0.6 - Next State After Flip:
RevealedState
- Flip Duration:
7c. RevealedState
- GameObject name: "RevealedState"
- Add component:
CardRevealedState.cs - Settings:
- Scale:
1.5(for NEW card emphasis) - Scale Duration:
0.5
- Scale:
7d. DraggingState
- GameObject name: "DraggingState"
- Add component:
CardDraggingState.cs - Settings:
- Drag Scale:
1.2 - Drag Rotation:
5degrees
- Drag Scale:
7e. PlacedInSlotState
- GameObject name: "PlacedInSlotState"
- Add component:
CardPlacedInSlotState.cs - Settings:
- (Auto-configured when placed)
7f. AlbumEnlargedState
- GameObject name: "AlbumEnlargedState"
- Add component:
CardAlbumEnlargedState.cs - Settings:
- Enlarged Scale:
2.5 - Scale Duration:
0.3
- Enlarged Scale:
Step 8: Wire Up References
Go back to the root "Card" GameObject:
Card.cs:
- Context: Drag the Card GameObject (auto-finds CardContext)
- Animator: Drag the Card GameObject (auto-finds CardAnimator)
- State Machine: Drag the "StateMachine" child
CardAnimator.cs:
- Card Display: Drag the "CardDisplay" child
- Visual Root: Drag the "Card" GameObject itself
CardContext.cs:
- (Everything auto-assigned, nothing to wire)
Step 9: Save as Prefab
- Drag the "Card" GameObject into your Prefabs folder
- Name it:
Card.prefab(or whatever you prefer) - Delete the instance from the scene
Step 10: Update Scene References
BoosterOpeningPage
- Find
BoosterOpeningPagein your scene - Assign
cardPrefabfield → your new Card prefab
AlbumViewPage
- Find
AlbumViewPagein your scene - Assign
cardPrefabfield → your new Card prefab
AlbumCardSlot Prefab
- Open your AlbumCardSlot prefab
- Assign
cardPrefabfield → your new Card prefab
Testing Your Prefab
Test 1: Booster Opening
- Play the game
- Open a booster pack
- Cards should spawn face-down
- Click a card → it flips and reveals
- If NEW → shows enlarged with "NEW" indicator
- If REPEAT → shows progress bar
- Click to dismiss → flies to album icon
Test 2: Album Placement
- After opening boosters, cards appear in bottom-right
- Drag a card → it scales up and rotates slightly
- Drop on valid slot → it snaps in and stays
- Drop outside → returns to original position
Test 3: Album Viewing
- Go to album view
- Cards in slots should display normally
- Click a placed card → enlarges with backdrop
- Click again (or backdrop) → shrinks back to slot
Common Issues & Fixes
Cards don't flip
- Check FlippingState is assigned in StateMachine
- Verify CardBack GameObject exists and has sprite
- Check CardAnimator has CardDisplay reference
Cards don't respond to clicks
- Make sure CardDisplay images have "Raycast Target" enabled
- Check EventSystem exists in scene
- Verify Card has CanvasGroup or Image for raycast blocking
Animations don't play
- Check CardAnimator reference is assigned
- Verify Tween library (Pixelplacement) is imported
- Check state components have correct duration values
Cards stuck in one state
- Enable StateMachine debug mode to see transitions
- Check state scripts don't have infinite loops
- Verify transition logic in state Enter/Exit methods
Advanced: Customizing States
Want to add your own card behavior? Here's how:
- Create new script inheriting from
AppleState - Override
Enter(),Exit(),UpdateState()as needed - Use
Cardreference to access context, animator, etc. - Add GameObject under StateMachine with your new component
- Transition to it via
Card.ChangeState("YourStateName")
Example:
public class CardBurningState : AppleState
{
private Card _card;
public override void Enter(params object[] args)
{
_card = GetComponentInParent<Card>();
// Play burning animation
_card.Animator.PlayBurnEffect();
}
public override void Exit()
{
// Clean up
}
}
Final Checklist
Before considering your prefab complete:
- Root Card GameObject has Card, CardContext, CardAnimator components
- CardDisplay child is set up with all UI elements
- CardBack child exists for flip animation
- StateMachine child has AppleMachine component
- All 6 state children are created and configured
- All references wired up on Card component
- Prefab saved and assigned in scene controllers
- Tested in both booster and album flows
- No console errors when playing
Need Help?
Refer to:
card_system_migration_summary.md- What changed and whycard_architecture_plan.md- Architecture overview- State script files - Implementation details
Happy card building! 🎴