DeckStacker v1.0
A card manager plugin for Unity games.
 
Loading...
Searching...
No Matches
Stack Prefab Setup
DeckStacker Stacks

DeckStacker was built with a particular prefab structure in mind. Let’s go through that structure and talk about each piece’s significance.

(I will be referring to the object names in the above diagram)

Stack - An Organizer of Cards

While designing DeckStacker, I went with the concept that cards are not fully independent, but instead are generally organized into groups. Those groups also commonly have a layout and order to them.

This shouldn’t be a shocking idea to anyone that’s played card games:

  • Cards often have an order
  • That order defines relationships between cards
  • There are also a variety of layouts that groups of cards take on
  • A group of cards also contains information, as a group
    • Such as: A discard pile has a particular significance in most card games
    • That discard pile could also treat the cards contained differently depending on placement
      • Example: The top card of a discard can be targeted by a card’s ability, but the rest of the pile is untouched.

To facilitate all of these potential mechanics, DeckStacker cards are organized into “Stacks”.

These Stacks contain, position, and order the cards according to certain values.

(For more information on Stacks: Visit the DeckStacker Concepts page)


Hierarchy Breakdown

Stack Prefab Diagram

DeckStacker Stack

This is the top-parent of the prefab, and contains just about all the scripts that control a Stack.

RectTransform

RectTransform
  • This is a UGUI setup, and DeckStacker heavily leverages the UGUI system.

Canvas

Canvas
  • This is a “sub-canvas” or “nested-canvas” setup for 2 reasons
    • Reduce Canvas dirtying in the UGUI system
      • For more UGUI optimization tips, see (Unity blog)
    • Using a sub-canvas setup, allows for Order In Layer overrides, which is needed on a pretty frequent basis for solving sorting issues when moving cards between Stacks.
      • Tech Note: When DeckStacker initiates a card transfer between 2 Stacks, the card is immediately re-parented to the second Stack.
      • This means that if the second Stack is sorting behind the first stack, the card immediately disappears behind its previous siblings.
      • You will most likely run into this problem very quickly, when using this system.
      • Core DSActions are provided for solving these sorting issues in the action queue: DSChangeStackRenderOrderAction, and DSResetStackRenderOrderAction

Graphic Raycaster

Graphic Raycaster
  • Only useful if you want to put Buttons on Stacks.
  • If so, you’ll need a Graphic Raycaster to go along with the sub-canvas setup.

DSStack

DSStack
  • This serves as a communication hub between the various Stack scripts, and allows other objects a pathway to the various components of a Stack.
  • This script also has some odd-ball methods and info, such as:
    • Selected Card Position Offset
      • When cards are selected in this Stack, what position offset should we trigger in the card, automatically?
    • Selected Card Scale Offset
      • When cards are selected in this Stack, what scale offset should we trigger in the card, automatically?
  • Note the Restack Helper:
    • This is where some key information is defined in the Stack.
      • Stack Type
      • Align To Center
      • Reverse Direction

DSCardManager

DSCardManager
  • This script provides key methods for managing cards in the Stack.
    • Highlights:
      • AddCard
      • RemoveCard
      • ReorderCardInStack
      • UpdateCardRenderOrder
  • Also defines if cards in the Stack are “grabbable” and whether card grabs will allow the player to change the grabbed card’s order in the stack by dragging it around (see StacksDemo for a demonstration).
  • This script also contains the “cards” List, but you can access that list through the DSStack.cards property for easier typing.

DSStackRenderManager

DSStackRenderManager
  • This script hooks up to the Canvas, described earlier, and controls whether the “Fake Pile Image” is visible.
    • The “Fake Pile Image” is there to hide cards below the top card of a Pile, reducing overdraw and potentially reducing draw calls. (This is purely for rendering optimization, especially for mobile)
    • If you want to disable the Fake Pile Image behavior: Check “Render Full Pile”

Stack Backing

This is just an image that is present underneath all the cards of the stack to show that this place has meaning, or to provide an input target if you enable clicks on a Stack.

Stack Fake Pile Image

This Image is hooked up to the DSStackRenderManager, and is only visible when a Stack is a Pile type.

Its purpose is to reduce overdraw and draw calls on a stack by hiding cards that are not designated as the “top card” by the DSStackRenderManager. Hiding those cards creates a gap in the visual, and the Fake Pile Image is there to fill that gap.

This is not always needed, so you can disable this behavior.

Card Stack Parent

This is assigned to the “Card Stack Parent” field in DSCardManager, and is the parent for all cards contained by the Stack.

This object also defines the Stack’s bounding box, which in turn tells Restack code when a Stack is considered “overstuffed”.

Overstuffed Stacks will change the card layout to accommodate more cards, preventing the cards from overflowing their designated bounding box.