Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
## [1.2.0-preview.4] - 2019-09-04
### Added
- Experimental feature to have Sprites with same name generated from source file
- Support for providing Layer and Group order to Animation Skinning Module
  • Loading branch information
Unity Technologies committed Sep 3, 2019
1 parent e826a30 commit 150faf4
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 25 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Changelog
All notable changes to this package will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [1.2.0-preview.4] - 2019-09-04
### Added
- Experimental feature to have Sprites with same name generated from source file
- Support for providing Layer and Group order to Animation Skinning Module

## [1.2.0-preview.3] - 2019-07-16
### Change
Expand Down
33 changes: 23 additions & 10 deletions Editor/PSDImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ struct BoneGO
[SerializeField]
bool m_PaperDollMode = false;

[SerializeField]
bool m_KeepDupilcateSpriteName = false;

[SerializeField]
SpriteCategoryList m_SpriteCategoryList = new SpriteCategoryList() {categories = new List<SpriteCategory>()};
GameObjectCreationFactory m_GameObjectFactory = new GameObjectCreationFactory();
Expand Down Expand Up @@ -354,6 +357,13 @@ void AutoGenerateSpriteSkinData(SpriteMetaData metaData)
}
}

string GetUniqueSpriteName(string name, List<int> namehash)
{
if (m_KeepDupilcateSpriteName)
return name;
return GetUniqueName(name, namehash);
}

void ImportFromLayers(AssetImportContext ctx, Document doc)
{
NativeArray<Color32> output = default(NativeArray<Color32>);
Expand Down Expand Up @@ -415,7 +425,7 @@ void ImportFromLayers(AssetImportContext ctx, Document doc)
spriteSheet.pivot = m_TextureImporterSettings.spritePivot;
}

psdLayers[layerIndex[i]].spriteName = GetUniqueName(psdLayers[layerIndex[i]].name, spriteNameHash);
psdLayers[layerIndex[i]].spriteName = GetUniqueSpriteName(psdLayers[layerIndex[i]].name, spriteNameHash);
spriteSheet.name = psdLayers[layerIndex[i]].spriteName;
spriteSheet.rect = new Rect(spritedata[i].x, spritedata[i].y, spritedata[i].width, spritedata[i].height);
spriteSheet.uvTransform = uvTransform[i];
Expand Down Expand Up @@ -445,7 +455,7 @@ void ImportFromLayers(AssetImportContext ctx, Document doc)
// layer name is still unique and use it as the sprite name
if (psdLayer != null && psdLayer.spriteName == spriteData.name)
{
psdLayer.spriteName = GetUniqueName(psdLayer.name, spriteNameHash);
psdLayer.spriteName = GetUniqueSpriteName(psdLayer.name, spriteNameHash);
spriteData.name = psdLayer.spriteName;
}
}
Expand All @@ -464,7 +474,7 @@ void ImportFromLayers(AssetImportContext ctx, Document doc)
spriteSheet.border = Vector4.zero;
spriteSheet.alignment = (SpriteAlignment)m_TextureImporterSettings.spriteAlignment;
spriteSheet.pivot = m_TextureImporterSettings.spritePivot;
psdLayers[i].spriteName = GetUniqueName(psdLayers[i].name, spriteNameHash);
psdLayers[i].spriteName = GetUniqueSpriteName(psdLayers[i].name, spriteNameHash);
spriteSheet.name = psdLayers[i].spriteName;
}
else if (spriteSheet != null)
Expand Down Expand Up @@ -542,9 +552,16 @@ void RegisterAssets(AssetImportContext ctx, TextureGenerationOutput output)
throw new Exception("Texture import fail");
}

var assetName = GetUniqueName(System.IO.Path.GetFileNameWithoutExtension(ctx.assetPath), assetNameHash, true);
// Setup all fixed name on the hash table
if (string.IsNullOrEmpty(m_TextureAssetName))
m_TextureAssetName = GetUniqueName(System.IO.Path.GetFileNameWithoutExtension(ctx.assetPath), assetNameHash, true);
output.texture.name = m_TextureAssetName;
m_TextureAssetName = GetUniqueName(string.Format("{0} Texture",assetName), assetNameHash, true);
if (string.IsNullOrEmpty(m_PrefabAssetName))
m_PrefabAssetName = GetUniqueName(string.Format("{0} Prefab", assetName), assetNameHash, true);
if (string.IsNullOrEmpty(m_SpriteLibAssetName))
m_SpriteLibAssetName = GetUniqueName(string.Format("{0} Sprite Lib", assetName), assetNameHash, true);

output.texture.name = assetName;
ctx.AddObjectToAsset(m_TextureAssetName, output.texture, output.thumbNail);
UnityEngine.Object mainAsset = output.texture;

