Drag and Drop (Inventory Example)
Last updated
Last updated
Support us as a GitHub Sponsor and get instant access to all our assets, exclusive tools and assets, escalated support and issue tracking and our gratitude. These articles are made possible by our GitHub Sponsors ... become a sponsor today!
This scene gives a more practice example of code free drag and drop and shows how to use tags and rules to control what can be draged to where. In this scene each drag item is idetified with a color and a number, each slot has either or both a number and a color.
Colorless slots can take any color
Numberless slots can take any number
Red slots can only take red blocks
Numbered slots can only take blocks of the same number
Using color and number is simply done to keep it simple and abstract you can greate any number and complex of tags you like (Weapon, Armour, Left Glove, Basic Attack, etc.) and use that to control drop behaviour.
Setting up code free drag and drop
Setting up drop containers
Setting up drag items
Using Scriptable Tags to defaine item types and cotrol drop rules
Settting up drop rules on drop containers
How to access the Knowledge Base (where you are now)
How to access the support Discord
How to leave a review ๐
The "Types" and "Filter Types" fields of Drag Item and Drop Container respectivly take Scriptable Objects. That is we use Scriptable Objects as unique identifiers to power our filtering system. This is better than simple strings in that comparing two Scriptable Objects is faster and less error prone than comparing two strings. We use the same system in the Heathen Behaviour to tag behaviours.
You can use any Scriptable Object you would like to represent a type. We have create a simple empty Scriptable Object called a Scriptable Tag which we use in this scene. Scriptable Tag has no long and not data it simply represents a unique referencable identifier.
You will find 4 items configured under the Canvas > Background > Inventory Game object. Each item has two "types" assigned. A type is simply a scriptable object and is used like a tag by the drop rules e.g. does the item have this tag, does that allow it or forbid it.
In the middle of the screen you will see 8 slots/containers located under the Canvas > Background > Simple Slots and Canvas > Background > Complex Slots Game objects respetivly, each slot is configured with "Filter Types" and "Mask Mode" which effects what items can and cannot be droped on it.