diff --git a/.PhotoshopScript/JSZXPsd2Unity/PSD导出Unity.js b/.PhotoshopScript/JSZXPsd2Unity/PSD导出Unity.js index fb9cd15..ba42ab2 100644 --- a/.PhotoshopScript/JSZXPsd2Unity/PSD导出Unity.js +++ b/.PhotoshopScript/JSZXPsd2Unity/PSD导出Unity.js @@ -944,28 +944,32 @@ function s2t(t) { return stringIDToTypeID(t) } outputDoc.layers[1].remove() layer = outputDoc.layers[0] - if (opt['九宫格']) { - if (!layer.isBackgroundLayer) { - var param; - if (opt['九宫格']) { - param = opt['九宫格']; - } + // if (opt['九宫格']) { + // if (!layer.isBackgroundLayer) { + // var param; + // if (opt['九宫格']) { + // param = opt['九宫格']; + // } - if (opt['九宫格'] === "true") { - this.snipImage(outputDoc, layer, opt); - fileName += "-slice"; - } - else { - outputDoc = this.sliceCutImg(outputDoc, layerName, param); - fileName += "-noslice"; - } - } - } - else { - fileName += "-noslice"; - if (!layer.isBackgroundLayer) { - this.snipImage(outputDoc, layer, opt); - } + // if (opt['九宫格'] === "true") { + // this.snipImage(outputDoc, layer, opt); + // fileName += "-slice"; + // } + // else { + // outputDoc = this.sliceCutImg(outputDoc, layerName, param); + // fileName += "-noslice"; + // } + // } + // } + // else { + // fileName += "-noslice"; + // if (!layer.isBackgroundLayer) { + // this.snipImage(outputDoc, layer, opt); + // } + // } + + if (!layer.isBackgroundLayer) { + this.snipImage(outputDoc, layer, opt); } saveFile = new File(this.baseFolder.fsName + "/" + fileName + ".png"); diff --git a/.psd2uguiExamples/Sample.psd b/.psd2uguiExamples/Sample.psd index c69a92a..09e7e6b 100644 Binary files a/.psd2uguiExamples/Sample.psd and b/.psd2uguiExamples/Sample.psd differ diff --git a/Assets/Scripts.meta b/Assets/Editor/Entity.meta similarity index 77% rename from Assets/Scripts.meta rename to Assets/Editor/Entity.meta index ecbb271..720592b 100644 --- a/Assets/Scripts.meta +++ b/Assets/Editor/Entity.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 558d96c5ace2fc7408f8fa23ef43414e +guid: 704dd5babe586c04e966a731c5186616 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Editor/Entity/IEntity.cs b/Assets/Editor/Entity/IEntity.cs new file mode 100644 index 0000000..653218d --- /dev/null +++ b/Assets/Editor/Entity/IEntity.cs @@ -0,0 +1,58 @@ +using System.Collections; +using Unity.Mathematics; +using UnityEngine; + +namespace UguiToolkit.Editor +{ + public interface IEntity + { + void SetTransform(float rotiation, float2 scale); + void ApplyTransform(Transform transform); + } + + public abstract class BaseEntity : MonoBehaviour, IEntity where T1 : MonoBehaviour where T2 : LayoutInfo.ElementInfo + { + // ElementInfo + private T2 m_elementInfo; + + private float rotiation; + private float2 scale; + private bool needFillTransform; + + public void ApplyTransform(Transform transform) + { + if (needFillTransform) + { + transform.rotation = Quaternion.Euler(0, 0, rotiation); + transform.localScale = new Vector3(scale.x, scale.y, 0); + } + var position = m_elementInfo.Position; + transform.position = new Vector3(position.x, position.y, 0); + } + + // 查找时调用 + public void SetTransform(float rotiation, float2 scale) + { + this.rotiation = rotiation; + this.scale = scale; + + this.needFillTransform = true; + } + + // 查找时调用 + public void ClearFillTransform() => this.needFillTransform = false; + + // 创建时调用 + public void SetData(T2 elementInfo) + { + this.m_elementInfo = elementInfo; + } + + public void ApplyData(T1 ui) + { + OnApplyData(ui, m_elementInfo); + } + + protected virtual void OnApplyData(T1 ui, T2 elementInfo) { } + } +} \ No newline at end of file diff --git a/Assets/Editor/Entity/IEntity.cs.meta b/Assets/Editor/Entity/IEntity.cs.meta new file mode 100644 index 0000000..f73e9d4 --- /dev/null +++ b/Assets/Editor/Entity/IEntity.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d91868a964b23744f80d13a618ee6ec1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/Entity/ImageEntity.cs b/Assets/Editor/Entity/ImageEntity.cs new file mode 100644 index 0000000..feb60d9 --- /dev/null +++ b/Assets/Editor/Entity/ImageEntity.cs @@ -0,0 +1,13 @@ +using System.Collections; +using System.Collections.Generic; +using UguiToolkit.Editor; +using UnityEngine; +using UnityEngine.UI; + +public class ImageEntity : BaseEntity +{ + protected override void OnApplyData(Image ui, LayoutInfo.ImageInfo elementInfo) + { + + } +} diff --git a/Assets/Editor/Entity/ImageEntity.cs.meta b/Assets/Editor/Entity/ImageEntity.cs.meta new file mode 100644 index 0000000..756d944 --- /dev/null +++ b/Assets/Editor/Entity/ImageEntity.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 21bdf5cdb7e38cf45bc06153662310b3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/Entity/TextEntity.cs b/Assets/Editor/Entity/TextEntity.cs new file mode 100644 index 0000000..db06fee --- /dev/null +++ b/Assets/Editor/Entity/TextEntity.cs @@ -0,0 +1,15 @@ +using System.Collections; +using System.Collections.Generic; +using UguiToolkit.Editor; +using UnityEngine; +using UnityEngine.UI; + +public class TextEntity : BaseEntity +{ + protected override void OnApplyData(Text ui, LayoutInfo.TextInfo elementInfo) + { + ui.text = elementInfo.text; + ui.fontSize = (int)elementInfo.size; + ui.color = elementInfo.color; + } +} \ No newline at end of file diff --git a/Assets/Editor/Entity/TextEntity.cs.meta b/Assets/Editor/Entity/TextEntity.cs.meta new file mode 100644 index 0000000..6463bbb --- /dev/null +++ b/Assets/Editor/Entity/TextEntity.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7d5791996f4b6cd4f9f2f6ee325c1701 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/Helper/LayoutParser.cs b/Assets/Editor/Helper/LayoutParser.cs index 8602bf1..81e59b4 100644 --- a/Assets/Editor/Helper/LayoutParser.cs +++ b/Assets/Editor/Helper/LayoutParser.cs @@ -25,6 +25,7 @@ namespace UguiToolkit.Editor { elementInfos.Add(new LayoutInfo.ImageInfo() { + name = layoutElementJsonData.name, imgPath = layoutElementJsonData.imageName, x = layoutElementJsonData.x, y = layoutElementJsonData.y, @@ -35,8 +36,22 @@ namespace UguiToolkit.Editor } else if (layoutElementJsonData.type == "Text") { - // TODO + ColorUtility.TryParseHtmlString(layoutElementJsonData.color, out var color); + elementInfos.Add(new LayoutInfo.TextInfo() + { + name = layoutElementJsonData.name, + text = layoutElementJsonData.text, + font = layoutElementJsonData.font, + size = layoutElementJsonData.size, + align = layoutElementJsonData.align, + color = color, + x = layoutElementJsonData.x, + y = layoutElementJsonData.y, + w = layoutElementJsonData.w, + h = layoutElementJsonData.h, + layoutInfo = layoutInfo + }); } if (layoutElementJsonData.elements != null) @@ -87,7 +102,14 @@ namespace UguiToolkit.Editor public float h; public List elements; - + // ͼƬ public string imageName; + + // ı + public string text; + public float size; + public string color; + public string align; + public string font; } } diff --git a/Assets/Scripts/Manager/ImageActorManager.cs b/Assets/Editor/Manager/ActorManager.cs similarity index 86% rename from Assets/Scripts/Manager/ImageActorManager.cs rename to Assets/Editor/Manager/ActorManager.cs index 7035d88..70d0c60 100644 --- a/Assets/Scripts/Manager/ImageActorManager.cs +++ b/Assets/Editor/Manager/ActorManager.cs @@ -3,7 +3,7 @@ using UnityEngine; namespace UguiToolkit { - public class ImageActorManager : MonoBehaviour + public class ActorManager : MonoBehaviour, IManager { private void Start() { diff --git a/Assets/Scripts/Manager/ImageActorManager.cs.meta b/Assets/Editor/Manager/ActorManager.cs.meta similarity index 100% rename from Assets/Scripts/Manager/ImageActorManager.cs.meta rename to Assets/Editor/Manager/ActorManager.cs.meta diff --git a/Assets/Editor/Manager/EntityManager.cs b/Assets/Editor/Manager/EntityManager.cs new file mode 100644 index 0000000..afeb7de --- /dev/null +++ b/Assets/Editor/Manager/EntityManager.cs @@ -0,0 +1,10 @@ +//using System; +//using UnityEngine; + +//namespace UguiToolkit +//{ +// public class EntityManager : MonoBehaviour, IManager +// { +// private PanelCache panelCache; +// } +//} \ No newline at end of file diff --git a/Assets/Editor/Manager/EntityManager.cs.meta b/Assets/Editor/Manager/EntityManager.cs.meta new file mode 100644 index 0000000..a4b4d21 --- /dev/null +++ b/Assets/Editor/Manager/EntityManager.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: e8be088e252d5d94995caae74d690cc6 +timeCreated: 1719934421 \ No newline at end of file diff --git a/Assets/Editor/Manager/GlobalManager.cs b/Assets/Editor/Manager/GlobalManager.cs index ae6b46d..ed89508 100644 --- a/Assets/Editor/Manager/GlobalManager.cs +++ b/Assets/Editor/Manager/GlobalManager.cs @@ -1,4 +1,5 @@ using UguiToolkit.Editor; +using UnityEditor; namespace UguiToolkit { @@ -20,5 +21,11 @@ namespace UguiToolkit public SettingScriptObject setting; public CacheScriptObject cache; + + public void SaveCache() + { + EditorUtility.SetDirty(cache); + AssetDatabase.SaveAssetIfDirty(cache); + } } } \ No newline at end of file diff --git a/Assets/Scripts/Manager/StageManager.cs b/Assets/Editor/Manager/StageManager.cs similarity index 65% rename from Assets/Scripts/Manager/StageManager.cs rename to Assets/Editor/Manager/StageManager.cs index bbe2b19..90af56e 100644 --- a/Assets/Scripts/Manager/StageManager.cs +++ b/Assets/Editor/Manager/StageManager.cs @@ -2,6 +2,7 @@ using UnityEngine; using UnityEditor; using UnityEngine.SceneManagement; +using System.Collections.Generic; namespace UguiToolkit { @@ -12,6 +13,8 @@ namespace UguiToolkit public Scene Scene => m_scene; private GameObject m_prefabContentsRoot; public GameObject PrefabContentsRoot => m_prefabContentsRoot; + private Dictionary m_mngMap = new Dictionary(); + private static StageManager m_instance; public static StageManager Instance @@ -27,7 +30,7 @@ namespace UguiToolkit } } - public static void CreateStageManager(Scene scene, GameObject prefabContentsRoot) + public static StageManager CreateStageManager(Scene scene, GameObject prefabContentsRoot) { var go = new GameObject(); go.name = "StageManager"; @@ -37,22 +40,28 @@ namespace UguiToolkit m_instance.m_prefabContentsRoot = prefabContentsRoot; go.hideFlags = HideFlags.DontSave; + + return m_instance; } - private T CreateSubManager() where T : MonoBehaviour + public T CreateSubManager() where T : MonoBehaviour, IManager { - var go = new GameObject(); - go.name = typeof(T).Name; - go.transform.parent = PrefabContentsRoot.transform; - var t = go.AddComponent(); - - go.hideFlags = HideFlags.DontSave; + var t = gameObject.AddComponent(); + m_mngMap[typeof(T)] = t; + return t; } - private void Start() + public T GetManager() where T : MonoBehaviour, IManager { - CreateSubManager(); + if (m_mngMap.TryGetValue(typeof(T), out var mng)) + return mng as T; + + return null; } } +} + +public interface IManager { + } \ No newline at end of file diff --git a/Assets/Scripts/Manager/StageManager.cs.meta b/Assets/Editor/Manager/StageManager.cs.meta similarity index 100% rename from Assets/Scripts/Manager/StageManager.cs.meta rename to Assets/Editor/Manager/StageManager.cs.meta diff --git a/Assets/Editor/ScriptObject/CacheScriptObject.cs b/Assets/Editor/ScriptObject/CacheScriptObject.cs index 1923374..1f87bce 100644 --- a/Assets/Editor/ScriptObject/CacheScriptObject.cs +++ b/Assets/Editor/ScriptObject/CacheScriptObject.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using Unity.Mathematics; using UnityEngine; using Sirenix.OdinInspector; +using static UguiToolkit.Editor.LayoutInfo; namespace UguiToolkit.Editor { @@ -21,29 +22,55 @@ namespace UguiToolkit.Editor public string layoutInfoFilePath; // Sample.layout.txt [LabelText("目标图片文件夹路径")] - public string TargetImgDirPath - { - get - { - if (string.IsNullOrWhiteSpace(layoutInfoFilePath)) return ""; - var dirName = System.IO.Path.GetDirectoryName(layoutInfoFilePath); - var fileName = System.IO.Path.GetFileName(layoutInfoFilePath); - var split = fileName.Split("."); - if (split.Length == 0) return ""; + public string TargetImgDirPath => GetTargetImgDirPath(layoutInfoFilePath); - return System.IO.Path.Join(dirName, split[0]); - } - } - // 通过读取layout.txt 获得 position 图片路径(源图) -> Transform信息(效果图) - public Dictionary> targetImageTransformInfos = new(); + // 通过ElementInfo创建所有Actor + + + // 1. 鼠标选中img或者text,1s 后触发助手 + + // img + // 2. 通过img的图片路径,查找rotScaleInfos,获得匹配的旋转缩放信息. 如果没有查找到则return + // 3. 通过img的图片路径, 查找ActorManager, 获得所有和图片路径匹配的Actor,并显示所有匹配的Actor + // 4. 每帧刷新,如果鼠标进入Actor的rect中,则播放scale动效。鼠标松开,则apply 该actor的 trasform + + // text + // 2. 每帧刷新,查找圆形范围内,所有text Actor,并显示所有匹配的Actor + // 3. 每帧刷新,如果鼠标进入Actor的rect中,则播放scale动效。鼠标松开,则apply 该actor的 trasform + // 通过cmd计算获得 图片路径(源图) -> 旋转缩放信息(效果图) public Dictionary> rotScaleInfos = new(); + public LayoutInfo layoutInfo; + + public IEnumerator GetLayoutElementInfos() where T : LayoutInfo.ElementInfo + { + if (layoutInfo == null) yield break; + + foreach (var e in layoutInfo) + { + if (e is T) + { + yield return e as T; + } + } + } + + public static string GetTargetImgDirPath(in string layoutInfoFilePath) + { + if (string.IsNullOrWhiteSpace(layoutInfoFilePath)) return ""; + var dirName = System.IO.Path.GetDirectoryName(layoutInfoFilePath); + var fileName = System.IO.Path.GetFileName(layoutInfoFilePath); + var split = fileName.Split("."); + if (split.Length == 0) return ""; + + return System.IO.Path.Join(dirName, split[0]); + } } [Serializable] - public class LayoutInfo + public class LayoutInfo: IEnumerable { private List m_elementInfos; private float m_w; @@ -59,8 +86,21 @@ namespace UguiToolkit.Editor this.m_h = h; } + public IEnumerator GetEnumerator() + { + return ((IEnumerable)m_elementInfos).GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return ((IEnumerable)m_elementInfos).GetEnumerator(); + } + + [Serializable] public class ElementInfo { + public string name; + public float x; public float y; public float w; @@ -68,7 +108,8 @@ namespace UguiToolkit.Editor public LayoutInfo layoutInfo; - public float2 Position { + public float2 Position + { get { float x = (layoutInfo.W / 2f) * -1 + this.x + this.w / 2f; float y = layoutInfo.H / 2f - this.y - this.h / 2f; @@ -76,16 +117,29 @@ namespace UguiToolkit.Editor return new float2(x, y); } } + + public Rect Rect { + get { + var pos = Position - new float2(this.w / 2f, this.h / 2f); + return new(pos.x, pos.y, this.w, this.h); + } + } } + [Serializable] public class ImageInfo : ElementInfo { public string imgPath; } + [Serializable] public class TextInfo : ElementInfo { public string text; + public float size; + public Color color; + public string align; + public string font; } } diff --git a/Assets/Editor/UguiToolkit.Editor.asmdef b/Assets/Editor/UguiToolkit.Editor.asmdef index 5b78ab3..41cff7b 100644 --- a/Assets/Editor/UguiToolkit.Editor.asmdef +++ b/Assets/Editor/UguiToolkit.Editor.asmdef @@ -2,8 +2,7 @@ "name": "UguiToolkit.Editor", "rootNamespace": "", "references": [ - "GUID:d8b63aba1907145bea998dd612889d6b", - "GUID:f5bcd4641e14bde4c8ba640a2285abc5" + "GUID:d8b63aba1907145bea998dd612889d6b" ], "includePlatforms": [ "Editor" diff --git a/Assets/Editor/Windows/PanelCacheWindow.cs b/Assets/Editor/Windows/PanelCacheWindow.cs index 5d1b32e..8fcf7f3 100644 --- a/Assets/Editor/Windows/PanelCacheWindow.cs +++ b/Assets/Editor/Windows/PanelCacheWindow.cs @@ -32,15 +32,16 @@ namespace UguiToolkit.Editor.Windows panelCache.layoutInfoFilePath = m_layoutInfoFilePath; if (!m_cacheExist) { - panelCache.rotScaleInfos = new(); CalcRotScaleInfos(); PaserLayout(); } var cache = GlobalManager.Instance.cache; cache.panelCaches[m_prefab] = panelCache; - - UguiToolkit.StageManager.CreateStageManager(m_prefabStage.scene, m_prefabStage.prefabContentsRoot); + GlobalManager.Instance.SaveCache(); + + var stageManager = UguiToolkit.StageManager.CreateStageManager(m_prefabStage.scene, m_prefabStage.prefabContentsRoot); + var actorManager = stageManager.CreateSubManager(); CloseWindow(); } @@ -56,7 +57,9 @@ namespace UguiToolkit.Editor.Windows using (StreamReader reader = File.OpenText(m_layoutInfoFilePath)) { var jsonData = reader.ReadToEnd(); - layoutParser.Parser(jsonData); + var layoutInfo = layoutParser.Parser(jsonData); + + panelCache.layoutInfo = layoutInfo; } } @@ -67,6 +70,7 @@ namespace UguiToolkit.Editor.Windows var jsonData = CommandHelper.CalcRotScale(panelCache.srcImgDirPath, panelCache.TargetImgDirPath, panelCache.rotScaleInfos); if (jsonData == null || jsonData.data == null) return; var rotScaleInfos = panelCache.rotScaleInfos; + rotScaleInfos.Clear(); foreach (var kv in jsonData.data) { List rotScaleItemList = new(); @@ -75,7 +79,7 @@ namespace UguiToolkit.Editor.Windows { rotScaleItemList.Add(new () { - imgPath = jsonItemData.targetPath, + imgPath = Path.GetRelativePath(Application.dataPath, jsonItemData.targetPath), rotiation = jsonItemData.rot, scale = new float2(jsonItemData.scale[0], jsonItemData.scale[1]) }); diff --git a/Assets/Scripts/Manager.meta b/Assets/Scripts/Manager.meta deleted file mode 100644 index fb9e424..0000000 --- a/Assets/Scripts/Manager.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: d62d1ab93d3c4beaa6f0d6cf680583da -timeCreated: 1718725983 \ No newline at end of file diff --git a/Assets/Scripts/UguiToolkit.asmdef b/Assets/Scripts/UguiToolkit.asmdef deleted file mode 100644 index fd2c2c1..0000000 --- a/Assets/Scripts/UguiToolkit.asmdef +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "UguiToolkit", - "rootNamespace": "", - "references": [], - "includePlatforms": [ - "Editor", - "WindowsStandalone32", - "WindowsStandalone64" - ], - "excludePlatforms": [], - "allowUnsafeCode": false, - "overrideReferences": false, - "precompiledReferences": [], - "autoReferenced": true, - "defineConstraints": [], - "versionDefines": [], - "noEngineReferences": false -} \ No newline at end of file diff --git a/Assets/Scripts/UguiToolkit.asmdef.meta b/Assets/Scripts/UguiToolkit.asmdef.meta deleted file mode 100644 index 65f2854..0000000 --- a/Assets/Scripts/UguiToolkit.asmdef.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: f5bcd4641e14bde4c8ba640a2285abc5 -AssemblyDefinitionImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: