Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
## [1.0.0-preview.2] - 2019-01-25
### Added
- Fix unable to rig Sprites created manually
- Remove legacy packing tag
- Default Texture Type is changed to 'Sprite (2D and UI)'
- Default Sprite Mode is changed to 'Multiple'
  • Loading branch information
Unity Technologies committed Jan 24, 2019
1 parent 390217a commit fbd0b6b
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 82 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ 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.0.0-preview.2] - 2019-01-25
### Added
- Fix unable to rig Sprites created manually
- Remove legacy packing tag
- Default Texture Type is changed to 'Sprite (2D and UI)'
- Default Sprite Mode is changed to 'Multiple'

## [1.0.0-preview.1] - 2018-11-20
### Added
- New release
Expand Down
13 changes: 6 additions & 7 deletions Documentation~/PSDImporter.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The following Photoshop features are **not** supported by the PSD Importer **:**

### Texture Type - Default

This is the default **Texture Type** when an image is imported without a specific Texture Type selected. Refer to the documentation on [Texture Types](https://docs.unity3d.com/Manual/TextureTypes.html) for further information and details.
This is the default **Texture Type** usage when an image is imported without a specific Texture Type selected. Refer to the documentation on [Texture Types](https://docs.unity3d.com/Manual/TextureTypes.html) for further information and details.

### Texture Type - Sprite (2D and UI)

Expand All @@ -41,10 +41,9 @@ Property settings that are specific to the **PSD Importer** are marked by an *.
| Property | Function |
| ------------------------------- | ------------------------------------------------------------ |
| __Texture Type__ | Select __Sprite (2D and UI)__ to import the Texture as a [Sprite](https://docs.unity3d.com/Manual/Sprites.html). This is required to begin using the imported images with the 2D Animation V2 package. |
| __Sprite Mode__ | Use this setting to specify how the the Sprite graphic is extracted from the image. The default for this option is **Single**. |
| __Sprite Mode__ | Use this setting to specify how the the Sprite graphic is extracted from the image. The default for this option is **Multiple**. |
| Single | Select this option if there is only a single element in the imported image. |
| Multiple | Select this option if there are multiple elements in the imported image. Select this option when importing a character meant for animation with the 2D Animation V2 package. |
| __Packing Tag__ | Specify a __Sprite Atlas__ by name, where the Texture into using the legacy Sprite Packer packing tag. |
| __Pixels Per Unit__ | The number of pixels that equal 1 Unity unit. |
| __Mesh Type__ | This defines the __Mesh__ type that is generated for the __Sprite__. The default for this option is 'Tight'. |
| Full Rect | The Sprite is mapped onto a mesh generated as a quad. |
Expand All @@ -53,7 +52,7 @@ Property settings that are specific to the **PSD Importer** are marked by an *.
| * [Import Hidden](#ImportHidde) | Select this property to specify that hidden layers in the PSB file should be imported. Clear this option to not import the hidden layers. |
| * [Mosaic](#Mosaic) | This option is only available if Texture Type is set to ‘Multiple’. Enable this to allow Unity to create a Sprite from each imported layer and arrange them into a Sprite Sheet layout. |
| * [Character Rig](#CharRig) | Select the imported image(s) is to be used for a multi-Sprite character. When selected, a Prefab containing the imported images is generated. |
| * [Use Folder Grouping](#Hierarchy) | Select to have the generated Prefab mimic the layer hierarchy of the imported PSB file. |
| * [Use Layer Grouping](#Hierarchy) | Select to have the generated Prefab mimic the layer hierarchy of the imported PSB file. |
| __Pivot__ | Select the pivot point of the Sprite from the dropdown menu options. |
| Custom | Define the X and Y coordinates of a custom __Pivot__ location. |
| * [Reslice](#Reslice) | Available only when __Mosaic__ is enabled.<br />Select this to clear away all previous Sprite metadata and recreate the Sprite from the imported PSB layers. |
Expand All @@ -70,7 +69,7 @@ The 4 sets are created by enabling the following property combinations:

3. Sprite Mode: Multiple + Mosaic

4. Sprite Mode: Multiple + Mosaic + Character Rig**
4. Sprite Mode: Multiple + Mosaic + Character Rig

#### User defined SpriteRect

Expand Down Expand Up @@ -113,7 +112,7 @@ When **Mosaic** is selected, all layers in the PSB file will be imported as sepa

When this is selected, a Prefab is generated containing a Sprite GameObject with the SpriteRenderer component. If the Sprite contains bone and skin data, the **Sprite Skin** component is added as well. The name of the GameObject is the same as the name specified in it's SpriteRect.

### Use Folder Grouping<a name="Hierarchy"></a>
### Use Layer Grouping<a name="Hierarchy"></a>

When this is selected, the generated GameObjects mimic the layer grouping in the imported file. When the Asset hierarchy is modified, it is reflected on the next import.

Expand All @@ -125,7 +124,7 @@ When this is selected, all user modification is discarded and SpriteRects are re

A name collision can occur in the following ways:

1. 2 or more layers in the Asset has the same name. This does not affect Photoshop folder name.
1. 2 or more layers in the Asset has the same name. This does not affect Photoshop group name.

2. A new layer created in the Asset has the same name as a user created SpriteRect.

Expand Down
35 changes: 19 additions & 16 deletions Editor/PSDImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ public int textureActualHeight
[SerializeField]
BoneGO[] m_BoneGOs;

[SerializeField]
bool m_FirstCreate = true;

[SerializeField]
bool m_GenerateGOHierarchy = false;

Expand Down Expand Up @@ -150,12 +147,6 @@ public override void OnImportAsset(AssetImportContext ctx)
if (ext != ".psb")
throw new Exception("File does not have psb extension");

if (m_FirstCreate)
{
m_TextureImporterSettings.textureType = EditorSettings.defaultBehaviorMode == EditorBehaviorMode.Mode2D ? TextureImporterType.Sprite : TextureImporterType.Default;
m_FirstCreate = false;
}

m_BoneGOs = null;

FileStream fileStream = new FileStream(ctx.assetPath, FileMode.Open, FileAccess.Read);
Expand Down Expand Up @@ -202,8 +193,8 @@ public override void OnImportAsset(AssetImportContext ctx)
if (spriteImportData.Count <= 0 || spriteImportData[0] == null)
{
spriteImportData.Add(new SpriteMetaData());
spriteImportData[0].name = System.IO.Path.GetFileNameWithoutExtension(ctx.assetPath);
}
spriteImportData[0].name = System.IO.Path.GetFileNameWithoutExtension(ctx.assetPath) +"_1";
spriteImportData[0].alignment = (SpriteAlignment)m_TextureImporterSettings.spriteAlignment;
spriteImportData[0].border = m_TextureImporterSettings.spriteBorder;
spriteImportData[0].pivot = m_TextureImporterSettings.spritePivot;
Expand Down Expand Up @@ -413,6 +404,8 @@ void ImportFromLayers(AssetImportContext ctx, Document doc)
foreach (var spriteData in spriteImportData)
{
var psdLayer = psdLayers.FirstOrDefault(x => x.spriteID == spriteData.spriteID);
if (psdLayer == null)
spriteData.uvTransform = new Vector2Int((int)spriteData.rect.position.x, (int)spriteData.rect.position.y);
// If it is user created rect or the name has been changed before
// add it into the spriteNameHash and we don't copy it over from the layer
if (psdLayer == null || psdLayer.spriteName != spriteData.name)
Expand Down Expand Up @@ -503,6 +496,7 @@ public TextureImporterPlatformSettings GetPlatformTextureSettings(BuildTarget bu

void RegisterAssets(AssetImportContext ctx, TextureGenerationOutput output)
{
List<int> assetNameHash = new List<int>();
if (!string.IsNullOrEmpty(output.importInspectorWarnings))
{
Debug.LogWarning(output.importInspectorWarnings);
Expand All @@ -518,21 +512,28 @@ void RegisterAssets(AssetImportContext ctx, TextureGenerationOutput output)
{
throw new Exception("Texture import fail");
}
var assetName = System.IO.Path.GetFileNameWithoutExtension(ctx.assetPath);
var assetName = GetUniqueName(System.IO.Path.GetFileNameWithoutExtension(ctx.assetPath), assetNameHash, true);
output.texture.name = assetName;
ctx.AddObjectToAsset(assetName, output.texture, output.thumbNail);
UnityEngine.Object mainAsset = output.texture;


if (output.sprites != null)
{
foreach (var s in output.sprites)
ctx.AddObjectToAsset(s.name, s);
{
assetName = GetUniqueName(s.name, assetNameHash, true, s);
ctx.AddObjectToAsset(assetName, s);
}


if (shouldProduceGameObject)
{
var prefab = OnProducePrefab(assetName, output.sprites);
if (prefab != null)
{
ctx.AddObjectToAsset(prefab.name, prefab);
assetName = GetUniqueName(prefab.name, assetNameHash, true, prefab);
ctx.AddObjectToAsset(assetName, prefab);
mainAsset = prefab;
}
}
Expand Down Expand Up @@ -684,7 +685,7 @@ GameObject OnProducePrefab(string assetname, Sprite[] sprites)
spriteRenderer.sortingOrder = psdLayers.Count - i;
var uvTransform = spriteMetaData.uvTransform;
var outlineOffset = new Vector2(spriteMetaData.rect.x - uvTransform.x + (spriteMetaData.pivot.x * spriteMetaData.rect.width),
spriteMetaData.rect.y - uvTransform.y + (spriteMetaData.pivot.y * spriteMetaData.rect.height)) * definitionScale / sprite.pixelsPerUnit;
spriteMetaData.rect.y - uvTransform.y + (spriteMetaData.pivot.y * spriteMetaData.rect.height)) * definitionScale / sprite.pixelsPerUnit;
l.gameObject.transform.position = new Vector3(outlineOffset.x, outlineOffset.y, 0);

if (characterSkeleton != null)
Expand Down Expand Up @@ -803,7 +804,7 @@ static string SanitizeName(string name)
return name;
}

static string GetUniqueName(string name, List<int> stringHash)
static string GetUniqueName(string name, List<int> stringHash, bool logNewNameGenerated = false, UnityEngine.Object context = null)
{
string uniqueName = string.Copy(SanitizeName(name));
int index = 1;
Expand All @@ -814,6 +815,8 @@ static string GetUniqueName(string name, List<int> stringHash)
if (!p.Any())
{
stringHash.Add(hash);
if (logNewNameGenerated && name != uniqueName)
Debug.Log(string.Format("Asset name {0} is changed to {1} to ensure uniqueness", name, uniqueName), context);
return uniqueName;
}
uniqueName = string.Format("{0}_{1}", name, index);
Expand Down Expand Up @@ -1047,7 +1050,7 @@ internal void PostProcessPrefab(GameObject go)
var spriteSkin = go.GetComponent<SpriteSkin>();
if (spriteSkin != null)
{
var spriteBones = m_CharacterData.parts.FirstOrDefault(x => new GUID(x.spriteId) == sr.sprite.GetSpriteID()).bones.Select(x => m_BoneGOs[x]);
var spriteBones = m_CharacterData.parts.FirstOrDefault(x => new GUID(x.spriteId) == sr.sprite.GetSpriteID()).bones.Where(x => x >= 0 && x < m_BoneGOs.Length).Select(x => m_BoneGOs[x]);
if (spriteBones.Any())
{
spriteSkin.rootBone = spriteBones.OrderBy(x => x.index).First().go.transform;
Expand Down
5 changes: 1 addition & 4 deletions Editor/PSDImporterEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class PSDImporterEditor : ScriptedImporterEditor
SerializedProperty m_TextureType;
SerializedProperty m_TextureShape;
SerializedProperty m_SpriteMode;
SerializedProperty m_SpritePackingTag;
SerializedProperty m_SpritePixelsToUnits;
SerializedProperty m_SpriteMeshType;
SerializedProperty m_SpriteExtrude;
Expand Down Expand Up @@ -61,7 +60,6 @@ public class PSDImporterEditor : ScriptedImporterEditor
TexturePlatformSettingsController m_TexturePlatformSettingsController = new TexturePlatformSettingsController();
public override void OnEnable()
{
m_SpritePackingTag = serializedObject.FindProperty("m_SpritePackingTag");
m_MosaicLayers = serializedObject.FindProperty("m_MosaicLayers");
m_ImportHiddenLayers = serializedObject.FindProperty("m_ImportHiddenLayers");
m_ResliceFromLayer = serializedObject.FindProperty("m_ResliceFromLayer");
Expand Down Expand Up @@ -567,7 +565,6 @@ void DoSpriteInspector()
// Show generic attributes
if (m_SpriteMode.intValue != 0)
{
EditorGUILayout.PropertyField(m_SpritePackingTag, s_Styles.spritePackingTag);
EditorGUILayout.PropertyField(m_SpritePixelsToUnits, s_Styles.spritePixelsPerUnit);

if (m_SpriteMode.intValue != (int)SpriteImportMode.Polygon && !m_SpriteMode.hasMultipleDifferentValues)
Expand Down Expand Up @@ -865,7 +862,7 @@ internal class Styles
public readonly GUIContent applyButtonLabel = new GUIContent("Apply");
public readonly GUIContent revertButtonLabel = new GUIContent("Revert");
public readonly GUIContent spriteEditorButtonLabel = new GUIContent("Sprite Editor");
public readonly GUIContent resliceFromLayerWarning = new GUIContent("This will reinitialized and recreate all Sprites based on the file's layer. Existing Sprite metadata for previous generated Sprite will be copied over.");
public readonly GUIContent resliceFromLayerWarning = new GUIContent("This will reinitialize and recreate all Sprites based on the file’s layer data. Existing Sprite metadata from previously generated Sprites are copied over.");
public readonly GUIContent alphaIsTransparency = new GUIContent("Alpha Is Transparency", "If the provided alpha channel is transparency, enable this to pre-filter the color to avoid texture filtering artifacts. This is not supported for HDR textures.");
public readonly GUIContent etc1Compression = new GUIContent("Compress using ETC1 (split alpha channel)|Alpha for this texture will be preserved by splitting the alpha channel to another texture, and both resulting textures will be compressed using ETC1.");
public readonly GUIContent crunchedCompression = new GUIContent("Use Crunch Compression", "Texture is crunch-compressed to save space on disk when applicable.");
Expand Down
2 changes: 1 addition & 1 deletion Editor/PSDPlugin/PsdFile/Layers/Layer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public Layer(PsdBinaryReader reader, PsdFile psdFile)
{
var layerInfo = LayerInfoFactory.Load(reader,
psdFile: this.PsdFile,
globalLayerInfo: false);
globalLayerInfo: false, adjustmentLayerEndPos);
AdditionalInfo.Add(layerInfo);
}

Expand Down
Loading

0 comments on commit fbd0b6b

Please sign in to comment.