Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
## [2.0.2] - 2019-07-13
### Changed
- Mark package to support Unity 2019.3.0a10 onwards.

## [2.0.1] - 2019-06-12
### Changed
- Update 2D Animation dependency

## [2.0.0] - 2019-06-17
### Changed
- Remove preview tag
- Remove experimental namespace
  • Loading branch information
Unity Technologies committed Jul 12, 2019
1 parent 82ef230 commit db14219
Show file tree
Hide file tree
Showing 70 changed files with 198 additions and 2,082 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@ 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).

## [2.0.2] - 2019-07-13
### Changed
- Mark package to support Unity 2019.3.0a10 onwards.

## [2.0.1] - 2019-06-12
### Changed
- Update 2D Animation dependency

## [2.0.0] - 2019-06-17
### Changed
- Remove preview tag
- Remove experimental namespace

## [1.2.0-preview.2] - 2019-06-07
### Added
- Change API to internal access
- Only generate Sprite Library Asset if there is entry
- Do not reset Reslice checkbox after Inspector apply

## [1.2.0-preview.1] - 2019-03-15
### Added
- Update support for 2019.2
Expand Down
4 changes: 0 additions & 4 deletions Documentation~/PSDImporter.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
---
typora-copy-images-to: images
---

# PSD Importer

## Summary
Expand Down
2 changes: 1 addition & 1 deletion Editor/Analytics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using UnityEngine;
using UnityEngine.Analytics;

namespace UnityEditor.Experimental.U2D.PSD
namespace UnityEditor.U2D.PSD
{
[Serializable]
internal struct PSDApplyEvent
Expand Down
2 changes: 1 addition & 1 deletion Editor/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("com.unity.2d.psdimporter.EditorTests")]
[assembly: InternalsVisibleTo("Unity.2D.Psdimporter.Tests.EditorTests")]
6 changes: 3 additions & 3 deletions Editor/PSDImportPostProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.U2D;
using UnityEditor.U2D.Sprites;
using UnityEngine;

