Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
## [8.0.2] - 2022-12-01
### Fixed
- Fixed an issue where the editor would crash when importing .psd/.psb files with their layers outside of the document canvas. (Case DANB-300)
- Fixed an issue where the amount of alpha removed from layers would not be re-applied as final position offset of the layers.
- Fixed an issue where the generated GameObjects would be laid out differently from how they appear in the DCC tool. (Case DANB-298)
  • Loading branch information
Unity Technologies committed Dec 1, 2022
1 parent cb142bb commit 80ef6dc
Show file tree
Hide file tree
Showing 7 changed files with 276 additions and 146 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Changelog
## [8.0.2] - 2022-12-01
### Fixed
- Fixed an issue where the editor would crash when importing .psd/.psb files with their layers outside of the document canvas. (Case DANB-300)
- Fixed an issue where the amount of alpha removed from layers would not be re-applied as final position offset of the layers.
- Fixed an issue where the generated GameObjects would be laid out differently from how they appear in the DCC tool. (Case DANB-298)

## [8.0.1] - 2022-10-11
### Fixed
Expand Down
19 changes: 11 additions & 8 deletions Editor/PSDImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace UnityEditor.U2D.PSD
/// ScriptedImporter to import Photoshop files
/// </summary>
// Version using unity release + 5 digit padding for future upgrade. Eg 2021.2 -> 21200000
[ScriptedImporter(22200002, new string[]{"psb"}, new []{"psd"}, AllowCaching = true)]
[ScriptedImporter(22200003, new string[]{"psb"}, new []{"psd"}, AllowCaching = true)]
[HelpURL("https://docs.unity3d.com/Packages/com.unity.2d.psdimporter@latest")]
[MovedFrom("UnityEditor.Experimental.AssetImporters")]
public partial class PSDImporter : ScriptedImporter, ISpriteEditorDataProvider
Expand Down Expand Up @@ -488,7 +488,7 @@ TextureGenerationOutput ImportFlattenImage(Document doc, AssetImportContext ctx,
var outputImageBuffer = new NativeArray<Color32>(doc.width * doc.height, Allocator.Persistent);
try
{
FlattenImageTask.Execute(m_ExtractData, ref outputImageBuffer, m_ImportHiddenLayers, documentSize);
FlattenImageTask.Execute(m_ExtractData, ref outputImageBuffer, m_ImportHiddenLayers, canvasSize);

var spriteImportData = GetSpriteImportData();
if (spriteImportData.Count <= 0 || spriteImportData[0] == null)
Expand Down Expand Up @@ -538,7 +538,7 @@ TextureGenerationOutput ImportFromLayers(AssetImportContext ctx)
List<PSDLayer> psdLayers = null;
try
{
ExtractLayerTask.Execute(in m_ExtractData, out psdLayers, m_ImportHiddenLayers, documentSize);
ExtractLayerTask.Execute(in m_ExtractData, out psdLayers, m_ImportHiddenLayers, canvasSize);

var mappingStrategy = GetLayerMappingStrategy();
var layerUnique = mappingStrategy.LayersUnique(psdLayers.ConvertAll(x => (IPSDLayerMappingStrategyComparable)x));
Expand Down Expand Up @@ -586,6 +586,10 @@ TextureGenerationOutput ImportFromLayers(AssetImportContext ctx)

ImagePacker.Pack(layerBuffers.ToArray(), layerWidth.ToArray(), layerHeight.ToArray(), m_Padding, m_SpriteSizeExpand, out outputImageBuffer, out int width, out int height, out RectInt[] spriteData, out Vector2Int[] uvTransform);

var packOffsets = new Vector2[spriteData.Length];
for (var i = 0; i < packOffsets.Length; ++i)
packOffsets[i] = new Vector2((uvTransform[i].x - spriteData[i].position.x) / -1f, (uvTransform[i].y - spriteData[i].position.y) / -1f);

var spriteImportData = GetSpriteImportData();
if (spriteImportData.Count <= 0 || shouldResliceFromLayer || hasNewLayer)
{
Expand Down Expand Up @@ -613,12 +617,11 @@ TextureGenerationOutput ImportFromLayers(AssetImportContext ctx)

psdLayer.spriteName = ImportUtilities.GetUniqueSpriteName(psdLayer.name, spriteNameHash, m_KeepDupilcateSpriteName);
spriteSheet.name = psdLayer.spriteName;
spriteSheet.spritePosition = psdLayer.layerPosition;
spriteSheet.spritePosition = psdLayer.layerPosition + packOffsets[i];

if(shouldResliceFromLayer)
spriteSheet.rect = new Rect(spriteData[i].x, spriteData[i].y, spriteData[i].width, spriteData[i].height);



spriteSheet.uvTransform = uvTransform[i];

psdLayer.spriteID = spriteSheet.spriteID;
Expand Down Expand Up @@ -688,7 +691,7 @@ TextureGenerationOutput ImportFromLayers(AssetImportContext ctx)
r.height = spriteData[k].height;
}
spriteSheet.rect = r;
spriteSheet.spritePosition = psdLayers[i].layerPosition;
spriteSheet.spritePosition = psdLayers[i].layerPosition + packOffsets[k];
}

if (spriteSheet != null)
Expand Down Expand Up @@ -1227,7 +1230,7 @@ internal CharacterData characterData
}
}

internal Vector2Int documentSize => importData.documentSize;
internal Vector2Int canvasSize => importData.documentSize;

SpriteLibraryAsset ProduceSpriteLibAsset(Sprite[] sprites)
{
Expand Down
2 changes: 1 addition & 1 deletion Editor/PSDImporterDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public CharacterData GetCharacterData()

parts.Reverse();
cd.parts = parts.ToArray();
cd.dimension = dataProvider.documentSize;
cd.dimension = dataProvider.canvasSize;
cd.characterGroups = groups.ToArray();
return cd;
}
Expand Down
19 changes: 19 additions & 0 deletions Editor/PSDLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,25 @@ public PSDLayer(NativeArray<Color32> tex, int parent, bool group, string layerNa
m_SpriteID = new GUID().ToString();
}

public PSDLayer(PSDLayer layer)
{
m_Name = layer.m_Name;
m_SpriteName = layer.m_SpriteName;
m_IsGroup = layer.m_IsGroup;
m_ParentIndex = layer.m_ParentIndex;
m_SpriteID = layer.m_SpriteID;
m_LayerID = layer.m_LayerID;
m_MosaicPosition = layer.m_MosaicPosition;
m_Flatten = layer.m_Flatten;
m_IsImported = layer.m_IsImported;
m_IsVisible = layer.m_IsVisible;
m_LayerPosition = layer.m_LayerPosition;
m_GameObject = layer.m_GameObject;
width = layer.width;
height = layer.height;
texture = layer.texture;
}

public bool isVisible => m_IsVisible;
public int layerID { get { return m_LayerID; } private set { m_LayerID = value; } }

Expand Down
Loading

0 comments on commit 80ef6dc

Please sign in to comment.