Expand All @@ -562,9 +579,6 @@ void RegisterAssets(AssetImportContext ctx, TextureGenerationOutput output)
prefab = OnProducePrefab(m_TextureAssetName, output.sprites, slAsset);
if (prefab != null)
{
if (string.IsNullOrEmpty(m_PrefabAssetName))
m_PrefabAssetName = GetUniqueName(prefab.name, assetNameHash, true, prefab);

ctx.AddObjectToAsset(m_PrefabAssetName, prefab);
mainAsset = prefab;
}
Expand All @@ -578,8 +592,7 @@ void RegisterAssets(AssetImportContext ctx, TextureGenerationOutput output)

if (slAsset != null)
{
if (string.IsNullOrEmpty(m_SpriteLibAssetName))
m_SpriteLibAssetName = GetUniqueName(slAsset.name, assetNameHash, true, slAsset);
slAsset.name = assetName;
ctx.AddObjectToAsset(m_SpriteLibAssetName, slAsset);
}
}
Expand Down
23 changes: 15 additions & 8 deletions Editor/PSDImporterDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Texture2D GetReadableTexture2D()
{
m_ReadableTexture = InternalEditorBridge.CreateTemporaryDuplicate(texture, texture.width, texture.height);
if (m_ReadableTexture != null)
m_ReadableTexture.filterMode = FilterMode.Point;
m_ReadableTexture.filterMode = texture.filterMode;
}
return m_ReadableTexture;
}
Expand Down Expand Up @@ -211,11 +211,19 @@ int ParentGroupInFlatten(int parentIndex, List<PSDLayer> psdLayers)
public CharacterData GetCharacterData()
{
var psdLayers = dataProvider.GetPSDLayers();
var groups = psdLayers.Where(x => x.isGroup).Select(y => new CharacterGroup()
var groups = new List<CharacterGroup>();
for (int i = 0; i < psdLayers.Count; ++i)
{
name = y.name,
parentGroup = ParentGroupInFlatten(y.parentIndex, psdLayers)
}).ToArray();
if (psdLayers[i].isGroup)
{
groups.Add(new CharacterGroup()
{
name = psdLayers[i].name,
parentGroup = ParentGroupInFlatten(psdLayers[i].parentIndex, psdLayers),
order = i
});
}
}

var cd = dataProvider.characterData;
var parts = cd.parts == null ? new List<CharacterPart>() : cd.parts.ToList();
Expand All @@ -226,6 +234,7 @@ public CharacterData GetCharacterData()
var srIndex = parts.FindIndex(x => new GUID(x.spriteId) == spriteMetaData.spriteID);
CharacterPart cp = srIndex == -1 ? new CharacterPart() : parts[srIndex];
cp.spriteId = spriteMetaData.spriteID.ToString();
cp.order = psdLayers.FindIndex(l => l.spriteID == spriteMetaData.spriteID);
cp.spritePosition = new RectInt();
var uvTransform = spriteMetaData.uvTransform;
var outlineOffset = new Vector2(spriteMetaData.rect.x - uvTransform.x, spriteMetaData.rect.y - uvTransform.y);
Expand All @@ -249,9 +258,7 @@ public CharacterData GetCharacterData()
var layers = dataProvider.GetPSDLayers();
parts.Sort((x, y) =>
{
var xIndex = layers.FindIndex(l => l.spriteID == new GUID(x.spriteId));
var yIndex = layers.FindIndex(l => l.spriteID == new GUID(y.spriteId));
return xIndex.CompareTo(yIndex);
return x.order.CompareTo(y.order);
});

parts.Reverse();
Expand Down
35 changes: 34 additions & 1 deletion Editor/PSDImporterEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ internal class PSDImporterEditor : ScriptedImporterEditor
SerializedProperty m_DocumentAlignment;
SerializedProperty m_GenerateGOHierarchy;
SerializedProperty m_PaperDollMode;
SerializedProperty m_KeepDupilcateSpriteName;

readonly int[] m_FilterModeOptions = (int[])(Enum.GetValues(typeof(FilterMode)));

bool m_IsPOT = false;
bool m_ShowAdvanced = false;
bool m_ShowExperimental = false;
Dictionary<TextureImporterType, Action[]> m_AdvanceInspectorGUI = new Dictionary<TextureImporterType, Action[]>();
int m_PlatformSettingsIndex;
bool m_ShowPerAxisWrapModes = false;
Expand All @@ -71,6 +73,7 @@ public override void OnEnable()
m_DocumentAlignment = serializedObject.FindProperty("m_DocumentAlignment");
m_GenerateGOHierarchy = serializedObject.FindProperty("m_GenerateGOHierarchy");
m_PaperDollMode = serializedObject.FindProperty("m_PaperDollMode");
m_KeepDupilcateSpriteName = serializedObject.FindProperty("m_KeepDupilcateSpriteName");

