diff --git a/.res/开启助手.png b/.res/开启助手.png index 60a04ee..08ca582 100644 Binary files a/.res/开启助手.png and b/.res/开启助手.png differ diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..88f4af5 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,18 @@ +{ + // 使用 IntelliSense 了解相关属性。 + // 悬停以查看现有属性的描述。 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "extendscript-debug", + "request": "attach", + "name": "Attach to ExtendScript Engine" + }, + { + "type": "extendscript-debug", + "request": "launch", + "name": "Launch Script in ExtendScript Engine" + } + ] +} \ No newline at end of file diff --git a/Assets/Editor/Entity/IEntity.cs b/Assets/Editor/Entity/IEntity.cs index 73b98f2..95ef9fe 100644 --- a/Assets/Editor/Entity/IEntity.cs +++ b/Assets/Editor/Entity/IEntity.cs @@ -9,6 +9,7 @@ namespace UguiToolkit.Editor public interface IEntity { void ApplyTransform(Transform tf); + void ApplyTransformByParent(Transform parentTf); bool IsInside(Transform tf); void ApplyData(T ui) where T: Component; void InitPreview(); @@ -37,6 +38,8 @@ namespace UguiToolkit.Editor public abstract void InitPreview(); protected abstract void OnApplyData(T1 ui); + public virtual void ApplyTransformByParent(Transform parentTf) { } + public bool IsInside(Transform tf) { diff --git a/Assets/Editor/Entity/ImageEntity.cs b/Assets/Editor/Entity/ImageEntity.cs index 90f0f5d..9bac622 100644 --- a/Assets/Editor/Entity/ImageEntity.cs +++ b/Assets/Editor/Entity/ImageEntity.cs @@ -19,6 +19,8 @@ namespace UguiToolkit.Editor private bool similarityCalc; [ShowInInspector] private bool needFillTransform; + [ShowInInspector] + private Matrix4x4 lastTransformMatrix; private Image m_previewImage; @@ -32,6 +34,14 @@ namespace UguiToolkit.Editor this.needFillTransform = true; } + public override void ApplyTransformByParent(Transform parentTf) + { + var position = lastTransformMatrix.GetColumn(3); // ȡλ + var rotation = Quaternion.LookRotation(lastTransformMatrix.GetColumn(2), lastTransformMatrix.GetColumn(1)); // ȡת + parentTf.position += new Vector3(position.x, position.y, position.z); + parentTf.rotation *= rotation; + } + private void LoadImageFromFile(string path) { if (System.IO.File.Exists(path)) @@ -78,6 +88,9 @@ namespace UguiToolkit.Editor var rt = tf as RectTransform; if (needFillTransform) { + Matrix4x4 oldTransformMatrix = Matrix4x4.TRS(tf.position, tf.rotation, tf.localScale); + + var pos = ElementInfo.Position; var worldPos = StageManager.Instance.PrefabContentsRoot.transform.TransformPoint(new Vector3(pos.x, pos.y, 0)); var anchorMin = rt.anchorMin; @@ -118,6 +131,10 @@ namespace UguiToolkit.Editor rt.pivot = oldPiovt; var offsetRectPos = oldRect.position - rt.rect.position; rt.Translate(offsetRectPos); + + + Matrix4x4 newTransformMatrix = Matrix4x4.TRS(tf.position, tf.rotation, tf.localScale); + lastTransformMatrix = newTransformMatrix * oldTransformMatrix.inverse; } else { diff --git a/Assets/Editor/Manager/EntityManager.cs b/Assets/Editor/Manager/EntityManager.cs index 05e0e07..250c088 100644 --- a/Assets/Editor/Manager/EntityManager.cs +++ b/Assets/Editor/Manager/EntityManager.cs @@ -94,7 +94,7 @@ namespace UguiToolkit.Editor { entity.ApplyData(tf); } - else if(tf.TryGetComponent(out var image)) + else if (tf.TryGetComponent(out var image)) { entity.ApplyData(image); } @@ -107,7 +107,7 @@ namespace UguiToolkit.Editor entity.ApplyData(temp); } - + if (editWindow) editWindow.SetLastApplyEntity(entity); m_lastSelectionGo = m_curSelectionGo; m_lastSelectionEntity = entity; diff --git a/Assets/Editor/Manager/GlobalManager.cs b/Assets/Editor/Manager/GlobalManager.cs index b433cbb..d91ebce 100644 --- a/Assets/Editor/Manager/GlobalManager.cs +++ b/Assets/Editor/Manager/GlobalManager.cs @@ -26,9 +26,28 @@ namespace UguiToolkit public SettingScriptObject setting; public CacheScriptObject cache; + public PanelCache GetCache(GameObject asset, bool isVertical = false) + { + if (cache.panelCaches.TryGetValue(asset, out var allDirectionPanelCache)) + { + if (isVertical) return allDirectionPanelCache.panelCacheOfVertical; + else return allDirectionPanelCache.panelCacheOfHorizontal; + } + return null; + } + public void SaveCache(GameObject asset, PanelCache panelCache) { - cache.panelCaches[asset] = panelCache; + if (!cache.panelCaches.TryGetValue(asset, out var allDirectionPanelCache)) + { + cache.panelCaches[asset] = new AllDirectionPanelCache(); + } + + if (panelCache.isVertical) + cache.panelCaches[asset].panelCacheOfVertical = panelCache; + else + cache.panelCaches[asset].panelCacheOfHorizontal = panelCache; + SaveCache(); } diff --git a/Assets/Editor/ScriptObject/CacheScriptObject.cs b/Assets/Editor/ScriptObject/CacheScriptObject.cs index 7160b17..972c7da 100644 --- a/Assets/Editor/ScriptObject/CacheScriptObject.cs +++ b/Assets/Editor/ScriptObject/CacheScriptObject.cs @@ -16,7 +16,7 @@ namespace UguiToolkit.Editor public class CacheScriptObject : SerializedScriptableObject { [SerializeField] - public Dictionary panelCaches = new(); + public Dictionary panelCaches = new(); public static LayoutInfo PaserLayout(string layoutInfoFilePath, string targetImgDirPath) { @@ -84,22 +84,28 @@ namespace UguiToolkit.Editor } } + [Serializable] + public class AllDirectionPanelCache + { + public PanelCache panelCacheOfVertical; + public PanelCache panelCacheOfHorizontal; + } + [Serializable] public class PanelCache { [LabelText("项目内导出图片文件夹"), FolderPath] public string srcImgDirPath; - [LabelText("目标图片信息文件(psd导出)"), Sirenix.OdinInspector.FilePath(Extensions = "layout.txt")] + [LabelText("目标图片信息文件(psd导出)"), Sirenix.OdinInspector.FilePath(AbsolutePath = true, Extensions = "layout.txt")] public string layoutInfoFilePath; // Sample.layout.txt [LabelText("目标图片文件夹路径")] public string TargetImgDirPath => m_targetImgDirPath; + [LabelText("是否竖版")] + public bool isVertical; // 通过ElementInfo创建所有Actor - - // 1. 鼠标选中img或者text,1s 后触发助手 - // img // 2. 通过img的图片路径,查找rotScaleInfos,获得匹配的旋转缩放信息. 如果没有查找到则return // 3. 通过img的图片路径, 查找ActorManager, 获得所有和图片路径匹配的Actor,并显示所有匹配的Actor @@ -123,10 +129,11 @@ namespace UguiToolkit.Editor private PanelCache() { } // public PanelCache(string srcImgDirPath, string layoutInfoFilePath) - public PanelCache(string layoutInfoFilePath, string srcImgDirPath) + public PanelCache(string layoutInfoFilePath, string srcImgDirPath, bool isVertical = false) { this.srcImgDirPath = srcImgDirPath; this.layoutInfoFilePath = layoutInfoFilePath; + this.isVertical = isVertical; this.m_targetImgDirPath = GetTargetImgDirPath(layoutInfoFilePath); } @@ -144,21 +151,25 @@ namespace UguiToolkit.Editor public void ClearRotScaleInfoItem(string imgDirPath) { - List index = new(); + List indeces = new(); foreach (var rotScaleInfo in rotScaleInfos.Values) { - index.Clear(); + indeces.Clear(); for (var i = 0; i < rotScaleInfo.Count; i++) { var item = rotScaleInfo[i]; if (item.imgPath.StartsWith(imgDirPath)) { - index.Add(i); + indeces.Add(i); } } - foreach (var i in index) + + indeces.Sort(); + indeces.Reverse(); + + foreach (var index in indeces) { - rotScaleInfo.RemoveAt(i); + rotScaleInfo.RemoveAt(index); } } } diff --git a/Assets/Editor/Windows/EditWindow.cs b/Assets/Editor/Windows/EditWindow.cs index 6663a52..40a9f2a 100644 --- a/Assets/Editor/Windows/EditWindow.cs +++ b/Assets/Editor/Windows/EditWindow.cs @@ -59,6 +59,31 @@ namespace UguiToolkit.Editor.Windows createAllTextEntity?.Invoke(); } + + [Title("")] + [LabelText("ϴα任Ķ"), SerializeField] + private IEntity m_lastApplyEntity; + [LabelText("ҪӦñ任Ķ"), SerializeField] + private Transform m_targetTransform; + + [Button("Ӧϴα任")] + private void EffectLastApplyTransform() + { + if (m_targetTransform) + { + var m_lastApplyTransform = m_lastApplyEntity.gameObject.transform; + var parent = m_lastApplyTransform.parent; + m_lastApplyTransform.parent = null; + m_lastApplyEntity.ApplyTransformByParent(m_targetTransform); + m_lastApplyTransform.parent = parent; + } + } + + public void SetLastApplyEntity(IEntity lastApplyTransform) + { + this.m_lastApplyEntity = lastApplyTransform; + } + public override string GettitleContent() { return "ֱ༭"; diff --git a/Assets/Editor/Windows/PanelCacheWindow.cs b/Assets/Editor/Windows/PanelCacheWindow.cs index 33eae2b..5929df2 100644 --- a/Assets/Editor/Windows/PanelCacheWindow.cs +++ b/Assets/Editor/Windows/PanelCacheWindow.cs @@ -13,12 +13,16 @@ namespace UguiToolkit.Editor.Windows { public class PanelCacheWindow : BaseWindow { + [LabelText("是否竖版"), OnValueChanged(nameof(OnIsVerticalChanged)),SerializeField] + private bool m_isVertical = false; - [LabelText("项目内导出图片文件夹"), FolderPath, SerializeField] + [Title("psd导出数据设置")] + [LabelText("项目中切图文件夹"), FolderPath, SerializeField] private string m_srcImgDirPath; - [LabelText("目标图片信息文件(psd导出)"), Sirenix.OdinInspector.FilePath(Extensions = "layout.txt"), SerializeField] + [LabelText("layout.txt文件"), Sirenix.OdinInspector.FilePath(AbsolutePath = true, Extensions = "layout.txt"), SerializeField] private string m_layoutInfoFilePath; - + + private PrefabStage m_prefabStage; private GameObject m_prefab; private PanelCache m_panelCache; @@ -32,37 +36,8 @@ namespace UguiToolkit.Editor.Windows // 打开编辑界面 EditWindow.ShowWindow(null); - //if (m_panelCache == null) - //{ - // var targetImgDirPath = PanelCache.GetTargetImgDirPath(m_layoutInfoFilePath); - // float distanceDifference = GlobalManager.Instance.setting.distanceDifference; - // CacheScriptObject.CalcRotScaleInfos(m_srcImgDirPath, targetImgDirPath, distanceDifference, (rotScaleInfos) => - // { - // if (!stageManager) return; - - // var panelCache = new PanelCache(m_srcImgDirPath, m_layoutInfoFilePath); - - // panelCache.rotScaleInfos = rotScaleInfos; - // panelCache.layoutInfo = CacheScriptObject.PaserLayout(m_layoutInfoFilePath, targetImgDirPath); - - // // 保存缓存 - // GlobalManager.Instance.SaveCache(m_prefab, panelCache); - - // var entityManager = stageManager.CreateSubManager(); - // entityManager.InitAllEntity(panelCache); - - // }); - - // CloseWindow(); - //} - //else { - // var entityManager = stageManager.CreateSubManager(); - // entityManager.InitAllEntity(m_panelCache); - // CloseWindow(); - //} - var targetImgDirPath = PanelCache.GetTargetImgDirPath(m_layoutInfoFilePath); - var panelCache = new PanelCache(m_layoutInfoFilePath, m_srcImgDirPath); + var panelCache = new PanelCache(m_layoutInfoFilePath, m_srcImgDirPath, m_isVertical); panelCache.layoutInfo = CacheScriptObject.PaserLayout(m_layoutInfoFilePath, targetImgDirPath); if (m_panelCache != null) @@ -97,6 +72,28 @@ namespace UguiToolkit.Editor.Windows } } + private void OnIsVerticalChanged() + { + UpdatePanelCache(); + } + + private void UpdatePanelCache() + { + var cache = GlobalManager.Instance.cache; + var panelCache = GlobalManager.Instance.GetCache(m_prefab, m_isVertical); + if (panelCache != null) + { + m_srcImgDirPath = panelCache.srcImgDirPath; + m_layoutInfoFilePath = panelCache.layoutInfoFilePath; + m_panelCache = panelCache; + } + else { + m_srcImgDirPath = null; + m_layoutInfoFilePath = null; + m_panelCache = null; + } + } + public override string GettitleContent() { return "请选择信息后开启助手"; @@ -108,12 +105,7 @@ namespace UguiToolkit.Editor.Windows m_prefabStage = _args.stage; m_prefab = AssetDatabase.LoadAssetAtPath(_args.stage.assetPath); - var cache = GlobalManager.Instance.cache; - if (cache.panelCaches.TryGetValue(m_prefab, out m_panelCache)) - { - m_srcImgDirPath = m_panelCache.srcImgDirPath; - m_layoutInfoFilePath = m_panelCache.layoutInfoFilePath; - } + UpdatePanelCache(); } public class PanelCacheWindowArgs : WindowArgs diff --git a/README.md b/README.md index eb79f0c..c7181f8 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,8 @@ 5. `<图层名>@预制体=<资源唯一名称>` : 引用通用组件预制体 例如:领取龙币@预制体=btn_common_yellow_large #### 导出数据 +> psd文件名不支持中文 + 运行指定脚本进行导出 ![](./.res/ps导出入口.png) @@ -30,10 +32,16 @@ ### unity中如何操作 -#### 进入预制体场景 -点击开启助手,并设置设置导出的psd数据 (yueka.layout.txt) +上述`yueka_output`为最终进入项目的切图,可自行根据分类放入 `client\Assets\res\ui\atlas` + +#### 进入预制体场景 +点击开启助手,设置如下路径后,点击`开启助手` + +1. 项目内导出图片文件夹:填入项目内该功能的切图目录 +2. 目标图片信息文件夹: 填入导出psd数据的 ` yueka.layout.txt` + +![img](F:\c1workspace\svn\__workspace__dev__\client\PackagesSource\com.txcombo.c1.ugui-toolkit\.res\开启助手.png) -![](./.res/开启助手.png) #### 如何吸附 ##### 图片