namespace UnityEditor.Experimental.U2D.PSD
namespace UnityEditor.U2D.PSD
{
public class PSDImportPostProcessor : AssetPostprocessor
internal class PSDImportPostProcessor : AssetPostprocessor
{
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
Expand Down
88 changes: 50 additions & 38 deletions Editor/PSDImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@
using System.Collections.Generic;
using System.IO;
using PDNWrapper;
using UnityEditor.Experimental.AssetImporters;
using UnityEngine;
using Unity.Collections;
using System.Linq;
using UnityEditor.Experimental.U2D.Animation;
using UnityEditor.Experimental.U2D.Common;
using UnityEditor.Experimental.AssetImporters;
using UnityEditor.U2D.Animation;
using UnityEditor.U2D.Common;
using UnityEditor.U2D.Sprites;
using UnityEngine.Assertions;
using UnityEngine.Experimental.U2D;
using UnityEngine.Experimental.U2D.Animation;
using UnityEngine.U2D;
using UnityEngine.U2D.Animation;

namespace UnityEditor.Experimental.U2D.PSD
namespace UnityEditor.U2D.PSD
{
[ScriptedImporter(2, "psb")]
public class PSDImporter : ScriptedImporter, ISpriteEditorDataProvider, IAnimationAssetPostProcess
[ScriptedImporter(4, "psb")]
internal class PSDImporter : ScriptedImporter, ISpriteEditorDataProvider, IAnimationAssetPostProcess
{
class GameObjectCreationFactory
{
Expand Down Expand Up @@ -66,10 +67,10 @@ struct BoneGO
bool m_PaperDollMode = false;

[SerializeField]
SpriteLibrary m_SpriteLibrary = new SpriteLibrary() {categories = new List<SpriteLibCategory>()};
SpriteCategoryList m_SpriteCategoryList = new SpriteCategoryList() {categories = new List<SpriteCategory>()};
GameObjectCreationFactory m_GameObjectFactory = new GameObjectCreationFactory();

internal SpriteLibrary spriteLibrary { get { return m_SpriteLibrary; } set { m_SpriteLibrary = value; } }
internal SpriteCategoryList spriteCategoryList { get { return m_SpriteCategoryList; } set { m_SpriteCategoryList = value; } }

[SerializeField]
int m_TextureActualWidth;
Expand Down Expand Up @@ -484,7 +485,6 @@ void ImportFromLayers(AssetImportContext ctx, Document doc)
}
oldPsdLayers.Clear();
oldPsdLayers.AddRange(psdLayers);
m_ResliceFromLayer = false;
m_ImportedTextureHeight = textureActualHeight = height;
m_ImportedTextureWidth = textureActualWidth = width;
var generatedTexture = ImportTexture(ctx, output, width, height, 0, spriteImportData.Count);
Expand Down Expand Up @@ -590,11 +590,11 @@ void RegisterAssets(AssetImportContext ctx, TextureGenerationOutput output)
bool SpriteIsMainFromSpriteLib(string spriteId, out string categoryName)
{
categoryName = "";
if (m_SpriteLibrary.categories != null)
if (m_SpriteCategoryList.categories != null)
{
foreach (var category in m_SpriteLibrary.categories)
foreach (var category in m_SpriteCategoryList.categories)
{
var index = category.spriteIds.FindIndex(x => x == spriteId);
var index = category.labels.FindIndex(x => x.spriteId == spriteId);
if (index == 0)
{
categoryName = category.name;
Expand Down Expand Up @@ -735,16 +735,18 @@ BoneGO[] CreateBonesGO(Transform root)
return new BoneGO[0];
}

void GetSpriteLibEntry(string spriteId, out string category, out int index)
void GetSpriteLiblabel(string spriteId, out string category, out string label)
{
category = "";
index = -1;
foreach (var cat in m_SpriteLibrary.categories)
label = "";
var index = -1;
foreach (var cat in m_SpriteCategoryList.categories)
{
index = cat.spriteIds.FindIndex(x => x == spriteId);
index = cat.labels.FindIndex(x => x.spriteId == spriteId);
if (index != -1)
{
category = cat.name;
label = cat.labels[index].name;
break;
}
}
Expand All @@ -762,7 +764,7 @@ GameObject OnProducePaperDollPrefab(string assetname, Sprite[] sprites, SpriteLi
var psdLayers = GetPSDLayers();
m_BoneGOs = CreateBonesGO(root.transform);
if (spriteLib != null)
root.AddComponent<SpriteLibraryComponent>().spriteLib = spriteLib;
root.AddComponent<SpriteLibrary>().spriteLibraryAsset = spriteLib;
for (int i = 0; i < sprites.Length; ++i)
{
string categoryName;
Expand Down Expand Up @@ -791,14 +793,13 @@ GameObject OnProducePaperDollPrefab(string assetname, Sprite[] sprites, SpriteLi
srGameObject.transform.position = new Vector3(outlineOffset.x, outlineOffset.y, 0);
}
var category = "";
var spriteIndex = -1;
GetSpriteLibEntry(sprites[i].GetSpriteID().ToString(), out category, out spriteIndex);
if (!string.IsNullOrEmpty(category) && spriteIndex >= 0)
var labelName = "";
GetSpriteLiblabel(sprites[i].GetSpriteID().ToString(), out category, out labelName);
if (!string.IsNullOrEmpty(category) && !string.IsNullOrEmpty(labelName))
{
var sresolver = srGameObject.AddComponent<SpriteResolver>();
sresolver.spriteCategory = category;
sresolver.spriteIndex = spriteIndex;
sresolver.RefreshSpriteFromSpriteKey();
sresolver.SetCategoryAndLabel(category, labelName);
sresolver.ResolveSpriteToSpriteRenderer();
}
}
}
Expand All @@ -816,7 +817,7 @@ GameObject OnProducePrefab(string assetname, Sprite[] sprites, SpriteLibraryAsse
root = new GameObject();
root.name = assetname + "_GO";
if (spriteLib != null)
root.AddComponent<SpriteLibraryComponent>().spriteLib = spriteLib;
root.AddComponent<SpriteLibrary>().spriteLibraryAsset = spriteLib;
var psdLayers = GetPSDLayers();
for (int i = 0; i < psdLayers.Count; ++i)
{
Expand Down Expand Up @@ -845,14 +846,13 @@ GameObject OnProducePrefab(string assetname, Sprite[] sprites, SpriteLibraryAsse
}

var category = "";
var spriteIndex = -1;
GetSpriteLibEntry(layerSpriteID.ToString(), out category, out spriteIndex);
if (!string.IsNullOrEmpty(category) && spriteIndex >= 0)
var labelName = "";
GetSpriteLiblabel(layerSpriteID.ToString(), out category, out labelName);
if (!string.IsNullOrEmpty(category) && !string.IsNullOrEmpty(labelName))
{
var sresolver = l.gameObject.AddComponent<SpriteResolver>();
sresolver.spriteCategory = category;
sresolver.spriteIndex = spriteIndex;
sresolver.RefreshSpriteFromSpriteKey();
sresolver.SetCategoryAndLabel(category, labelName);
sresolver.ResolveSpriteToSpriteRenderer();
}
}
}
Expand Down Expand Up @@ -1239,18 +1239,30 @@ internal Vector2Int documentSize

SpriteLibraryAsset ProduceSpriteLibAsset(Sprite[] sprites)
{
if (!characterMode || m_SpriteLibrary.categories == null)
if (!characterMode || m_SpriteCategoryList.categories == null)
return null;
var sla = ScriptableObject.CreateInstance<SpriteLibraryAsset>();
sla.name = "Sprite Lib";
sla.entries = m_SpriteLibrary.categories.Select(x =>
new LibEntry()
sla.labels = m_SpriteCategoryList.categories.Select(x =>
new SpriteLibCategory()
{
category = x.name,
spriteList = x.spriteIds.Select(y => sprites.FirstOrDefault(z => z.GetSpriteID().ToString() == y)).ToList()
name = x.name,
categoryList = x.labels.Select(y =>
{
var sprite = sprites.FirstOrDefault(z => z.GetSpriteID().ToString() == y.spriteId);
return new Categorylabel()
{
name = y.name,
sprite = sprite
};
}).ToList()
}).ToList();
sla.UpdateHashes();
return sla;
if (sla.labels.Count > 0)
{
sla.UpdateHashes();
return sla;
}
return null;
}
}
}
32 changes: 16 additions & 16 deletions Editor/PSDImporterDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
using System.Linq;
using UnityEngine;
using UnityEngine.Assertions;
using UnityEngine.Experimental.U2D;
using UnityEditor.Experimental.U2D.Common;
using UnityEditor.Experimental.U2D.Animation;
using UnityEditor.U2D.Common;
using UnityEditor.U2D.Animation;
using System;
using UnityEditor.U2D.Sprites;
using UnityEngine.U2D;

namespace UnityEditor.Experimental.U2D.PSD
namespace UnityEditor.U2D.PSD
{
public abstract class PSDDataProvider
internal abstract class PSDDataProvider
{
public PSDImporter dataProvider;
}

public class SpriteBoneDataProvider : PSDDataProvider, ISpriteBoneDataProvider
internal class SpriteBoneDataProvider : PSDDataProvider, ISpriteBoneDataProvider
{
public List<SpriteBone> GetBones(GUID guid)
{
Expand All @@ -32,7 +32,7 @@ public void SetBones(GUID guid, List<SpriteBone> bones)
}
}

public class TextureDataProvider : PSDDataProvider, ITextureDataProvider
internal class TextureDataProvider : PSDDataProvider, ITextureDataProvider
{
Texture2D m_ReadableTexture;
Texture2D m_OriginalTexture;
Expand Down Expand Up @@ -72,7 +72,7 @@ public void GetTextureActualWidthAndHeight(out int width, out int height)
}
}

public class SpriteOutlineDataProvider : PSDDataProvider, ISpriteOutlineDataProvider
internal class SpriteOutlineDataProvider : PSDDataProvider, ISpriteOutlineDataProvider
{
public List<Vector2[]> GetOutlines(GUID guid)
{
Expand Down Expand Up @@ -105,7 +105,7 @@ public void SetTessellationDetail(GUID guid, float value)
}
}

public class SpritePhysicsOutlineProvider : PSDDataProvider, ISpritePhysicsOutlineDataProvider
internal class SpritePhysicsOutlineProvider : PSDDataProvider, ISpritePhysicsOutlineDataProvider
{
public List<Vector2[]> GetOutlines(GUID guid)
{
Expand Down Expand Up @@ -138,7 +138,7 @@ public void SetTessellationDetail(GUID guid, float value)
}
}

public class SpriteMeshDataProvider : PSDDataProvider, ISpriteMeshDataProvider
internal class SpriteMeshDataProvider : PSDDataProvider, ISpriteMeshDataProvider
{
public Vertex2DMetaData[] GetVertices(GUID guid)
{
Expand Down Expand Up @@ -196,7 +196,7 @@ public void SetEdges(GUID guid, Vector2Int[] edges)
}


public class CharacterDataProvider : PSDDataProvider, ICharacterDataProvider
internal class CharacterDataProvider : PSDDataProvider, ICharacterDataProvider
{
int ParentGroupInFlatten(int parentIndex, List<PSDLayer> psdLayers)
{
Expand Down Expand Up @@ -268,16 +268,16 @@ public void SetCharacterData(CharacterData characterData)
}
}

public class SpriteLibraryDataProvider : PSDDataProvider, ISpriteLibDataProvider
internal class SpriteLibraryDataProvider : PSDDataProvider, ISpriteLibDataProvider
{
public SpriteLibrary GetSpriteLibrary()
public SpriteCategoryList GetSpriteCategoryList()
{
return dataProvider.spriteLibrary;
return dataProvider.spriteCategoryList;
}

public void SetSpriteLibrary(SpriteLibrary spriteLibrary)
public void SetSpriteCategoryList(SpriteCategoryList spriteCategoryList)
{
dataProvider.spriteLibrary = spriteLibrary;
dataProvider.spriteCategoryList = spriteCategoryList;
}
}
}
8 changes: 4 additions & 4 deletions Editor/PSDImporterEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
using System.IO;
using PhotoshopFile;
using UnityEditor.Experimental.AssetImporters;
using UnityEditor.Experimental.U2D.Animation;
using UnityEditor.Experimental.U2D.Common;
using UnityEditor.U2D.Animation;
using UnityEditor.U2D.Common;
using UnityEditor.U2D.Sprites;
using UnityEngine;

namespace UnityEditor.Experimental.U2D.PSD
namespace UnityEditor.U2D.PSD
{
[CustomEditor(typeof(PSDImporter))]
public class PSDImporterEditor : ScriptedImporterEditor
internal class PSDImporterEditor : ScriptedImporterEditor
{
SerializedProperty m_TextureType;
SerializedProperty m_TextureShape;
Expand Down
2 changes: 1 addition & 1 deletion Editor/PSDLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Unity.Collections;
using UnityEngine;

namespace UnityEditor.Experimental.U2D.PSD
namespace UnityEditor.U2D.PSD
{
[Serializable]
class PSDLayer
Expand Down
3 changes: 3 additions & 0 deletions Editor/PSDPlugin/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Unity.2D.PsdImporter.Editor")]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit db14219

Please sign in to comment.