var textureImporterSettingsSP = serializedObject.FindProperty("m_TextureImporterSettings");
m_TextureType = textureImporterSettingsSP.FindPropertyRelative("m_TextureType");
Expand Down Expand Up @@ -596,7 +599,6 @@ void DoSpriteInspector()
if (m_SpriteMode.intValue == (int)SpriteImportMode.Multiple && !m_SpriteMode.hasMultipleDifferentValues)
{
EditorGUILayout.PropertyField(m_MosaicLayers, s_Styles.mosaicLayers);

using (new EditorGUI.DisabledScope(!m_MosaicLayers.boolValue))
{
EditorGUILayout.PropertyField(m_CharacterMode, s_Styles.characterMode);
Expand All @@ -621,6 +623,13 @@ void DoSpriteInspector()
EditorGUILayout.HelpBox(s_Styles.resliceFromLayerWarning.text, MessageType.Info, true);
}
}
m_ShowExperimental = EditorGUILayout.Foldout(m_ShowExperimental, s_Styles.experimental, true);
if (m_ShowExperimental)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_KeepDupilcateSpriteName, s_Styles.keepDuplicateSpriteName);
EditorGUI.indentLevel--;
}
}

using (new EditorGUI.DisabledScope(targets.Length != 1))
Expand Down Expand Up @@ -753,6 +762,28 @@ void EnumPopup(SerializedProperty property, System.Type type, GUIContent label)
System.Enum.GetValues(type) as int[]);
}

void ExportMosaicTexture()
{
var assetPath = ((AssetImporter)target).assetPath;
var texture2D = AssetDatabase.LoadAssetAtPath<Texture2D>(assetPath);
if (texture2D == null)
return;
if (!texture2D.isReadable)
texture2D = InternalEditorBridge.CreateTemporaryDuplicate(texture2D, texture2D.width, texture2D.height);
var pixelData = texture2D.GetPixels();
texture2D = new Texture2D(texture2D.width, texture2D.height);
texture2D.SetPixels(pixelData);
texture2D.Apply();
byte[] bytes = texture2D.EncodeToPNG();
var fileName = Path.GetFileNameWithoutExtension(assetPath);
var filePath = Path.GetDirectoryName(assetPath);
var savePath = Path.Combine(filePath, fileName + ".png");
File.WriteAllBytes(savePath, bytes);
AssetDatabase.Refresh();
}

public override bool showImportedObject { get => false; }

