diff --git a/.PhotoshopScript/JSZXPsd2Unity/PSD导出Unity.js b/.PhotoshopScript/JSZXPsd2Unity/PSD导出Unity.js index d30ee35..0114b5a 100644 --- a/.PhotoshopScript/JSZXPsd2Unity/PSD导出Unity.js +++ b/.PhotoshopScript/JSZXPsd2Unity/PSD导出Unity.js @@ -109,19 +109,20 @@ function s2t(t) { return stringIDToTypeID(t) } this.documentName = app.activeDocument.name.slice(0, -4); - // 导出整个psd作为png参考图 var i, j, k, len, ref1, removeFiles; var baseFolder = Folder(this.saveFolder + "/" + this.documentName); if (baseFolder.exists) { removeFiles = baseFolder.getFiles(); for (i = j = 0, ref1 = removeFiles.length; 0 <= ref1 ? j < ref1 : j > ref1; i = 0 <= ref1 ? ++j : --j) { - if (removeFiles[i].name.startsWith(this.documentName) && removeFiles[i].name.endsWith('.png')) { - removeFiles[i].remove(); - } + removeFiles[i].remove(); + // if (removeFiles[i].name.startsWith(this.documentName) && removeFiles[i].name.endsWith('.png')) { + // removeFiles[i].remove(); + // } } baseFolder.remove(); } baseFolder.create(); + // 导出整个psd作为png参考图 saveFile = new File(baseFolder.fsName + "/" + "__background__.png"); options = new ExportOptionsSaveForWeb(); options.format = SaveDocumentType.PNG; diff --git a/.PhotoshopScript/JSZXPsd2Unity/step2.exe b/.PhotoshopScript/JSZXPsd2Unity/step2.exe index eac7dde..d62165e 100644 Binary files a/.PhotoshopScript/JSZXPsd2Unity/step2.exe and b/.PhotoshopScript/JSZXPsd2Unity/step2.exe differ diff --git a/.psd2uguiExamples/Sample.psd b/.psd2uguiExamples/Sample.psd index ca2002d..d02899b 100644 Binary files a/.psd2uguiExamples/Sample.psd and b/.psd2uguiExamples/Sample.psd differ diff --git a/Assets/Editor/Entity/IEntity.cs b/Assets/Editor/Entity/IEntity.cs index deeedd3..ea73dcc 100644 --- a/Assets/Editor/Entity/IEntity.cs +++ b/Assets/Editor/Entity/IEntity.cs @@ -11,6 +11,9 @@ namespace UguiToolkit.Editor void ApplyTransform(Transform tf); bool IsInside(Transform tf); void ApplyData(T ui) where T: MonoBehaviour; + void InitPreview(); + void ShowSelectionImg(bool show); + GameObject gameObject { get; } } public abstract class BaseEntity : MonoBehaviour, IEntity where T1 : MonoBehaviour where T2 : LayoutInfo.ElementInfo @@ -20,10 +23,6 @@ namespace UguiToolkit.Editor private UnityEngine.UI.Image m_selectionImg; public T2 ElementInfo => m_elementInfo; - - public abstract void ApplyTransform(Transform tf); - protected abstract void OnApplyData(T1 ui); - public void ShowSelectionImg(bool show) { if (m_selectionImg) @@ -32,6 +31,12 @@ namespace UguiToolkit.Editor } } + + public abstract void ApplyTransform(Transform tf); + public abstract void InitPreview(); + protected abstract void OnApplyData(T1 ui); + + public bool IsInside(Transform tf) { var rect = ElementInfo.Rect; @@ -65,7 +70,7 @@ namespace UguiToolkit.Editor rtf.sizeDelta = new Vector2(m_elementInfo.w, m_elementInfo.h); m_selectionImg = go.AddComponent(); - m_selectionImg.color = new Color(0, 1, 0, 0.2f); + m_selectionImg.color = new Color(0, 1, 0, 0.15f); } } } diff --git a/Assets/Editor/Entity/ImageEntity.cs b/Assets/Editor/Entity/ImageEntity.cs index f9b869b..c9d8666 100644 --- a/Assets/Editor/Entity/ImageEntity.cs +++ b/Assets/Editor/Entity/ImageEntity.cs @@ -21,25 +21,17 @@ namespace UguiToolkit.Editor private Image m_previewImage; - protected override void OnApplyData(Image ui) + // ʱ + public void SetTransform(float rotiation, float2 scale, bool similarityCalc) { - ApplyTransform(ui.transform); + this.rotiation = rotiation; + this.scale = scale; + this.similarityCalc = similarityCalc; + + this.needFillTransform = true; } - public void InitPreviewImage() - { - if (ElementInfo == null) return; - - if (!TryGetComponent(out m_previewImage)) - { - m_previewImage = gameObject.AddComponent(); - } - - LoadImageFromFile(ElementInfo.imgPath); - ApplyTransform(transform); - } - - void LoadImageFromFile(string path) + private void LoadImageFromFile(string path) { if (System.IO.File.Exists(path)) { @@ -58,18 +50,29 @@ namespace UguiToolkit.Editor } } - // ʱ - public void SetTransform(float rotiation, float2 scale, bool similarityCalc) + protected override void OnApplyData(Image ui) { - this.rotiation = rotiation; - this.scale = scale; - this.similarityCalc = similarityCalc; + ApplyTransform(ui.transform); - this.needFillTransform = true; + if (ElementInfo.HaveSlice) + { + ui.type = Image.Type.Sliced; + } + } + + public override void InitPreview() + { + if (ElementInfo == null) return; + + if (!TryGetComponent(out m_previewImage)) + { + m_previewImage = gameObject.AddComponent(); + } + + LoadImageFromFile(ElementInfo.imgPath); + ApplyTransform(transform); } - // ʱ - public void ClearFillTransform() => this.needFillTransform = false; public override void ApplyTransform(Transform tf) { diff --git a/Assets/Editor/Entity/TextEntity.cs b/Assets/Editor/Entity/TextEntity.cs index 38981d2..97d3a23 100644 --- a/Assets/Editor/Entity/TextEntity.cs +++ b/Assets/Editor/Entity/TextEntity.cs @@ -23,7 +23,7 @@ namespace UguiToolkit.Editor rectTransform.sizeDelta = new Vector2(ElementInfo.w + 10, ElementInfo.h + 10); } - public void InitPreviewText() + public override void InitPreview() { if (ElementInfo == null) return; diff --git a/Assets/Editor/Entity/TextMeshProEntity.cs b/Assets/Editor/Entity/TextMeshProEntity.cs index 1d7a178..42f233d 100644 --- a/Assets/Editor/Entity/TextMeshProEntity.cs +++ b/Assets/Editor/Entity/TextMeshProEntity.cs @@ -30,7 +30,7 @@ namespace UguiToolkit.Editor rectTransform.sizeDelta = new Vector2(ElementInfo.w + 10, ElementInfo.h + 10); } - public void InitPreviewText() + public override void InitPreview() { if (ElementInfo == null) return; diff --git a/Assets/Editor/Helper/LayoutParser.cs b/Assets/Editor/Helper/LayoutParser.cs index c086f2b..f46b0a9 100644 --- a/Assets/Editor/Helper/LayoutParser.cs +++ b/Assets/Editor/Helper/LayoutParser.cs @@ -31,7 +31,8 @@ namespace UguiToolkit.Editor y = layoutElementJsonData.y, w = layoutElementJsonData.w, h = layoutElementJsonData.h, - layoutInfo = layoutInfo + layoutInfo = layoutInfo, + imgSlicePath = layoutElementJsonData.slice ? layoutElementJsonData.imageName + "-slice" : null }); } else if (layoutElementJsonData.type == "Text") @@ -104,6 +105,7 @@ namespace UguiToolkit.Editor // ͼƬ public string imageName; + public bool slice; // ǷΪŹ // ı public string text; diff --git a/Assets/Editor/Manager/EntityManager.cs b/Assets/Editor/Manager/EntityManager.cs index 27f1764..f70254d 100644 --- a/Assets/Editor/Manager/EntityManager.cs +++ b/Assets/Editor/Manager/EntityManager.cs @@ -5,7 +5,6 @@ using System.IO; using UnityEditor; using UnityEditor.SceneManagement; using UnityEngine; -using static UguiToolkit.Editor.LayoutInfo; namespace UguiToolkit.Editor { @@ -19,8 +18,7 @@ namespace UguiToolkit.Editor private GameObject m_curSelectionGo; private List m_imageEntities; - private List m_textEntities; - private List m_tmpEntities; + private List m_textEntities; private List m_selectionEntities; [LabelText("脱离选择控制"), ShowInInspector] @@ -189,7 +187,7 @@ namespace UguiToolkit.Editor foreach (var rotScale in rotScaleInfoItems) { var imgInfo = imgEntity.ElementInfo; - if (imgInfo.imgPath == rotScale.imgPath) + if ( (imgInfo.HaveSlice && imgInfo.imgSlicePath == rotScale.imgPath) || imgInfo.imgPath == rotScale.imgPath) { if (rotScale.similarityCalc) { @@ -226,10 +224,6 @@ namespace UguiToolkit.Editor { textEntity.gameObject.SetActive(false); } - foreach (var textEntity in m_tmpEntities) - { - textEntity.gameObject.SetActive(false); - } } else if (activeGameObject.TryGetComponent(out var text)) { @@ -261,45 +255,6 @@ namespace UguiToolkit.Editor { imgEntity.gameObject.SetActive(false); } - foreach (var textEntity in m_tmpEntities) - { - textEntity.gameObject.SetActive(false); - } - } - else if (activeGameObject.TryGetComponent(out var tmp)) - { - bool IsInside = false; - m_entityRoot.gameObject.SetActive(true); - foreach (var tmpEntity in m_tmpEntities) - { - tmpEntity.ShowSelectionImg(true); - tmpEntity.gameObject.SetActive(true); - - m_selectionEntities.Add(tmpEntity); - - if (!IsInside && tmpEntity.IsInside(activeGameObject.transform)) IsInside = true; - } - - if (IsInside) - { - if (m_lastSelectionGo && m_lastSelectionGo == activeGameObject) - { - m_curSelectionGo = activeGameObject; - } - } - else - { - m_curSelectionGo = activeGameObject; - } - - foreach (var imgEntity in m_imageEntities) - { - imgEntity.gameObject.SetActive(false); - } - foreach (var textEntity in m_textEntities) - { - textEntity.gameObject.SetActive(false); - } } } } @@ -318,7 +273,6 @@ namespace UguiToolkit.Editor UpdateHierarchyOfEntity(show, m_entityRoot.gameObject); foreach (var entity in m_imageEntities) UpdateHierarchyOfEntity(show, entity.gameObject); foreach (var entity in m_textEntities) UpdateHierarchyOfEntity(show, entity.gameObject); - foreach (var entity in m_tmpEntities) UpdateHierarchyOfEntity(show, entity.gameObject); } private void UpdateHierarchyOfEntity(in bool show, in GameObject entity) @@ -339,7 +293,6 @@ namespace UguiToolkit.Editor m_imageEntities = new(m_panelCache.layoutInfo.Count); m_textEntities = new(m_panelCache.layoutInfo.Count); - m_tmpEntities = new(m_panelCache.layoutInfo.Count); m_selectionEntities = new(m_panelCache.layoutInfo.Count); foreach (var elementInfo in m_panelCache.GetLayoutElementInfos()) @@ -353,10 +306,12 @@ namespace UguiToolkit.Editor entity.transform.SetSiblingIndex(0); entity.SetData(imgInfo); - entity.InitPreviewImage(); + entity.InitPreview(); m_imageEntities.Add(entity); UpdateHierarchyOfEntity(false, entity.gameObject); + + // 创建九宫格 continue; } var textInfo = elementInfo as LayoutInfo.TextInfo; @@ -370,9 +325,9 @@ namespace UguiToolkit.Editor entity.transform.SetSiblingIndex(0); entity.SetData(textInfo); - entity.InitPreviewText(); + entity.InitPreview(); - m_tmpEntities.Add(entity); + m_textEntities.Add(entity); UpdateHierarchyOfEntity(false, entity.gameObject); continue; } @@ -384,7 +339,7 @@ namespace UguiToolkit.Editor entity.transform.SetSiblingIndex(0); entity.SetData(textInfo); - entity.InitPreviewText(); + entity.InitPreview(); m_textEntities.Add(entity); UpdateHierarchyOfEntity(false, entity.gameObject); diff --git a/Assets/Editor/ScriptObject/CacheScriptObject.cs b/Assets/Editor/ScriptObject/CacheScriptObject.cs index 60b3527..de33464 100644 --- a/Assets/Editor/ScriptObject/CacheScriptObject.cs +++ b/Assets/Editor/ScriptObject/CacheScriptObject.cs @@ -39,6 +39,12 @@ namespace UguiToolkit.Editor { imgInfo.imgPath = System.IO.Path.Join(targetImgDirPath, imgInfo.imgPath) + ".png"; imgInfo.imgPath = Path.GetRelativePath(projectPath, imgInfo.imgPath).Replace("\\", "/"); + + if (imgInfo.HaveSlice) + { + imgInfo.imgSlicePath = System.IO.Path.Join(targetImgDirPath, imgInfo.imgSlicePath) + ".png"; + imgInfo.imgSlicePath = Path.GetRelativePath(projectPath, imgInfo.imgSlicePath).Replace("\\", "/"); + } } } @@ -210,6 +216,8 @@ namespace UguiToolkit.Editor public class ImageInfo : ElementInfo { public string imgPath; + public string imgSlicePath; // 九宫格图片路径 + public bool HaveSlice => imgSlicePath != null; // 是否有九宫格 } [Serializable]