Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
## [6.0.0] - 2021-08-10
### Fixed
- Fixed performance regression in PSDImporter Editor (case 1349408)
- Updated manual on Importer override to use latest API.

### Changed
- Changed some of PSDImporter settings to use checkboxes instead of drop down
  • Loading branch information
Unity Technologies committed Aug 10, 2021
1 parent 8c9c21c commit c10d994
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 107 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [6.0.0] - 2021-08-10
### Fixed
- Fixed performance regression in PSDImporter Editor (case 1349408)
- Updated manual on Importer override to use latest API.

### Changed
- Changed some of PSDImporter settings to use checkboxes instead of drop down

## [6.0.0-pre.4] - 2021-07-05
### Fixed
- Fixed changing PSD Importer inspector fields causes UnityEditor.ObjectPreview errors (case 1333823)
Expand Down
20 changes: 7 additions & 13 deletions Documentation~/PSD-importer-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,16 @@ The following section is only available if the **Texture Type** is set to **Mult
![](images/psdimporter-properties-v6-21.2-layerimport.png)
Property |Function
--|--
**Import Mode** | Use this property to specify how the layers from the source file are imported. This property is set to **Individual Sprites (Mosaic)** by default.
  [Individual Sprites (Mosaic)](#Mosaic)|Select this option to have the PSD Importer generate individual Sprites from the individual layers of the source file, and combines them into a single Texture in a Sprite sheet layout.
  [Merged](#merged) | Select this to have the PSD Importer generate a Texture with all layers merged.
**Layer Name** |This setting is only available if you set the **Import Mode** to **Individual Sprites (Mosaic)**. Use this property to specify how the importer handles layer names when duplicated layer names are found. This property is set to **Keep Duplicate Names** by default.
  [Keep Duplicate Names](#keep-duplicate-names) | Select this to have the PSD Importer generate Sprites from the source files with the exact same name as their source layers, even when there are multiple layers with the same name.
  Resolve Duplicate Names | Select this to have the PSD Importer generate Sprites from the source files with the same name as their source layers. If there are multiple layers with the same name, the Sprite’s name will be prefixed with a number.
**Layer** |This setting is only available if you set the **Import Mode** to **Individual Sprites (Mosaic)**.<br/>Use this property to specify how the importer handles layer’s that are set to not visible in the source file. This property is set to **Visible Layers Only** by default. |
&nbsp;&nbsp;Visible Layers Only |Select this to only import the visible layers from the source file.
&nbsp;&nbsp;Include Hidden Layers |Select this to include the hidden layers of the source file in the import. This produces the same import result as making all layers visible in the source file before you import it into Unity. |
**Layer Mapping ID**| Select this option to use the internal ID provided by the .psb file to map between the .psb file’s layer and the generated Sprite.|
**Include Hidden Layers** | Enable this property to include the hidden [layers](https://helpx.adobe.com/photoshop/using/layer-basics.html#layers_panel_overview) of the .psb file in the import. This produces the same import result as making all layers visible in the source file unhiding all layers in the source file before you importing it into Unity. Clear this option if you want to only import the visible layers in the .psb file. |
[__Keep Duplicate Name__](#keep-duplicate-name) | Enable this setting to make the PSD Importer generate Sprites from the source files with the exact same name as their source layers, even when there are multiple layers with the same name. |
__Use Layer Grouping__<a name="LayerGrouping"></a> | This setting is only available when you enable __Character Rig__. Enable this setting to make the importer generate a Prefab that follows the layer and grouping hierarchy of the imported .psb. file. |
**Layer Mapping**| Select this option to use the internal ID provided by the .psb file to map between the .psb file’s layer and the generated Sprite.|
&nbsp;&nbsp;Use Layer ID |Select this to only import the visible layers in the .psb file. |
&nbsp;&nbsp;Use Layer Name| Select this option to use the name of the layer in the .psb file to map between the .psb file’s layer and the generated Sprite. Note that for this option to work correctly, each layer's name needs to be unique. Duplicated names might cause layers to be mapped to the wrong Sprite.|
&nbsp;&nbsp;Use Layer Name (Case Sensitive) | Select this option to use the name of the layer (with case sensitivity) in the .psb file to map between the .psb file’s layer and the generated Sprite. Note that for this option to work correctly, each layer's name needs to be unique. Duplicated names might cause layers to be mapped to the wrong Sprite. |
[Layer Group](#layer-group) |Use this property to specify how the importer handles the Layer group from the source file.<br/>This setting is only available when you enable **Use as Rig** and set the **Import Mode** to **Individual Sprites (Mosaic)**. |
&nbsp;&nbsp;Ignore Layer Groups |Select this option to have the generated Prefab contain only Layers from the source file while ignoring Layer Groups. |
&nbsp;&nbsp;As Per Source File |Select this option to make the importer generate a Prefab that follows the layer and grouping hierarchy of the imported .psb. |
**Import Mode** | Use this property to specify how the layers from the source file are imported. This property is set to **Individual Sprites (Mosaic)** by default.
&nbsp;&nbsp;[Individual Sprites (Mosaic)](#Mosaic)|Select this option to have the PSD Importer generate individual Sprites from the individual layers of the source file, and combines them into a single Texture in a Sprite sheet layout.
&nbsp;&nbsp;[Merged](#merged) | Select this to have the PSD Importer generate a Texture with all layers merged.

####<a name="Mosaic">Individual Sprites (Mosaic)</a>
Enable this to have the PSD Importer attempt to create a Texture with each layer from the source file laid out in a mosaic manner.
Expand Down
34 changes: 7 additions & 27 deletions Documentation~/PSD-override.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,21 @@
# PSD File Importer Override

From Unity 2019.30f1 onwards, you can customize the PSD Importer to import files with the .psd extension. To do that you need to create custom scripts that call the `AssetDatabaseExperimental.SetImporterOverride` method.
It is possible to use PSDImporter to import files with 'psd' extensions. The following are the sample scripts that you can use.

## Example SetImporterOverride scripts

### PSDImporterOverride.cs
```
using UnityEngine;
namespace UnityEditor.U2D.PSD
{
[ScriptedImporter(1, "psd", AutoSelect = false)]
[AssetImporters.ScriptedImporter(1, new string[0],new[] {"psd"} )]
internal class PSDImporterOverride : PSDImporter
{
[MenuItem("Assets/2D Importer", false, 30)]
[MenuItem("Assets/2D Importer/Change PSD File Importer", false, 30)]
static void ChangeImporter()
{
foreach (var obj in Selection.objects)
{
var path = AssetDatabase.GetAssetPath(obj);
var ext = System.IO.Path.GetExtension(path);
if (ext == ".psd")
{
var importer = AssetImporter.GetAtPath(path);
if (importer is PSDImporterOverride)
{
Debug.Log(string.Format("{0} is now imported with TextureImporter", path));
AssetDatabaseExperimental.ClearImporterOverride(path);
}
else
{
Debug.Log(string.Format("{0} is now imported with PSDImporter", path));
AssetDatabaseExperimental.SetImporterOverride<PSDImporterOverride>(path);
}
}
}
}
}
}
```

### PSDImporterOverrideEditor.cs
Expand All @@ -52,3 +29,6 @@ namespace UnityEditor.U2D.PSD
}
```

After implementing the above scripts, you will be able to switch the importer from a dropdown list in the Inspector.
![](images/PSDImporterOverride.png)
Binary file added Documentation~/images/PSDImporterOverride.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions Editor/PSDImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,9 @@ internal SpriteImportMode spriteImportMode
}
}

/// <summary>
/// Implementation for ISpriteEditorDataProvider.pixelsPerUnit.
/// </summary>
SpriteImportMode ISpriteEditorDataProvider.spriteImportMode => spriteImportMode;

internal int spriteDataCount
Expand Down Expand Up @@ -1259,6 +1262,11 @@ internal T GetDataProvider<T>() where T : class
return this as T;
}

/// <summary>
/// Implementation for ISpriteEditorDataProvider.GetDataProvider.
/// </summary>
/// <typeparam name="T">Data provider type to retrieve.</typeparam>
/// <returns></returns>
T ISpriteEditorDataProvider.GetDataProvider<T>()
{
return GetDataProvider<T>();
Expand Down Expand Up @@ -1286,6 +1294,11 @@ internal bool HasDataProvider(Type type)
return type.IsAssignableFrom(GetType());
}

/// <summary>
/// Implementation for ISpriteEditorDataProvider.HasDataProvider.
/// </summary>
/// <param name="type">Data provider type to query.</param>
/// <returns>True if data provider is supported, false otherwise.</returns>
bool ISpriteEditorDataProvider.HasDataProvider(Type type)
{
return HasDataProvider(type);
Expand Down Expand Up @@ -1340,12 +1353,19 @@ internal void Apply()
EditorPrefs.SetBool("VerifySavingAssets", originalValue);
}

/// <summary>
/// Implementation for ISpriteEditorDataProvider.Apply.
/// </summary>
void ISpriteEditorDataProvider.Apply()
{
Apply();
}

internal void InitSpriteEditorDataProvider() {}

/// <summary>
/// Implementation for ISpriteEditorDataProvider.InitSpriteEditorDataProvider.
/// </summary>
void ISpriteEditorDataProvider.InitSpriteEditorDataProvider()
{
InitSpriteEditorDataProvider();
Expand All @@ -1358,6 +1378,10 @@ internal SpriteRect[] GetSpriteRects()
return spriteImportMode == SpriteImportMode.Multiple ? spriteImportData.Skip(skip).Select(x => new SpriteMetaData(x) as SpriteRect).ToArray() : new[] {new SpriteMetaData(spriteImportData[0]) };
}

/// <summary>
/// Implementation for ISpriteEditorDataProvider.GetSpriteRects.
/// </summary>
/// <returns>An array of SpriteRect for the current import mode.</returns>
SpriteRect[] ISpriteEditorDataProvider.GetSpriteRects()
{
return GetSpriteRects();
Expand Down Expand Up @@ -1465,6 +1489,10 @@ internal void SetSpriteRects(SpriteRect[] spriteRects)
}
}

/// <summary>
/// Implementation for ISpriteEditorDataProvider.SetSpriteRects.
/// </summary>
/// <param name="spriteRects">Set the SpriteRect data for the current import mode.</param>
void ISpriteEditorDataProvider.SetSpriteRects(SpriteRect[] spriteRects)
{
SetSpriteRects(spriteRects);
Expand Down
Loading

0 comments on commit c10d994

Please sign in to comment.