Skip to content

Commit dd3c4d0

Browse files
author
Jon Gill
committed
Fix README documentation to actually be about Autofill
1 parent 1516484 commit dd3c4d0

File tree

5 files changed

+39
-140
lines changed

5 files changed

+39
-140
lines changed

Packages/com.jonagill.autofill/Editor/AutofillEditorUpdater.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ private static void UpdateCurrentSelection()
355355
target = gameObject;
356356
}
357357

358-
Debug.LogFormat(target, "Updating autofilled properties for {0}", target);
359358
UpdateAndSavePrefab(target);
359+
Debug.LogFormat(target, "Updated autofilled properties for {0}", target);
360360
}
361361
}
362362
}

README.md

Lines changed: 38 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -1,157 +1,56 @@
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!
33

4-
![Cards from a prototype generated with Deckard](img/NockCards.png)
4+
Autofill turns messy Inspectors like this:
55

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+
![A Unity component inspector containing nine serialized component references](img/SerializedFields.png)
77

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:
99

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+
![A Unity component inspector with no serialized properties](img/AutofilledFields.png)
1411

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.
1714

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.
2817

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:
3119

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+
![A Unity component inspector displaying a warning that no valid Rigidbody component could be found by the Autofill system](img/AutofillError.png)
3421

35-
The top row of your spreadsheet will be treated as headers and define the name of each column.
3622

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.
3825

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.
4027

41-
![Sample data from an example CSV file](img/CsvData.png)
28+
### Additional parameters
29+
Both `[Autofill]` and `[AutofillOptional]` take a number of constructor parameters:
4230

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:
4533

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).
4747

48-
You can create a DeckAsset via the right-click `Create > Deckard > New Deck` context menu item.
4948

50-
![A screenshot of the Unity inspector for a DeckAsset object](img/DeckAsset.png)
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).
5151

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.
5454

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-
![A screenshot of the Unity inspector for a DeckardCanvas component](img/DeckardCanvas.png)
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-
![A screenshot of the Unity inspector for a SpriteCollection object](img/SpriteCollection.png)
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-
![A screenshot of the Unity inspector for a ColorCollection object](img/ColorCollection.png)
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-
![A screenshot of the column name selector on a CSV data component](img/CsvBehaviour.png)
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-
![A screenshot of the Unity inspector for a CsvSprite component](img/CsvSprite.png)
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-
![A screenshot of the Unity inspector for a CsvText component](img/CsvText.png)
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-
![A screenshot of the Unity inspector for a CsvColor component](img/CsvColor.png)
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-
![A screenshot of the Unity inspector for a CsvCount component](img/CsvCount.png)
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-
![A screenshot of the Unity inspector for a CsvVisibility component](img/CsvVisibility.png)
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-
![A screenshot of the Unity inspector for a EnableForBleed component](img/EnableForBleeds.png)
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-
![A screenshot of the Unity inspector for a EnableForExportType component](img/EnableForExportType.png)
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.

img/AutofillError.png

9.6 KB
Loading

img/AutofilledFields.png

4.3 KB
Loading

img/SerializedFields.png

28.6 KB
Loading

0 commit comments

Comments
 (0)