CardEase is a 2D Unity asset that provides simple drag-and-drop functionality with a high level of customization. It allows users to implement basic drag-and-drop features for cards, organize cards into groups, adjust spacing between cards, and customize prefabs to there likings. CardEase removes the complexity of creating drag-and-drop systems from scratch while giving you total control over each game object.
- you can try the demo of asset on itch here
- Download the CardEase package from the Unity Asset Store.
- Open your Unity project.
- Import the CardEase package into your project(it will be imported in
Maziminds/CardEasefolder).
- if you found any bug/issue in package or wants to request any update then please open an issue from here
- if you like this project and wants to support it by donation then you can do it from here
-
The package mainly has 2 folders:
Demoandsrc. The folder contains some demo scenes and prefabs that you can use to test the functionality and get familiar with the package, you can change anything in that folder to test the functionalities. this folder has 3 foldersV1,V2andV3in it,V1folder shows a basic demo of package with default settings andV2folder shows a bit customized demo with some customizations examples andV3shows the latest update with Event system. -
The
srcfolder contains the source code for the package, it contains all core scripts for drag-drop and other features. if you want to change anything in that folder, you can do that(only if you know what you are doing). -
This package works with RectTransform and Horizontal Layout Group to show an organized deck of cards that you drag around in the scene. The package simply provides you with some abstract classes(scripts) that you can extends and customize. by default it gives basic drag-drop functionality with events on different actions like card pick/drop or select/deselect and you can add your own customization by extending it.
-
The package mainly contains 3 things:
CardZone: this represent the place or area where cards can be placed. it's mostly a rectangularGameObject.CardGroup: this is a child ofCardZone, that has a group of cards in it. 1CardZonecan have multipleCardGroupbut 1CardGroupcan only be a child of 1CardZone.Card: This is a child ofCardGroup, this represents a single card that can be dragged around in between differentCardGroupandCardZone.
-
once you are familiar with the package, you can delete the
Demofolder and start using the package in your game.
- You will mainly need 3 prefabs, one for each
CardZone, one for eachCardGroup, and one for eachCard. there will be 1 more Prefab calledCardPlaceholderthat will be used as a placeholder for cards when they are being dragged.CardZone: this prefab needs to have RectTransform and Horizontal Layout Group attached to it. plus 1Imageelement to show the Card Zone in game.- this prefab will also need a CardZoneManager script attached to it(you have to first extend it on another class).
- it's important to note that you can't add any child to this element, since it has a
HorizontalLayoutGroupattached to it, only child it should have isCardGroup. - You can checkout
Demofolder for more detailed info.
CardGroup: this prefab also needs to have RectTransform and Horizontal Layout Group attached to it. plus 1Imageelement to show the Card Group in game.- This prefab will also need a CardGroupManager script attached to it(you have to first extend it on another class).
- it's important to note that you can't add any child to this element, since it has a
HorizontalLayoutGroupattached to it, only child it should have isCard. - You can checkout
Demofolder for more detailed info.
Card: this prefab also needs to have RectTransform and Layout Element, Canvas Group attached to it. plus 1Imageelement to show the Card in game.- This prefab will also need a CardManager script attached to it(you have to first extend it on another class).
- this is the last child so you can add any child on this
GameObject. you can customize it as you want. - You can checkout
Demofolder for more detailed info.
CardZoneandCardGroupboth's scripts have aMin SpacingandMax Spacingproperties that you can use to adjust the spacing between cards and cardGroups.- this values will be used by the CardZoneManager and CardGroupManager scripts in functions
RefreshCardZone,RefreshCardGroupto adjust the spacing between cards and cardGroups.
- By default the card select feature is not enabled, but you can do that by first adding some
Buttonorclick listenerto theCardprefab. that can call theUpdateSelectionmethod in the CardManager script. from there you can decide how card should look while it's selected. - you can also use
GroupSelectedCardsmethod from CardZoneManager to create a new group of selected cards.
- This CardModel is an Abstract class that you can extend with your own custom script. this class serves as a
DataContainerthat you can use to store any custom values you want to be applied to the card. for example you can have propertynameorvalue,pointsthat shows how many points or value does any card have. - Once Extended, you can use this class in other classes like CardManager, CardZoneManager and CardGroupManager.
- This CardZoneManager is an Abstract class that you can extend with your own custom script. that extended script should be attached to a
CardZoneprefab. this Abstract class implements classes likeMonoBehaviour,IPointerEnterHandlerto handle some drag-drop functions. - while extending, pass the CardModel's extended class. something like
V1CardZoneManager: CardEase.CardZoneManager<V1CardModel>. here theV1CardModelis the extended class for CardModel andV1CardZoneManageris the extended class for CardZoneManager. - Once Extended, make sure you
overridetheAwakeand called thebase.Awake()before adding your own custom logic. also update the values likecardGroupPrefabandminSpacing,maxSpacingaccording to your needs. there are some methods in this class that you can use.AddGroup: This method creates a new empty group in the card zone. If a list of cards is provided, those cards will be added to the new group as wellGetAllCards: This method will get the list of all cards in thatCardZone. no matter how manyCardGroupare in that zone, it will take of the cards in them.GroupSelectedCards: This method will make a new group of selected cards and return the group. make sure that yourCardprefab has someclick listenerattached to it.RefreshCardZone: This method can arrange the elements(cardGroups) in it so it will cover the screen area properly
- This CardGroupManager is an Abstract class that you can extend with your own custom script. that extended script should be attached to a
CardGroupprefab. this Abstract class implements classes likeMonoBehaviour,IPointerEnterHandlerto handle some drag-drop functions. - while extending, pass the CardModel's extended class.
- Once Extended, make sure you
overridetheAwakeand called thebase.Awake()before adding your own custom logic. also update the values likecardPrefabandminSpacing,maxSpacingaccording to your needs. there are some methods in this class that you can use.AddCard: This method creates a new card in thatCardGroup. it takes a class that extend CardModel model that contains any custom values you want to be applied to the card.RefreshCardGroup: This method can arrange the elements(cards) in it so it will cover the screen area properly\
- This CardManager is also an Abstract class that you can extend with your own custom script. that extended script should be attached to a
Cardprefab. this Abstract class implements classes likeMonoBehaviour,IBeginDragHandler,IDragHandler,IEndDragHandlerto handle some drag-drop functions. - while extending, pass the CardModel's extended class.
- Once Extended, you need to override 2 methods
SetDataandUpdateSelection. you can add any other custom element to theCardprefab to suites your requirements.SetData: This method will set the data of the card. it takes a class that extend CardModel model that contains any custom values you want to be applied to the card. then you can use this values to render your card. you can see it's example in V2CardManagerUpdateSelection: This method will update the card selection. it takes a Boolean value that indicates if the card is selected or not. while overriding this method, make sure you updateisSelectedproperty bythis.isSelected = isSelected;then you can add any other custom code that change card's look while it's selected. you can see it's example in V2CardManager
- This EventManager is a Generic type class that contains a list of events that can be invoked and listened by any script/class in whole game.
- this events are supposed to be used to make the UI/GAME interact while the player is performing some action on cards. for example, if you want to do some action whenever the player pick/drop a card and you can listen to it's event. similarly there is an event for card select/deselect as well.
- by default it wont fire any events but you can decide which event to fire/invoke and which event to listen, for example:
SELECT/DESELECT events: take a look at V3CardManager, inUpdateSelectionmethod we are invoking events likeCARD_SELECTEDandCARD_DESELECTEDwhenever the card is selected/deselected.- this events are the listened by V3Controller with
AddListenermethod and then we can perform some tasks on UI like showing the list of all selected cards in the UI.
- this events are the listened by V3Controller with
PICK/DROP events: in V3CardManager, we override 2 more methodsCardPickedandCardDroppedthat's called when any card is picked/dropped and then we invoked events likeCARD_PICKEDandCARD_DROPPEDfrom there.- this events also listened by V3Controller with
AddListenermethod and then we can perform some tasks on UI like highlighting the group of card by it's color or any other logic you want to perform.
- this events also listened by V3Controller with