|
1 | | -# Deckard |
2 | | -Deckard is a Unity-based layout tool for card game prototyping, built for game designers who are already familiar with Unity's built-in Canvas components. |
| 1 | +# Autofill |
| 2 | +Autofill is a simple Unity extension that can automatically assign serialized component references for you. If a reference is successfully autofilled, it will be hidden in the Inspector, allowing you to safely ignore it like the implementation detail it is. This provides all the ease of use of calling `GetComponent` with none of the runtime costs! |
3 | 3 |
|
4 | | - |
| 4 | +Autofill turns messy Inspectors like this: |
5 | 5 |
|
6 | | -There are lots of great existing tools for generating card assets, including [nanDECK](https://www.nandeck.com/), [Component Studio](https://component.studio/), [Squib](https://github.com/andymeneely/squib), [Cocktail](https://cocktail.software/download/), [CardMaker](https://github.com/nhmkdev/cardmaker), and [InDesign data merge](https://helpx.adobe.com/indesign/using/data-merge.html), but if you are most comfortable building out layouts in Unity, you might want to give Deckard a try! |
| 6 | + |
7 | 7 |
|
8 | | -Deckard is designed to be used as an editor tool only, and is not optimized or designed for use in builds or runtime gameplay. |
| 8 | +into this: |
9 | 9 |
|
10 | | -## Features |
11 | | -* Combine card data from CSVs with Unity UI prefabs to generate decks of cards |
12 | | -* Customize text, images, colors, and more while using intuitive human-readable names in your spreadsheets |
13 | | -* Export cards as individual files, print-and-play sheets, and sprite atlases for digital prototyping platforms (Screentop.gg, Tabletop Playground, etc.) |
| 10 | + |
14 | 11 |
|
15 | | -## Installation |
16 | | -We recommend you install Deckard via [OpenUPM](https://openupm.com/packages/com.jonagill.deckard/). Per OpenUPM's documentation: |
| 12 | +## Using Autofill |
| 13 | +To enable Autofill for a serialized field on a given component, you must mark it up with the `[Autofill]` or `[AutofillOptional]` attributes. |
17 | 14 |
|
18 | | -1. Open `Edit/Project Settings/Package Manager` |
19 | | -2. Add a new Scoped Registry (or edit the existing OpenUPM entry) to read: |
20 | | - * Name: `package.openupm.com` |
21 | | - * URL: `https://package.openupm.com` |
22 | | - * Scope(s): `com.jonagill.deckard` |
23 | | -3. Click Save (or Apply) |
24 | | -4. Open Window/Package Manager |
25 | | -5. Click the + button |
26 | | -6. Select Add package by name... |
27 | | -6. Click Add |
| 15 | +### [Autofill] |
| 16 | +A serialized component field marked with `[Autofill]` will be automatically filled whenever the component is viewed in the Inspector or a prefab containing the component gets saved. If the component is found, we hide the field in the Inspector to avoid cluttering the component with useless property drawers. |
28 | 17 |
|
29 | | -## Core assets |
30 | | -To generate a deck, you will want to create the following assets: |
| 18 | +If the component is not found, we display an error into the Inspector like so: |
31 | 19 |
|
32 | | -#### CSV data |
33 | | -A CSV file generated from a spreadsheet will provide the raw data for customizing all the cards of your deck. This CSV can be exported from any existing spreadsheet in a tool like Google Sheets or Excel. |
| 20 | + |
34 | 21 |
|
35 | | -The top row of your spreadsheet will be treated as headers and define the name of each column. |
36 | 22 |
|
37 | | -Every other row of your spreadsheet will define a single card in your deck, defining details like its text, images, colors, resource counts, and so on. Feel free to use whatever names you want for images and colors -- you'll give these names meaning later in Unity. |
| 23 | +### [AutofillOptional] |
| 24 | +A serialized component field marked with `[AutofillOptional]` will be automatically filled whenever the component is viewed in the Inspector or a prefab containing the component gets saved. If the component is found, we hide the field in the Inspector to avoid cluttering the component with useless property drawers. |
38 | 25 |
|
39 | | -If you want to include multiple copies of each card in your deck, you can create a column titled Count to define the number of copies of each card in your deck. |
| 26 | +Unlike `[Autofill]`, we do not display an error if no component could be found, as this component is understood to be optional. Any references to that component should be wrapped in nullity checks within your component logic. |
40 | 27 |
|
41 | | - |
| 28 | +### Additional parameters |
| 29 | +Both `[Autofill]` and `[AutofillOptional]` take a number of constructor parameters: |
42 | 30 |
|
43 | | -#### DeckAsset |
44 | | -DeckAssets are ScriptableObject assets that define a deck of cards. They link together a CSV file and a corresponding DeckardCanvas prefab, and their inspector provides access to Deckard's various export options. |
| 31 | +#### type |
| 32 | +The `type` parameter specifies where the Autofill system will search to try and find a valid target component to assign to the autofilled reference. There five possible options: |
45 | 33 |
|
46 | | -Hover over each property in the inspector to learn more about what it does. |
| 34 | +* Self *(default)* |
| 35 | + * Autofill will only check the GameObject containing the declaring component for the target component. |
| 36 | + * This is equivalent to a `GetComponent` call. |
| 37 | +* Parent |
| 38 | + * Autofill will check all the parents of the GameObject containing the declaring component for the target component. |
| 39 | +* SelfAndParent |
| 40 | + * Autofill will check both the GameObject containing the declaring component and all of its parents for the target component. |
| 41 | + * This is equivalent to a `GetComponentInParent` call (since that call also checks the invoking object for the desired component). |
| 42 | +* Children |
| 43 | + * Autofill will check all descendants of the GameObject containing the declaring component for the target component. |
| 44 | +* SelfAndChildren |
| 45 | + * Autofill will check both the GameObject containing the declaring component and all of its descendants for the target component. |
| 46 | + * This is equivalent to a `GetComponentInChildren` call (since that call also checks the invoking object for the desired component). |
47 | 47 |
|
48 | | -You can create a DeckAsset via the right-click `Create > Deckard > New Deck` context menu item. |
49 | 48 |
|
50 | | - |
| 49 | +#### acceptFirstValidResult |
| 50 | +The Autofill system usually displays an error if it finds multiple valid target components when trying to fill a reference. If this parameter is set to true, the Autofill system will accept the first result is finds (usually the closest component to the declaring component in the hierarchy). |
51 | 51 |
|
52 | | -#### DeckardCanvas prefab |
53 | | -DeckardCanvases are components that go on a Unity prefab to define a card's layout. You can then use Unity's regular set of RectTransform and layout options to design your card's layout. |
| 52 | +#### alwaysShowInInspector |
| 53 | +The Autofill will usually hide autofilled references that have been successfully filled in the Inspector. If this parameter is set to true, the Autofill system will draw a disabled version of this field instead of hiding it entirely. |
54 | 54 |
|
55 | | -To create a new DeckardCanvas, create a new GameObject, add the DeckardCanvas component to it, and then save it as a prefab. |
56 | | - |
57 | | - |
58 | | - |
59 | | -#### SpriteCollection |
60 | | -SpriteCollections are ScriptableObject assets that define a set of sprites. Each sprite is assigned a human-readable key so that you can easily reference it from your spreadsheets. |
61 | | - |
62 | | -The "Bulk Import from Folder" option allows you to rapidly add all of the sprites in a folder into the SpriteCollection, using their filenames as the default keys. |
63 | | - |
64 | | -You can create a SpriteCollection via the right-click `Create > Deckard > New SpriteCollection` context menu item. |
65 | | - |
66 | | - |
67 | | - |
68 | | -#### ColorCollection |
69 | | -SpriteCollections are ScriptableObject assets that define a set of colors. Each color is assigned a human-readable key so that you can easily reference it from your spreadsheets. |
70 | | - |
71 | | -You can create a ColorCollection via the right-click `Create > Deckard > New ColorCollection` context menu item. |
72 | | - |
73 | | - |
74 | | - |
75 | | -## Decorator components |
76 | | -Deckard provides a suite of components that can be placed on your card prefabs to customize each card during the export process. |
77 | | - |
78 | | -### CSV data components |
79 | | -These components read in fields from your spreadsheet CSV and modify the cards using that data. |
80 | | - |
81 | | - |
82 | | - |
83 | | -For every CSV data component, you will have to specify the name of the column that this component will reference when running its logic. A search field and drop-down box are provided to help you find the valid names of the columns in all of your decks. |
84 | | - |
85 | | -#### CsvSprite |
86 | | -This component will assign a sprite to an Image component on the same GameObject based on the contents of a CSV field. You must assign a reference to the SpriteCollection that you want to use for this object. |
87 | | - |
88 | | -If no sprite can be found in the SpriteCollection matching the name in the CSV field, the Image will be disabled and hidden in any exports. This means that the Image will be hidden appropriately for empty fields in your CSV. |
89 | | - |
90 | | - |
91 | | - |
92 | | -#### CsvText |
93 | | -This component copies the contents of a CSV field into a TextMeshProUGUI text component on the same GameObject. |
94 | | - |
95 | | -If your TextMeshProUGUI component has rich text enabled, you can use [rich text tags](http://digitalnativestudios.com/textmeshpro/docs/rich-text/) to stylize your text. |
96 | | - |
97 | | -By assigning a reference to a SpriteCollection asset, you can embed icon sprites within your text by surrounding the name of a sprite in that collection with double carats, such as: `<<spritename>>`. By default, embedded sprites will be tinted to match the color of the surrounding text. To render an icon without colorization, add an exclamation point to the start of it's name like so: `<<!spritename>>`. |
98 | | - |
99 | | - |
100 | | - |
101 | | -#### CsvColor |
102 | | -This component colorizes Graphic components (TextMeshProUGUI, Image, etc.) on the same object based on the contents of a CSV field. You must assign a reference to the ColorCollection that you want to use for this object. |
103 | | - |
104 | | - |
105 | | - |
106 | | -#### CsvCount |
107 | | -This component will duplicate the GameObject that it's on to match the number of instances specified in a CSV field. This is useful for things like mana costs or health values where you want a variable number of icons based on a certain value on the card. |
108 | | - |
109 | | -You will generally want to make sure that any GameObjects containing a CsvCount component are children of a HorizontalLayoutGroup, VerticalLayoutGroup, or GridLayoutGroup so that they can be dynamically positioned correctly based on the number of instances generated. |
110 | | - |
111 | | - |
112 | | - |
113 | | -#### CsvVisibility |
114 | | -This component will enable and disable a GameObject (and all of its children) by comparing a value in a CSV field with the conditions and values specified on the component. |
115 | | - |
116 | | -If multiple conditions are specified, you can choose whether a single condition being true will make the GameObject visible, or require that all conditions be true before the GameObject is made visible. |
117 | | - |
118 | | - |
119 | | - |
120 | | -### Export type components |
121 | | -These components will alter their behavior based on the export settings you are using. |
122 | | - |
123 | | -#### EnableForBleed |
124 | | -This component will enable or disable the targeted components based on whether the current export contains the bleed region of the cards or not. |
125 | | - |
126 | | -Bleeds are always included for printable sheet exports, never included for sprite atlas exports, and can optionally be included when exporting individual card images. |
127 | | - |
128 | | -Note that unlike CsvVisibility, this component will enable and disable specific components, rather than entire GameObjects. This means you can use it to target specific components to disable without altering the overall layout of your card. |
129 | | - |
130 | | - |
131 | | - |
132 | | -#### EnableForExportType |
133 | | -This component will enable or disable the targeted components based on whether you are exporting individual card images or whole sheets of cards (printable sheets or sprite atlases). |
134 | | - |
135 | | -This is mainly useful for enabling and disabling background elements that you want opaque when exporting sheets, but transparent when exporting individual cards (such as the exterior region of circular tokens). |
136 | | - |
137 | | -Note that unlike CsvVisibility, this component will enable and disable specific components, rather than entire GameObjects. This means you can use it to target specific components to disable without altering the overall layout of your card. |
138 | | - |
139 | | - |
140 | | - |
141 | | -## Bonus content |
142 | | -#### TextureImporter.preset |
143 | | -A Unity preset that specifies some desirable default values for importing textures as Deckard-ready Sprites. |
144 | | - |
145 | | -## Tips & tricks |
146 | | -#### Import icons as 100% white |
147 | | -Unless you have full color art for your icons, you should export your icons from your art program as completely white (apart from any transparency). This will allow you to dynamically tint your icons however you want using Unity's Image component and Deckard's CsvColor component. |
148 | | - |
149 | | -#### Use Unity's Vector Graphics package to import SVGs |
150 | | -Vector graphics can be a great way to author icons, as they maintain their quality at any resolution. They can also be easily downloaded from website like [The Noun Project](https://thenounproject.com/) and [GameIcons.net](https://game-icons.net/). Unity does not support importing SVGs by default, but there is a first-party package that allows you to import SVGs and automatically convert them into Image-compatible sprites. |
151 | | - |
152 | | -Unfortunately, this package is marked as experimental and is hidden in Unity's Package Manager by default. On pre-2020 versions of Unity, you could just tick a box to get Experimental packages to show up in the Package Manager. Starting with Unity 2020, [Unity has started hiding experimental packages entirely](https://forum.unity.com/threads/visibility-changes-for-preview-packages-in-2020-1.910880/) unless you know the exact package name to import. |
153 | | - |
154 | | -To install the Unity Vector Graphics package, open the Package Manager (`Window > Package Manager`), hit the plus icon, and select "Add package by name". Paste in `com.unity.vectorgraphics` into the window that pops up, hit Add, and Unity should download the latest version of the package to include in your project. |
155 | | - |
156 | | -#### Ignore EndLayoutGroup errors |
157 | | -There seems to be a bug in how Unity's layout scopes work for editor UI, such that every time you export, Unity will print an error saying `EndLayoutGroup: BeginLayoutGroup must be called first.`. This is totally benign and is safe to ignore. |
| 55 | +## Limitations |
| 56 | +* Autofill is not currently supported on serialized arrays or lists. |
0 commit comments