diff --git a/CHANGELOG.md b/CHANGELOG.md index befcb34..18ee520 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [9.0.3] - 2024-04-01 +### Fixed +- Fix source file cannot be deleted after subsequent import. (Case DANB-579) + +### Changed +- Updated the Editor Analytics to use the latest APIs. + ## [9.0.2] - 2024-02-06 ### Fixed - Provide custom packing override for users to override to address DANB-526. (Case DANB-526) diff --git a/Editor/Analytics.cs b/Editor/Analytics.cs index 0ee3ff0..8e259ae 100644 --- a/Editor/Analytics.cs +++ b/Editor/Analytics.cs @@ -7,7 +7,12 @@ namespace UnityEditor.U2D.PSD { [Serializable] internal struct PSDApplyEvent +#if USE_NEW_EDITOR_ANALYTICS + : IAnalytic.IData +#endif { + public const string name = "psdImporterApply"; + public int instance_id; public int texture_type; public int sprite_mode; @@ -20,9 +25,32 @@ internal struct PSDApplyEvent public SpriteAlignment character_alignment; public bool is_psd; public PsdColorMode color_mode; - } +#if USE_NEW_EDITOR_ANALYTICS + [AnalyticInfo(eventName: PSDApplyEvent.name, + vendorKey: Analytics.vendorKey, + version: Analytics.version, + maxEventsPerHour: Analytics.maxEventsPerHour, + maxNumberOfElements: Analytics.maxNumberOfElements)] + internal class PSDApplyEventAnalytic : IAnalytic + { + PSDApplyEvent m_EvtData; + + public PSDApplyEventAnalytic(PSDApplyEvent evtData) + { + m_EvtData = evtData; + } + + public bool TryGatherData(out IAnalytic.IData data, out Exception error) + { + data = m_EvtData; + error = null; + return true; + } + } +#endif + internal interface IAnalytics { AnalyticsResult SendApplyEvent(PSDApplyEvent evt); @@ -31,34 +59,36 @@ internal interface IAnalytics internal static class AnalyticFactory { static IAnalytics s_Analytics; - static public IAnalytics analytics + + public static IAnalytics analytics { - get - { - if (s_Analytics == null) - s_Analytics = new Analytics(); - return s_Analytics; - } - set { s_Analytics = value; } + get => s_Analytics ??= new Analytics(); + set => s_Analytics = value; } } [InitializeOnLoad] internal class Analytics : IAnalytics { - const int k_MaxEventsPerHour = 100; - const int k_MaxNumberOfElements = 1000; - const string k_VendorKey = "unity.2d.psdimporter"; - const int k_Version = 1; + public const int maxEventsPerHour = 100; + public const int maxNumberOfElements = 1000; + public const string vendorKey = "unity.2d.psdimporter"; + public const int version = 1; static Analytics() { - EditorAnalytics.RegisterEventWithLimit("psdImporterApply", k_MaxEventsPerHour, k_MaxNumberOfElements, k_VendorKey, k_Version); +#if !USE_NEW_EDITOR_ANALYTICS + EditorAnalytics.RegisterEventWithLimit(PSDApplyEvent.name, maxEventsPerHour, maxNumberOfElements, vendorKey, version); +#endif } public AnalyticsResult SendApplyEvent(PSDApplyEvent evt) { - return EditorAnalytics.SendEventWithLimit("psdImporterApply", evt, k_Version); +#if USE_NEW_EDITOR_ANALYTICS + return EditorAnalytics.SendAnalytic(new PSDApplyEventAnalytic(evt)); +#else + return EditorAnalytics.SendEventWithLimit(PSDApplyEvent.name, evt, version); +#endif } } -} +} \ No newline at end of file diff --git a/Editor/PSDPlugin/PsdFile/PsdFile.cs b/Editor/PSDPlugin/PsdFile/PsdFile.cs index abb55a2..ee5d8cc 100644 --- a/Editor/PSDPlugin/PsdFile/PsdFile.cs +++ b/Editor/PSDPlugin/PsdFile/PsdFile.cs @@ -109,6 +109,9 @@ private void Load(Stream stream, LoadContext loadContext, ELoadFlag loadFlag) LoadImage(reader); DecompressImages(); } + + reader.Dispose(); + reader = null; } #endregion @@ -557,10 +560,10 @@ internal void VerifyLayerSections() if (depth < 0) throw new PsdInvalidException("Layer section ended without matching start marker."); break; - + case LayerSectionType.Layer: // Nothing to do here yet. break; - + default: throw new PsdInvalidException("Unrecognized layer section type."); } @@ -594,7 +597,7 @@ public void SetVersionInfo() versionInfo.FileVersion = 1; } } - + /////////////////////////////////////////////////////////////////////////// @@ -708,4 +711,4 @@ internal enum ImageCompression /// ZipPrediction = 3 } -} +} \ No newline at end of file diff --git a/Editor/Unity.2D.Psdimporter.Editor.asmdef b/Editor/Unity.2D.Psdimporter.Editor.asmdef index b76638a..099b8e8 100644 --- a/Editor/Unity.2D.Psdimporter.Editor.asmdef +++ b/Editor/Unity.2D.Psdimporter.Editor.asmdef @@ -26,6 +26,11 @@ "name": "com.unity.2d.animation", "expression": "0.0.1", "define": "ENABLE_2D_ANIMATION" + }, + { + "name": "Unity", + "expression": "2023.2.0a22", + "define": "USE_NEW_EDITOR_ANALYTICS" } ], "noEngineReferences": false diff --git a/package.json b/package.json index 282de89..1f22680 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.unity.2d.psdimporter", - "version": "9.0.2", + "version": "9.0.3", "unity": "2023.1", "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.", @@ -15,7 +15,7 @@ "com.unity.2d.sprite": "1.0.0" }, "relatedPackages": { - "com.unity.2d.psdimporter.tests": "9.0.2" + "com.unity.2d.psdimporter.tests": "9.0.3" }, "samples": [ { @@ -25,15 +25,15 @@ } ], "_upm": { - "changelog": "### Fixed\n- Provide custom packing override for users to override to address DANB-526. (Case DANB-526)\n- Fixed layers are not shown in LayerImportSettings after unselecting all layers and applying. (Case DANB-569)" + "changelog": "### Fixed\n- Fix source file cannot be deleted after subsequent import. (Case DANB-579)\n\n### Changed\n- Updated the Editor Analytics to use the latest APIs." }, "upmCi": { - "footprint": "d8630d2026a2a1f0ccffccd1458e4ec610fda110" + "footprint": "ec7f070542925957d8aeffef11be9cd939d31bd7" }, "documentationUrl": "https://docs.unity3d.com/Packages/com.unity.2d.psdimporter@9.0/manual/index.html", "repository": { "url": "https://github.cds.internal.unity3d.com/unity/2d.git", "type": "git", - "revision": "de1d2b0a924b0621324b0cfe0fcbef92f03bd2c2" + "revision": "cacb780673a1e5d1e9bd0e398015b1a9924c0922" } }