https://github.com/blatke/prefab-thumbnail-generator
Unity scripts for generating thumbnails from selected prefabs.
https://github.com/blatke/prefab-thumbnail-generator
scripts unity
Last synced: 2 months ago
JSON representation
Unity scripts for generating thumbnails from selected prefabs.
- Host: GitHub
- URL: https://github.com/blatke/prefab-thumbnail-generator
- Owner: Blatke
- Created: 2025-06-14T18:51:07.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-14T20:26:45.000Z (about 1 year ago)
- Last Synced: 2025-06-14T20:28:12.827Z (about 1 year ago)
- Topics: scripts, unity
- Language: C#
- Homepage: https://www.blatke.cc
- Size: 16.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Prefab Thumbnail Generator
Unity scripts for generating thumbnails from selected prefabs.
It reads the built-in thumbnails of selected prefabs in generating, and such built-in thumbnails were created as their prefabs were created.

## Requirements
1. **Unity Editor** with the version newer than 2018.1.
2. **Newtonsoft.Json**. It requires Newtonsoft.Json to save the settings, please download it at first at https://github.com/JamesNK/Newtonsoft.Json, if you don't have it in Unity. Drag and drop the **net20** folder from the compression pack into your **Asset** folder in Unity.
## Installation
Download the **Source code.zip** file for the latest version on the [Release](https://github.com/Blatke/Prefab-Thumbnail-Generator/releases) page. Uncompress it and there will be .cs files as below:
1. JsonRead.cs
2. ModifyTextureImportSettings.cs
3. PathHepler.cs
4. PrefabThumbnailGenerator.cs
5. TextureGenerator.cs
6. XmlFileRead.cs
7. FileNaming.cs
Drag and drop ALL the .cs files into your project folder, **Asset/Editor/**. If you don't have this **Editor** folder, you need to create one in the Asset folder.
> [!NOTE]
>
> - Since the Generator is running in Unity Editor, ALL its script files have to be put in **Asset/Editor/** folder, as referred above. Otherwise, the Generator cannot start and leaves lots of alterts in the Console panel.
>
> - If you're updating this tool, please replace ALL the .cs files with the newly downloaded ones. Also, don't forget to RE-OPEN the Generator's window after finishing the updating.
## Use It
Go to Unity Editor, click the top menu: **Window -> Bl@ke -> Prefab Thumbnail Generator**, to show the window.
**Select one or more prefabs** that you want to create thumbnails from in your project window, then click the button of **Generate from Selected Prefabs**. The Generator will process it and save the images at the same path of the prefabs:

If you haven't selected at least one prefab before clicking the button for generating, the Generator will give you a warning below the button:

Some of the options will pop tips if the mouse is hovering the texts:

### Prefix & Suffix in Naming
The thumbnails will be named same as the prefabs. We can choose to give them a prefix and suffix beside the names of thumbnails:

### Include Images and Materials
Sometimes we also want to resize images, or generate the thumbnails from materials. So, check **"Include Images"** or **"Include Materials"**, and the Generator will also generate thumbnails from our selected images or materials:

Without "Include Images" or "Include Materials" being checked, the Generator will not process images or materials.
### Avoid Repeated-Names
If a particular object such as a prefab, image or material is refenerced in thumbnail generating, and the file name the generated thumbnail supposes to use is same to an existing image at the same path, let us say, _"Assets/Folder/thumb_A.png"_, the generated thumbnail will overwrite it.
To avoid this overwriting problem, we can check **"Rename Name-Repeated Thumbs"** to give another name to these sort of newly generated thumbnails according to the way that Unity treats to the imported files with repeated names.

So if a newly generated thumbnail is _"Assets/Folder/thumb_A.png"_ and is repeated to an existing one, the earlier will be renamed to _"Assets/Folder/thumb_A 1.png"_. If the renamed one still meets repeated, it will then be renamed to _"Assets/Folder/thumb_A 2.png"_, and so forth... till it is unique to all the existing images at the same path.
### "Good" and "Failed" Prefabs
Commonly, only "good" prefabs, that got built-in thumbnails when they were created, will generate thumbnails by the Generator, whereas the rests such like Lights, Terrain, Sprite, etc. will not generate anything, and the Generator will give a warning below the button:

Checking **"Designate Texture/Color"** and selecting a particular texture or pure color will let the Generator reference to not the prefabs in generating but the designated texture or pure color. So, each thumbnail will be generated by the designated texture / pure color:

> [!NOTE]
>
> Only when "Texture" is "None" slot, which means no texture designated, "Pure Color" setting is available. Otherwise, the Generator still use the designated texture in generating.
If **"Only for Failed Prefabs"** is checked, the Generator will reference to the "good" prefabs in generating, but for "failed" prefabs, it will reference to the designated texture / pure color:

### Use Watermark
You can adopt a texture as a watermark adding to the thumbnail during the generation.
1. Prepare a texture as the watermark.
> [!NOTE]
>
> The alpha values in the texture indicate the weights of the watermark blending with the thumbnail.
>
> The texture should have the same size as the generated thumbnails. Otherwise, the watermark might be split to fit the thumbnail size, or will not apply, which may cause unexpected visual effect.
Take the following texture as an instance:

2. After importing the watermark texture in Unity, make sure the options of **"Alpha is Transparency"** as well as **"Read/Write Enabled" is checked**. Also, **"Use Crunch Compression" must remain unchecked**.

3. On the Generator tab, check "Use Watermark", and then assign "Watermark Texture" to your prepared watermark.

4. Generate the thumbnail, and you would got this following effect. If the watermark is not correctly arranged, it only generate the thumbnail without a watermark.

### Background Color Replace
The default background color of prefab (and other assets) is #525252, and this leads to the same background color of generated thumbnails, such like:

This option will replace it with a designated one.

The replaced result is:

> [!NOTE]
>
> However, any other parts in the generated thumbnails with the same color will also be replaced, which may cause unexpected visual effect. Please use this option carefully.
>
> This sort of conflict will not affect watermark in the generation.
Also, you can choose a texture as the new background in replacement:

Suppose we assign this texture slot to this following image:

The replaced result could be:

> [!NOTE]
>
> The Import Settings and size of this replace background texture have to be like what it does in [Watermark](https://github.com/Blatke/Prefab-Thumbnail-Generator?tab=readme-ov-file#use-watermark).
>
> If you want to use pure color in background replacing instead of texture, just leave the texture slot blank.
### Save Settings
You can click **"Save Settings"** button at the right-top to persist your adjustments in settings:

# For HS2/AIS Modders using hooh Modding tools
Starting from v1.0.2 of the Generator, it can name the generated thumbnails in the format of HS2/AIS studio item thumbnail by reading the mod.xml file, and save the generated thumbnails in 'thumbs' folder. This will make your modding more convenient.

As the screenshot shown above, if checking the option of **"Name by 'mod.xml' for StuioItem"**, the Generator will automatically check if any mod.xml exists outside the current 'prefabs' folder, and if there is such a file, it will further read the tags in that file. If the selected prefabs can be found their file names in the tags with the Object attributes, the corresponding studio item's names will be got and put with the big- and mid-category's ids. Then the thumbnails will be named in the format of HS2/AIS studio item thumbnail, such like _00000001-00000001-StudioItemName.png_. If there's no such a file or no corresponding tags found, the naming will be the names of the prefabs.
> [!TIP]
>
> 1. The .xml file has to be named like: **mod.xml**, **mod 1.xml** or **mod 2.xml**. Otherwise, the Generator cannot find it.
>
> 2. Tags in **mod.sxml**, **mod 1.sxml** or **mod 2.sxml** that are used in hooh Modding Tools v0.7.0 can be also read. [1.0.5 Updated]
>
> 3. If the Generator find the **first** compatible .xml/.sxml file for a particular prefab, it will read it and stop searching.
When checking "Name by 'mod.xml' for StuioItem", the option of **"Save in 'thumbs' Folder"** is available. If check it, the thumbnails will be saved in the 'thumbs' folder outside the current 'prefabs' folder. If no such this folder found, it will create one and save them it.