添加横竖版
This commit is contained in:
parent
1604997689
commit
93fd37730f
BIN
.res/开启助手.png
BIN
.res/开启助手.png
Binary file not shown.
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 42 KiB |
18
.vscode/launch.json
vendored
Normal file
18
.vscode/launch.json
vendored
Normal file
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
@ -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>(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)
|
||||
{
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -94,7 +94,7 @@ namespace UguiToolkit.Editor
|
||||
{
|
||||
entity.ApplyData(tf);
|
||||
}
|
||||
else if(tf.TryGetComponent<UnityEngine.UI.Image>(out var image))
|
||||
else if (tf.TryGetComponent<UnityEngine.UI.Image>(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;
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ namespace UguiToolkit.Editor
|
||||
public class CacheScriptObject : SerializedScriptableObject
|
||||
{
|
||||
[SerializeField]
|
||||
public Dictionary<GameObject, PanelCache> panelCaches = new();
|
||||
public Dictionary<GameObject, AllDirectionPanelCache> 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<int> index = new();
|
||||
List<int> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 "助手编辑界面";
|
||||
|
@ -13,12 +13,16 @@ namespace UguiToolkit.Editor.Windows
|
||||
{
|
||||
public class PanelCacheWindow : BaseWindow<PanelCacheWindow>
|
||||
{
|
||||
[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>();
|
||||
// entityManager.InitAllEntity(panelCache);
|
||||
|
||||
// });
|
||||
|
||||
// CloseWindow();
|
||||
//}
|
||||
//else {
|
||||
// var entityManager = stageManager.CreateSubManager<EntityManager>();
|
||||
// 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<GameObject>(_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
|
||||
|
14
README.md
14
README.md
@ -20,6 +20,8 @@
|
||||
5. `<图层名>@预制体=<资源唯一名称>` : 引用通用组件预制体 例如:领取龙币@预制体=btn_common_yellow_large
|
||||
|
||||
#### 导出数据
|
||||
> psd文件名不支持中文
|
||||
|
||||
运行指定脚本进行导出
|
||||

|
||||
|
||||
@ -30,10 +32,16 @@
|
||||
|
||||
### unity中如何操作
|
||||
|
||||
#### 进入预制体场景
|
||||
点击开启助手,并设置设置导出的psd数据 (yueka.layout.txt)
|
||||
上述`yueka_output`为最终进入项目的切图,可自行根据分类放入 `client\Assets\res\ui\atlas`
|
||||
|
||||
#### 进入预制体场景
|
||||
点击开启助手,设置如下路径后,点击`开启助手`
|
||||
|
||||
1. 项目内导出图片文件夹:填入项目内该功能的切图目录
|
||||
2. 目标图片信息文件夹: 填入导出psd数据的 ` yueka.layout.txt`
|
||||
|
||||

|
||||
|
||||

|
||||
#### 如何吸附
|
||||
##### 图片
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user