Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
## [6.0.6] - 2022-09-07
### Fixed
- Improved import speed and memory allocation for psd/psb files by reducing the intermediate texture buffers.
- Fixed an editor freeze caused by over allocating intermediate texture buffers. (Case DANB-140)
- Fixed an issue where some layers would become invisible when merging multiple layers together. (Case DANB-131)
- Fixed exception when showing PSDImporter inspector. (DANB-198)
  • Loading branch information
Unity Technologies committed Sep 7, 2022
1 parent 649b822 commit f1a2fb3
Show file tree
Hide file tree
Showing 22 changed files with 2,330 additions and 569 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Changelog
## [6.0.6] - 2022-09-07
### Fixed
- Improved import speed and memory allocation for psd/psb files by reducing the intermediate texture buffers.
- Fixed an editor freeze caused by over allocating intermediate texture buffers. (Case DANB-140)
- Fixed an issue where some layers would become invisible when merging multiple layers together. (Case DANB-131)
- Fixed exception when showing PSDImporter inspector. (DANB-198)

## [6.0.5] - 2022-07-21
### Changed
Expand Down
25 changes: 24 additions & 1 deletion Editor/ImportUtilites.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
using Unity.Collections;
using UnityEngine;

namespace UnityEditor.U2D.PSD
Expand Down Expand Up @@ -87,4 +87,27 @@ public GameObject CreateGameObject(string name, params System.Type[] components)
}
}

internal static class ImportUtilities
{
public static string SaveToPng(NativeArray<Color32> buffer, int width, int height)
{
if (!buffer.IsCreated ||
buffer.Length == 0 ||
width == 0 ||
height == 0)
return "No .png generated.";

var texture2D = new Texture2D(width, height);
texture2D.SetPixels32(buffer.ToArray());
var png = texture2D.EncodeToPNG();
var path = Application.dataPath + $"/tex_{System.Guid.NewGuid().ToString()}.png";
var fileStream = System.IO.File.Create(path);
fileStream.Write(png);
fileStream.Close();

UnityEngine.Object.DestroyImmediate(texture2D);

return path;
}
}
}
66 changes: 50 additions & 16 deletions Editor/PSDImportData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

namespace UnityEditor.U2D.PSD
{
/// <summary>
/// Custom hidden asset to store meta information of the last import state
/// </summary>
internal class PSDImportData : ScriptableObject
{
[SerializeField]
Expand All @@ -16,7 +19,7 @@ public int importedTextureWidth
}

[SerializeField]
public int m_ImportedTextureHeight;
int m_ImportedTextureHeight;
public int importedTextureHeight
{
get => m_ImportedTextureHeight;
Expand Down Expand Up @@ -88,21 +91,42 @@ internal struct BoneGO
public GameObject go;
public int index;
}

internal class FlattenLayerData: IPSDLayerMappingStrategyComparable
{
public int layerID { get; set; }
public string name { get; set;}
public bool isGroup => true;
}

[Serializable]
class PSDLayerImportSetting
class PSDLayerImportSetting: IPSDLayerMappingStrategyComparable
{
[SerializeField]
string m_SpriteId;
GUID m_SpriteIDGUID;

public string name;
public int layerId;
public bool flatten;
public bool isGroup;

public int layerID => layerId;
string IPSDLayerMappingStrategyComparable.name => name;
bool IPSDLayerMappingStrategyComparable.isGroup => isGroup;

public GUID spriteId
{
get
{
if (string.IsNullOrEmpty(m_SpriteId))
{
m_SpriteIDGUID = GUID.Generate();
m_SpriteId = m_SpriteIDGUID.ToString();
}

return m_SpriteIDGUID;

}
set
{
m_SpriteIDGUID = value;
m_SpriteId = m_SpriteIDGUID.ToString();
}
}
}

[Serializable]
Expand Down Expand Up @@ -147,14 +171,24 @@ public bool isGroup
get => m_IsGroup;
set => m_IsGroup = value;
}

[SerializeField]
bool m_IsImported;
public bool isImported
{
get => m_IsImported;
set => m_IsImported = value;
}
}


[Serializable]
struct SpriteLayerMapping
/// <summary>
/// Data for extracting layers and colors from PSD
/// </summary>
class PSDExtractLayerData
{
public string spriteId;
public int layerId;
public string layerName;
public BitmapLayer bitmapLayer;
public PSDLayerImportSetting importSetting;
public PSDExtractLayerData[] children;
}
}

}
Loading

0 comments on commit f1a2fb3

Please sign in to comment.