From 392315ac32bdd58f549b134f37cf735d1a5eccda Mon Sep 17 00:00:00 2001 From: Unity Technologies <@unity> Date: Wed, 24 Nov 2021 00:00:00 +0000 Subject: [PATCH] com.unity.2d.psdimporter@7.0.0-pre.4 ## [7.0.0-pre.4] - 2021-11-24 ### Fixed - Fixed per platform settings does not get applied in Windows platform. (Case 1376608) - Fixed unable to change mipmap settings in inspector. (Case 1379426) - Fixed PSDImporter to able to specify swizzle data. ### Added - Added ability to change swizzle format in inspector. --- CHANGELOG.md | 9 +++++ Editor/PSDImporter.cs | 17 +++++++-- Editor/PSDImporterAPI.cs | 62 +++++++++++++++++++++++++++----- Editor/PSDImporterEditor.cs | 70 ++++++++++++++++++++++++++++++++++--- package.json | 14 ++++---- 5 files changed, 150 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32c5daf..ac6e4d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## [7.0.0-pre.4] - 2021-11-24 +### Fixed +- Fixed per platform settings does not get applied in Windows platform. (Case 1376608) +- Fixed unable to change mipmap settings in inspector. (Case 1379426) +- Fixed PSDImporter to able to specify swizzle data. + +### Added +- Added ability to change swizzle format in inspector. + ## [7.0.0-pre.3] - 2021-10-21 ### Changed - Update to latest com.unity.2d.animation package diff --git a/Editor/PSDImporter.cs b/Editor/PSDImporter.cs index 4461c85..45dc4ae 100644 --- a/Editor/PSDImporter.cs +++ b/Editor/PSDImporter.cs @@ -20,7 +20,7 @@ namespace UnityEditor.U2D.PSD /// ScriptedImporter to import Photoshop files /// // Version using unity release + 5 digit padding for future upgrade. Eg 2021.2 -> 21200000 - [ScriptedImporter(22100000, new string[]{"psb"}, new []{"psd"}, AllowCaching = true)] + [ScriptedImporter(22100001, 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 @@ -99,6 +99,10 @@ internal enum ECustomSpriteMode wrapModeU = TextureWrapMode.Repeat, wrapModeV = TextureWrapMode.Repeat, wrapModeW = TextureWrapMode.Repeat, + swizzleR = TextureImporterSwizzle.R, + swizzleG = TextureImporterSwizzle.G, + swizzleB = TextureImporterSwizzle.B, + swizzleA = TextureImporterSwizzle.A, }; [SerializeField] @@ -241,6 +245,14 @@ ECustomSpriteMode GetCustomSpriteMode() } return ECustomSpriteMode.Multiple; } + + public PSDImporter() + { + m_TextureImporterSettings.swizzleA = TextureImporterSwizzle.A; + m_TextureImporterSettings.swizzleR = TextureImporterSwizzle.R; + m_TextureImporterSettings.swizzleG = TextureImporterSwizzle.G; + m_TextureImporterSettings.swizzleB = TextureImporterSwizzle.B; + } /// /// Implementation of ScriptedImporter.OnImportAsset @@ -251,6 +263,7 @@ ECustomSpriteMode GetCustomSpriteMode() /// public override void OnImportAsset(AssetImportContext ctx) { + FileStream fileStream = new FileStream(ctx.assetPath, FileMode.Open, FileAccess.Read); Document doc = null; if(m_ImportData == null) @@ -760,7 +773,7 @@ void EnsureSingleSpriteExist() TextureImporterPlatformSettings GetPlatformTextureSettings(BuildTarget buildTarget) { - var buildTargetName = TexturePlatformSettingsHelper.GetBuildTargetName(buildTarget); + var buildTargetName = TexturePlatformSettingsHelper.GetBuildTargetGroupName(buildTarget); TextureImporterPlatformSettings platformSettings = null; platformSettings = m_PlatformSettings.SingleOrDefault(x => x.name == buildTargetName && x.overridden == true); platformSettings = platformSettings ?? m_PlatformSettings.SingleOrDefault(x => x.name == TexturePlatformSettingsHelper.defaultPlatformName); diff --git a/Editor/PSDImporterAPI.cs b/Editor/PSDImporterAPI.cs index bca3e12..c013b1c 100644 --- a/Editor/PSDImporterAPI.cs +++ b/Editor/PSDImporterAPI.cs @@ -162,10 +162,7 @@ public bool mipMapsPreserveCoverage /// Exception when non valid values are set. public SpriteImportMode spriteImportMode { - get - { - return (SpriteImportMode)m_TextureImporterSettings.spriteMode; - } + get { return (SpriteImportMode)m_TextureImporterSettings.spriteMode; } set { if (value == SpriteImportMode.Multiple || value == SpriteImportMode.Single) @@ -185,10 +182,7 @@ public SpriteImportMode spriteImportMode /// Exception when non valid values are set. public TextureImporterType textureType { - get - { - return (TextureImporterType)m_TextureImporterSettings.textureType; - } + get { return (TextureImporterType)m_TextureImporterSettings.textureType; } set { if (value == TextureImporterType.Sprite || value == TextureImporterType.Default) @@ -331,8 +325,58 @@ public bool useMosaicMode SetDirty(); } } + + internal TextureImporterSwizzle swizzeR + { + get { return m_TextureImporterSettings.swizzleR; } + set + { + m_TextureImporterSettings.swizzleR = value; + SetDirty(); + } + } + + internal TextureImporterSwizzle swizzeG + { + get { return m_TextureImporterSettings.swizzleG; } + set + { + m_TextureImporterSettings.swizzleG = value; + SetDirty(); + } + } - void SetDirty() + internal TextureImporterSwizzle swizzeB + { + get { return m_TextureImporterSettings.swizzleB; } + set + { + m_TextureImporterSettings.swizzleB = value; + SetDirty(); + } + } + + internal TextureImporterSwizzle swizzeA + { + get { return m_TextureImporterSettings.swizzleA; } + set + { + m_TextureImporterSettings.swizzleA = value; + SetDirty(); + } + } + + internal bool sRGBTexture + { + get { return m_TextureImporterSettings.sRGBTexture; } + set + { + m_TextureImporterSettings.sRGBTexture = value; + SetDirty(); + } + } + + void SetDirty() { EditorUtility.SetDirty(this); } diff --git a/Editor/PSDImporterEditor.cs b/Editor/PSDImporterEditor.cs index 3c905f4..0afc494 100644 --- a/Editor/PSDImporterEditor.cs +++ b/Editor/PSDImporterEditor.cs @@ -42,6 +42,7 @@ struct InspectorGUI SerializedProperty m_IsReadable; SerializedProperty m_sRGBTexture; SerializedProperty m_AlphaSource; + SerializedProperty m_Swizzle; SerializedProperty m_MipMapMode; SerializedProperty m_EnableMipMap; SerializedProperty m_FadeOut; @@ -75,7 +76,8 @@ struct InspectorGUI private SkeletonAsset m_SkeletonAsset; readonly int[] m_FilterModeOptions = (int[])(Enum.GetValues(typeof(FilterMode))); - + static readonly int s_SwizzleFieldHash = "SwizzleField".GetHashCode(); + bool m_IsPOT = false; Dictionary m_AdvanceInspectorGUI = new Dictionary(); int m_PlatformSettingsIndex; @@ -131,6 +133,7 @@ public override void OnEnable() m_AlphaSource = textureImporterSettingsSP.FindPropertyRelative("m_AlphaSource"); m_MipMapMode = textureImporterSettingsSP.FindPropertyRelative("m_MipMapMode"); m_EnableMipMap = textureImporterSettingsSP.FindPropertyRelative("m_EnableMipMap"); + m_Swizzle = textureImporterSettingsSP.FindPropertyRelative("m_Swizzle"); m_FadeOut = textureImporterSettingsSP.FindPropertyRelative("m_FadeOut"); m_BorderMipMap = textureImporterSettingsSP.FindPropertyRelative("m_BorderMipMap"); m_MipMapsPreserveCoverage = textureImporterSettingsSP.FindPropertyRelative("m_MipMapsPreserveCoverage"); @@ -159,7 +162,8 @@ public override void OnEnable() AlphaHandlingGUI, POTScaleGUI, ReadableGUI, - MipMapGUI + MipMapGUI, + SwizzleGUI }; m_AdvanceInspectorGUI.Add(TextureImporterType.Sprite, advanceGUIAction); @@ -167,7 +171,8 @@ public override void OnEnable() { POTScaleGUI, ReadableGUI, - MipMapGUI + MipMapGUI, + SwizzleGUI }; m_AdvanceInspectorGUI.Add(TextureImporterType.Default, advanceGUIAction); LoadPlatformSettings(); @@ -911,7 +916,7 @@ void MipMapGUI() { EditorGUI.indentLevel++; ToggleFromInt(m_BorderMipMap, s_Styles.borderMipMaps); - EditorGUILayout.Popup(s_Styles.mipMapFilter, m_MipMapMode.intValue, s_Styles.mipMapFilterOptions); + m_MipMapMode.intValue = EditorGUILayout.Popup(s_Styles.mipMapFilter, m_MipMapMode.intValue, s_Styles.mipMapFilterOptions); ToggleFromInt(m_MipMapsPreserveCoverage, s_Styles.mipMapsPreserveCoverage); if (m_MipMapsPreserveCoverage.intValue != 0 && !m_MipMapsPreserveCoverage.hasMultipleDifferentValues) @@ -978,6 +983,42 @@ void ExportMosaicTexture() AssetDatabase.Refresh(); } + static void SwizzleField(SerializedProperty property, GUIContent label) + { + EditorGUI.BeginProperty(EditorGUILayout.BeginHorizontal(), label, property); + EditorGUI.BeginChangeCheck(); + EditorGUI.showMixedValue = property.hasMultipleDifferentValues; + var rect = EditorGUILayout.GetControlRect(true, EditorGUI.GetPropertyHeight(SerializedPropertyType.Vector4, label), EditorStyles.numberField); + var id = GUIUtility.GetControlID(s_SwizzleFieldHash, FocusType.Keyboard, rect); + rect = EditorGUI.PrefixLabel(rect, id, label); + var value = property.uintValue; + float w = (rect.width - 3 * EditorGUIUtility.standardVerticalSpacing) / 4; + var subRect = new Rect(rect) {width = w}; + var oldIndent = EditorGUI.indentLevel; + EditorGUI.indentLevel = 0; + for (int i = 0; i < 4; i++) + { + int shift = 8 * i; + uint swz = (value >> shift) & 0xFF; + swz = (uint)EditorGUI.Popup(subRect, (int)swz, s_Styles.swizzleOptions); + value &= ~(0xFFu << shift); + value |= swz << shift; + subRect.x += w + EditorGUIUtility.standardVerticalSpacing; + } + EditorGUI.indentLevel = oldIndent; + + EditorGUI.showMixedValue = false; + if (EditorGUI.EndChangeCheck()) + property.uintValue = value; + EditorGUILayout.EndHorizontal(); + EditorGUI.EndProperty(); + } + + void SwizzleGUI() + { + SwizzleField(m_Swizzle, s_Styles.swizzle); + } + /// /// Implementation of AssetImporterEditor.ResetValues. /// @@ -1068,6 +1109,14 @@ void ITexturePlatformSettingsDataProvider.GetImporterSettings(int i, TextureImpo GetSerializedPropertySettings(settings); } + static (TextureImporterSwizzle r, TextureImporterSwizzle g, TextureImporterSwizzle b, TextureImporterSwizzle a) ConvertSwizzleRaw(uint value) + { + return ((TextureImporterSwizzle)((int)value & (int)byte.MaxValue), + (TextureImporterSwizzle) ((int)(value >> 8) & (int) byte.MaxValue), + (TextureImporterSwizzle) ((int)(value >> 16) & (int) byte.MaxValue), + (TextureImporterSwizzle) ((int)(value >> 24) & (int) byte.MaxValue)); + } + internal TextureImporterSettings GetSerializedPropertySettings(TextureImporterSettings settings) { if (!m_AlphaSource.hasMultipleDifferentValues) @@ -1100,6 +1149,15 @@ internal TextureImporterSettings GetSerializedPropertySettings(TextureImporterSe if (!m_MipMapMode.hasMultipleDifferentValues) settings.mipmapFilter = (TextureImporterMipFilter)m_MipMapMode.intValue; + if (!m_Swizzle.hasMultipleDifferentValues) + { + var swizzleValue = ConvertSwizzleRaw(m_Swizzle.uintValue); + settings.swizzleR = swizzleValue.r; + settings.swizzleG = swizzleValue.g; + settings.swizzleB = swizzleValue.b; + settings.swizzleA = swizzleValue.a; + } + if (!m_FadeOut.hasMultipleDifferentValues) settings.fadeOut = m_FadeOut.intValue > 0; @@ -1435,6 +1493,10 @@ internal class Styles EditorGUIUtility.TrTextContent("Layer Management", "Layer merge settings.") }; + public readonly GUIContent swizzle = EditorGUIUtility.TrTextContent("Swizzle", + "Reorder and invert texture color channels. For each of R,G,B,A channels pick where the channel data comes from."); + public readonly string[] swizzleOptions = new[] {"R","G","B","A", "1-R","1-G","1-B","1-A", "0","1" }; + public Styles() { // This is far from ideal, but it's better than having tons of logic in the GUI code itself. diff --git a/package.json b/package.json index 75e8263..57950a8 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "com.unity.2d.psdimporter", - "version": "7.0.0-pre.3", + "version": "7.0.0-pre.4", "unity": "2022.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.\n\nDocumentation for v5.0 is currently being updated.", + "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": [ "2d", "psdimporter", @@ -11,19 +11,19 @@ ], "category": "2D", "dependencies": { - "com.unity.2d.animation": "8.0.0-pre.3", - "com.unity.2d.common": "7.0.0-pre.3", + "com.unity.2d.animation": "8.0.0-pre.4", + "com.unity.2d.common": "7.0.0-pre.4", "com.unity.2d.sprite": "1.0.0" }, "relatedPackages": { - "com.unity.2d.psdimporter.tests": "7.0.0-pre.3" + "com.unity.2d.psdimporter.tests": "7.0.0-pre.4" }, "upmCi": { - "footprint": "5f2aad71791167dc2ab90b88c9659eb3088a025b" + "footprint": "f1a15a8f988d611cbb180bebea038e1fe445bf5e" }, "repository": { "url": "https://github.cds.internal.unity3d.com/unity/2d.git", "type": "git", - "revision": "fc17ecffb5da8133c390aba47276756c1b22f123" + "revision": "2ccafc0d438881083c9c1ec71f92ef170494bd59" } }