From 762a82e884930589ceadf7af14152cc4ae989079 Mon Sep 17 00:00:00 2001 From: Unity Technologies <@unity> Date: Tue, 7 Jul 2020 00:00:00 +0000 Subject: [PATCH] com.unity.2d.psdimporter@4.0.1 ## [4.0.1] - 2020-07-07 ### Fixed - Fixed ArgumentException thrown when 2D Game Kit is imported for the first time (case 1244287) - Updated to use non-experimental AssetImporter (case 1254380) --- CHANGELOG.md | 5 +++++ Editor/PSDImportPostProcessor.cs | 23 ++++++++++++++++++----- Editor/PSDImporter.cs | 10 +++++----- Editor/PSDImporterEditor.cs | 4 +++- Editor/SpriteData.cs | 4 ++-- package.json | 14 +++++++------- 6 files changed, 40 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72fcc50..246a3f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [4.0.1] - 2020-07-07 +### Fixed +- Fixed ArgumentException thrown when 2D Game Kit is imported for the first time (case 1244287) +- Updated to use non-experimental AssetImporter (case 1254380) + ## [4.0.0] - 2020-05-11 ### Changed - Version bump for Unity 2020.2 diff --git a/Editor/PSDImportPostProcessor.cs b/Editor/PSDImportPostProcessor.cs index 3726445..e041c0b 100644 --- a/Editor/PSDImportPostProcessor.cs +++ b/Editor/PSDImportPostProcessor.cs @@ -14,7 +14,10 @@ void OnPostprocessSprites(Texture2D texture, Sprite[] sprites) { var dataProviderFactories = new SpriteDataProviderFactories(); dataProviderFactories.Init(); - ISpriteEditorDataProvider importer = dataProviderFactories.GetSpriteEditorDataProviderFromObject(AssetImporter.GetAtPath(assetPath)); + PSDImporter psd = AssetImporter.GetAtPath(assetPath) as PSDImporter; + if (psd == null) + return; + ISpriteEditorDataProvider importer = dataProviderFactories.GetSpriteEditorDataProviderFromObject(psd); if (importer != null) { importer.InitSpriteEditorDataProvider(); @@ -32,13 +35,23 @@ void OnPostprocessSprites(Texture2D texture, Sprite[] sprites) var outlineOffset = sprite.rect.size / 2; if (outline != null && outline.Count > 0) { - var convertedOutline = new Vector2[outline.Count][]; + // Ensure that outlines are all valid. + int validOutlineCount = 0; + for (int i = 0; i < outline.Count; ++i) + validOutlineCount = validOutlineCount + ( (outline[i].Length > 2) ? 1 : 0 ); + + int index = 0; + var convertedOutline = new Vector2[validOutlineCount][]; for (int i = 0; i < outline.Count; ++i) { - convertedOutline[i] = new Vector2[outline[i].Length]; - for (int j = 0; j < outline[i].Length; ++j) + if (outline[i].Length > 2) { - convertedOutline[i][j] = outline[i][j] * definitionScale + outlineOffset; + convertedOutline[index] = new Vector2[outline[i].Length]; + for (int j = 0; j < outline[i].Length; ++j) + { + convertedOutline[index][j] = outline[i][j] * definitionScale + outlineOffset; + } + index++; } } sprite.OverridePhysicsShape(convertedOutline); diff --git a/Editor/PSDImporter.cs b/Editor/PSDImporter.cs index 0314a6b..3f0fc3c 100644 --- a/Editor/PSDImporter.cs +++ b/Editor/PSDImporter.cs @@ -5,7 +5,7 @@ using UnityEngine; using Unity.Collections; using System.Linq; -using UnityEditor.Experimental.AssetImporters; +using UnityEditor.AssetImporters; using UnityEditor.U2D.Animation; using UnityEditor.U2D.Common; using UnityEditor.U2D.Sprites; @@ -13,8 +13,7 @@ using UnityEngine.Experimental.U2D.Animation; using UnityEngine.U2D; using UnityEngine.U2D.Animation; -using UnityEditor.MemoryProfiler; -using UnityEngine.Profiling.Memory.Experimental; +using UnityEngine.Scripting.APIUpdating; namespace UnityEditor.U2D.PSD { @@ -22,7 +21,8 @@ namespace UnityEditor.U2D.PSD /// ScriptedImporter to import Photoshop files /// [ScriptedImporter(4, "psb")] - [HelpURL("https://docs.unity3d.com/Packages/com.unity.2d.psdimporter@3.1/manual/index.html")] + [HelpURL("https://docs.unity3d.com/Packages/com.unity.2d.psdimporter@latest")] + [MovedFrom("UnityEditor.Experimental.AssetImporters")] public class PSDImporter : ScriptedImporter, ISpriteEditorDataProvider { class UniqueNameGenerator @@ -342,7 +342,7 @@ TextureGenerationOutput ImportTexture(AssetImportContext ctx, NativeArray [CustomEditor(typeof(PSDImporter))] + [MovedFrom("UnityEditor.Experimental.AssetImporters")] public class PSDImporterEditor : ScriptedImporterEditor, ITexturePlatformSettingsDataProvider { SerializedProperty m_TextureType; diff --git a/Editor/SpriteData.cs b/Editor/SpriteData.cs index 92a7191..2cbdf53 100644 --- a/Editor/SpriteData.cs +++ b/Editor/SpriteData.cs @@ -68,9 +68,9 @@ public static Vector2 GetPivotValue(SpriteAlignment alignment, Vector2 customOff return Vector2.zero; } - public static implicit operator UnityEditor.Experimental.AssetImporters.SpriteImportData(SpriteMetaData value) + public static implicit operator UnityEditor.AssetImporters.SpriteImportData(SpriteMetaData value) { - var output = new UnityEditor.Experimental.AssetImporters.SpriteImportData(); + var output = new UnityEditor.AssetImporters.SpriteImportData(); output.name = value.name; output.alignment = value.alignment; output.rect = value.rect; diff --git a/package.json b/package.json index aaf699b..5f4fccf 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "com.unity.2d.psdimporter", - "version": "4.0.0", + "version": "4.0.1", "unity": "2020.2", - "unityRelease": "0a14", + "unityRelease": "0a19", "displayName": "2D PSD Importer", "description": "A ScriptedImporter for importing Adobe Photoshop PSB (Photoshop Big) file format. The ScriptedImporter is currently targeted for users who wants to create multi Sprite character animation using Unity 2D Animation Package.", "keywords": [ @@ -12,19 +12,19 @@ ], "category": "2D", "dependencies": { - "com.unity.2d.common": "4.0.0", - "com.unity.2d.animation": "5.0.0", + "com.unity.2d.common": "4.0.1", + "com.unity.2d.animation": "5.0.1", "com.unity.2d.sprite": "1.0.0" }, "relatedPackages": { - "com.unity.2d.psdimporter.tests": "4.0.0" + "com.unity.2d.psdimporter.tests": "4.0.1" }, "upmCi": { - "footprint": "d2b08e5f1725cfeb59cd2f03f5c922d7f5579ed5" + "footprint": "8f06a9aae8646933a40d67cc3ac738f21194b732" }, "repository": { "url": "https://github.cds.internal.unity3d.com/unity/2d.git", "type": "git", - "revision": "4651ccecac488987a6b5bbb033282cb61de0e007" + "revision": "7d7470f4ca0ea8353d4c9640b3b6ae9d1ebd9c1d" } }