internal class Styles
{
public readonly GUIContent textureTypeTitle = new GUIContent("Texture Type", "What will this texture be used for?");
Expand Down Expand Up @@ -908,6 +939,8 @@ internal class Styles
public readonly GUIContent generateGOHierarchy = new GUIContent(L10n.Tr("Use Layer Grouping"), L10n.Tr("GameObjects are grouped according to source file layer grouping"));
public readonly GUIContent resliceFromLayer = new GUIContent(L10n.Tr("Reslice"), L10n.Tr("Recreate Sprite rects from file"));
public readonly GUIContent paperDollMode = new GUIContent(L10n.Tr("Paper Doll Mode"), L10n.Tr("Special mode to generate a Prefab for Paper Doll use case"));
public readonly GUIContent experimental = new GUIContent(L10n.Tr("Experimental"));
public readonly GUIContent keepDuplicateSpriteName = new GUIContent(L10n.Tr("Keep Duplicate Name"), L10n.Tr("Keep Sprite name same as Layer Name even if there are duplicated Layer Name"));

public Styles()
{
Expand Down
43 changes: 43 additions & 0 deletions Editor/TexturePlatformSettingsModal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ internal static class TexturePlatformSettingsModal
TextureImporterFormat.ETC2_RGB4,
TextureImporterFormat.ETC2_RGB4_PUNCHTHROUGH_ALPHA,
TextureImporterFormat.ETC2_RGBA8,
#if UNITY_2019_1_OR_NEWER
TextureImporterFormat.ASTC_4x4,
TextureImporterFormat.ASTC_5x5,
TextureImporterFormat.ASTC_6x6,
TextureImporterFormat.ASTC_8x8,
TextureImporterFormat.ASTC_10x10,
TextureImporterFormat.ASTC_12x12,
#else
TextureImporterFormat.ASTC_RGB_4x4,
TextureImporterFormat.ASTC_RGB_5x5,
TextureImporterFormat.ASTC_RGB_6x6,
Expand All @@ -26,6 +34,7 @@ internal static class TexturePlatformSettingsModal
TextureImporterFormat.ASTC_RGBA_8x8,
TextureImporterFormat.ASTC_RGBA_10x10,
TextureImporterFormat.ASTC_RGBA_12x12
#endif
};

public struct BuildPlatformData
Expand Down Expand Up @@ -93,6 +102,14 @@ public struct BuildPlatformData
(int)TextureImporterFormat.PVRTC_RGB4,
(int)TextureImporterFormat.PVRTC_RGBA4,

#if UNITY_2019_1_OR_NEWER
(int)TextureImporterFormat.ASTC_4x4,
(int)TextureImporterFormat.ASTC_5x5,
(int)TextureImporterFormat.ASTC_6x6,
(int)TextureImporterFormat.ASTC_8x8,
(int)TextureImporterFormat.ASTC_10x10,
(int)TextureImporterFormat.ASTC_12x12,
#else
(int)TextureImporterFormat.ASTC_RGB_4x4,
(int)TextureImporterFormat.ASTC_RGB_5x5,
(int)TextureImporterFormat.ASTC_RGB_6x6,
Expand All @@ -105,6 +122,7 @@ public struct BuildPlatformData
(int)TextureImporterFormat.ASTC_RGBA_8x8,
(int)TextureImporterFormat.ASTC_RGBA_10x10,
(int)TextureImporterFormat.ASTC_RGBA_12x12,
#endif

(int)TextureImporterFormat.RGB16,
(int)TextureImporterFormat.RGB24,
Expand Down Expand Up @@ -137,6 +155,14 @@ public struct BuildPlatformData
(int)TextureImporterFormat.ETC_RGB4,
(int)TextureImporterFormat.ETC2_RGBA8,

#if UNITY_2019_1_OR_NEWER
(int)TextureImporterFormat.ASTC_4x4,
(int)TextureImporterFormat.ASTC_5x5,
(int)TextureImporterFormat.ASTC_6x6,
(int)TextureImporterFormat.ASTC_8x8,
(int)TextureImporterFormat.ASTC_10x10,
(int)TextureImporterFormat.ASTC_12x12,
#else
(int)TextureImporterFormat.ASTC_RGB_4x4,
(int)TextureImporterFormat.ASTC_RGB_5x5,
(int)TextureImporterFormat.ASTC_RGB_6x6,
Expand All @@ -149,6 +175,7 @@ public struct BuildPlatformData
(int)TextureImporterFormat.ASTC_RGBA_8x8,
(int)TextureImporterFormat.ASTC_RGBA_10x10,
(int)TextureImporterFormat.ASTC_RGBA_12x12,
#endif

(int)TextureImporterFormat.RGB16,
(int)TextureImporterFormat.RGB24,
Expand Down Expand Up @@ -306,6 +333,21 @@ static string GetTextureFormatString(TextureImporterFormat format)
return "RGB + 1-bit Alpha Compressed ETC2 4 bits";
case TextureImporterFormat.ETC2_RGBA8:
return "RGBA Compressed ETC2 8 bits";

#if UNITY_2019_1_OR_NEWER
case TextureImporterFormat.ASTC_4x4:
return "RGB(A) Compressed ASTC 4 x 4 block";
case TextureImporterFormat.ASTC_5x5:
return "RGB(A) Compressed ASTC 5 x 5 block";
case TextureImporterFormat.ASTC_6x6:
return "RGB(A) Compressed ASTC 6 x 6 block";
case TextureImporterFormat.ASTC_8x8:
return "RGB(A) Compressed ASTC 8 x 8 block";
case TextureImporterFormat.ASTC_10x10:
return "RGB(A) Compressed ASTC 10 x 10 block";
case TextureImporterFormat.ASTC_12x12:
return "RGB(A) Compressed ASTC 12 x 12 block";
#else
case TextureImporterFormat.ASTC_RGB_4x4:
return "RGB Compressed ASTC 4 x 4 block";
case TextureImporterFormat.ASTC_RGB_5x5:
Expand All @@ -330,6 +372,7 @@ static string GetTextureFormatString(TextureImporterFormat format)
return "RGBA Compressed ASTC 10 x 10 block";
case TextureImporterFormat.ASTC_RGBA_12x12:
return "RGBA Compressed ASTC 12 x 12 block";
#endif
}
return "Unsupported";
}
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.unity.2d.psdimporter",
"version": "1.2.0-preview.3",
"version": "1.2.0-preview.4",
"unity": "2019.2",
"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 2D Animation v2.",
Expand All @@ -11,14 +11,14 @@
],
"category": "2D",
"dependencies": {
"com.unity.2d.animation": "3.0.0-preview.1",
"com.unity.2d.common": "1.2.0-preview.1",
"com.unity.2d.animation": "2.2.0-preview.4",
"com.unity.2d.sprite": "1.0.0",
"com.unity.test-framework": "1.0.9"
},
"repository": {
"type": "git",
"url": "[email protected]:unity/2d.git",
"revision": "7839cbdf328aa994f0d64eac8162c219aee1a47b"
"revision": "c3111e990155cb61bd3b7c21871a813208c3b669"
}
}

0 comments on commit 150faf4

Please sign in to comment.