Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
## [9.0.0] - 2023-02-23
### Fixed
- Fixed an issue where warning logs in the console would get cut short due to invalid characters in layer names.
  • Loading branch information
Unity Technologies committed Feb 23, 2023
1 parent a8904de commit a5f3ece
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 26 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [9.0.0] - 2023-02-23
### Fixed
- Fixed an issue where warning logs in the console would get cut short due to invalid characters in layer names.

## [9.0.0-pre.2] - 2022-11-30
### Fixed
- Enabled the ability to select mipmap streaming for textures imported with the PSD Importer.
Expand Down
4 changes: 2 additions & 2 deletions Documentation~/PSD-importer-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ The Settings tab allows you to customize how the PSD Importer imports a file. Th
</tr>
<tr>
<td rowspan="1"><strong>Extrude Edges</strong></td>
<td colspan="2">Select <a href="https://docs.unity3d.com/Manual/TextureTypes.html#Sprite"> Sprite (2D and UI)</a> to import the Texture as a <a href="https://docs.unity3d.com/Manual/Sprites.html">Sprite</a>. The is required to begin using the imported Texture with the <a href="https://docs.unity3d.com/Packages/com.unity.2d.animation@latest/">2D Animation</a> package.</td>
<td colspan="2">Use the slider to determine how much to extend the Mesh from the edge of the Sprite.</td>
</tr>
<tr>
<td rowspan="1"><strong>Generate Physics Shape</strong></td>
<td colspan="2">Select <a href="https://docs.unity3d.com/Manual/TextureTypes.html#Sprite"> Sprite (2D and UI)</a> to import the Texture as a <a href="https://docs.unity3d.com/Manual/Sprites.html">Sprite</a>. The is required to begin using the imported Texture with the <a href="https://docs.unity3d.com/Packages/com.unity.2d.animation@latest/">2D Animation</a> package.</td>
<td colspan="2">Enable this option to generate a default [Physics Shape](https://docs.unity3d.com/2017.4/Documentation/Manual/SpritePhysicsShapeEditor.html) from the outline of the Sprite, if a [Custom Physics Shape](https://docs.unity3d.com/Manual/CustomPhysicsShape.html) has not be defined</td>
</tr>
<tr>
<td rowspan="1"><strong><a href="#automatic-reslice">Automatic Reslice</a></strong></td>
Expand Down
33 changes: 17 additions & 16 deletions Editor/ImportUtilites.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,31 @@ public string GetUniqueName(string name, bool logNewNameGenerated = false, Unity
static string GetUniqueName(string name, HashSet<int> stringHash, bool logNewNameGenerated = false, UnityEngine.Object context = null)
{
var sanitizedName = string.Copy(SanitizeName(name));
string uniqueName = sanitizedName;
int index = 1;
var uniqueName = sanitizedName;
var index = 1;
while (true)
{
var hash = GetStringHash(uniqueName);
if (!stringHash.Contains(hash))
{
stringHash.Add(hash);
if (logNewNameGenerated && sanitizedName != uniqueName)
Debug.Log(string.Format("Asset name {0} is changed to {1} to ensure uniqueness", name, uniqueName), context);
Debug.Log($"Asset name {name} is changed to {uniqueName} to ensure uniqueness", context);
return uniqueName;
}
uniqueName = string.Format("{0}_{1}", sanitizedName, index);
uniqueName = $"{sanitizedName}_{index}";
++index;
}
}

static int GetStringHash(string str)
{
var md5Hasher = MD5.Create();
var hashed = md5Hasher.ComputeHash(Encoding.UTF8.GetBytes(str));
return BitConverter.ToInt32(hashed, 0);
}

static string SanitizeName(string name)
public static string SanitizeName(string name)
{
name = name.Replace('\0', ' ');
string newName = null;
Expand All @@ -69,18 +76,11 @@ static string SanitizeName(string name)

if (!string.IsNullOrEmpty(newName))
{
Debug.LogWarning(string.Format("File contains layer with invalid name for generating asset. {0} is renamed to {1}", name, newName));
Debug.LogWarning($"File contains layer with invalid name for generating asset. {name} is renamed to {newName}");
return newName;
}
return name;
}

static int GetStringHash(string str)
{
MD5 md5Hasher = MD5.Create();
var hashed = md5Hasher.ComputeHash(Encoding.UTF8.GetBytes(str));
return BitConverter.ToInt32(hashed, 0);
}
}
}

class GameObjectCreationFactory : UniqueNameGenerator
Expand Down Expand Up @@ -161,8 +161,9 @@ public static void ValidatePSDLayerId(IEnumerable<PSDLayer> oldPsdLayer, IEnumer

if (uniqueNameGenerator.ContainHash(childBitmapLayer.LayerID))
{
var importWarning = string.Format("Layer {0}: LayerId is not unique. Mapping will be done by Layer's name.", childBitmapLayer.Name);
var layerName = uniqueNameGenerator.GetUniqueName(childBitmapLayer.Name);
var layerName = UniqueNameGenerator.SanitizeName(childBitmapLayer.Name);
var importWarning = $"Layer {layerName}: LayerId is not unique. Mapping will be done by Layer's name.";
layerName = uniqueNameGenerator.GetUniqueName(layerName);
if (layerName != childBitmapLayer.Name)
importWarning += "\nLayer names are not unique. Please ensure they are unique to for SpriteRect to be mapped back correctly.";
childBitmapLayer.LayerID = layerName.GetHashCode();
Expand Down
6 changes: 3 additions & 3 deletions Editor/PSDImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ public override void OnImportAsset(AssetImportContext ctx)
}
catch (Exception e)
{
Debug.LogError($"Failed to import file {assetPath}. Ex:{e.Message}");
Debug.LogError($"Failed to import file {assetPath}. Error: {e.Message}\n{e.StackTrace}");
}
finally
{
Expand Down Expand Up @@ -1163,8 +1163,8 @@ GameObject OnProducePrefab(AssetImportContext ctx, string assetname, Sprite[] sp
var spriteBones = currentCharacterData.parts.FirstOrDefault(x => new GUID(x.spriteId) == spriteRenderer.sprite.GetSpriteID()).bones.Where(x => x >= 0 && x < boneGOs.Length).Select(x => boneGOs[x]);
if (spriteBones.Any())
{
spriteSkin.rootBone = root.transform;
spriteSkin.boneTransforms = spriteBones.Select(x => x.go.transform).ToArray();
spriteSkin.SetRootBone(root.transform);
spriteSkin.SetBoneTransforms(spriteBones.Select(x => x.go.transform).ToArray());
if (spriteSkin.isValid)
spriteSkin.CalculateBounds();
}
Expand Down
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.unity.2d.psdimporter",
"version": "9.0.0-pre.2",
"version": "9.0.0",
"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.",
Expand All @@ -11,19 +11,22 @@
],
"category": "2D",
"dependencies": {
"com.unity.2d.common": "9.0.0-pre.2",
"com.unity.2d.common": "9.0.0",
"com.unity.2d.sprite": "1.0.0"
},
"relatedPackages": {
"com.unity.2d.psdimporter.tests": "9.0.0-pre.2"
"com.unity.2d.psdimporter.tests": "9.0.0"
},
"_upm": {
"changelog": "### Fixed\n- Fixed an issue where warning logs in the console would get cut short due to invalid characters in layer names."
},
"upmCi": {
"footprint": "05c21630cde4e94d5822721b3889989b6ef9e4a4"
"footprint": "8f637153f11248fa2596796616076d6552ef5b49"
},
"documentationUrl": "https://docs.unity3d.com/Packages/[email protected]/manual/index.html",
"repository": {
"url": "https://github.cds.internal.unity3d.com/unity/2d.git",
"type": "git",
"revision": "754f72df4d3d05edbd6100a322f8cadb46ba5dab"
"revision": "921f93408bc912dafbc669a5d5ff55b7b04e7b3e"
}
}

0 comments on commit a5f3ece

Please sign in to comment.