支持九宫格
This commit is contained in:
parent
708dc913d0
commit
74aa81a4ba
@ -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();
|
||||
}
|
||||
// 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;
|
||||
|
Binary file not shown.
Binary file not shown.
@ -11,6 +11,9 @@ namespace UguiToolkit.Editor
|
||||
void ApplyTransform(Transform tf);
|
||||
bool IsInside(Transform tf);
|
||||
void ApplyData<T>(T ui) where T: MonoBehaviour;
|
||||
void InitPreview();
|
||||
void ShowSelectionImg(bool show);
|
||||
GameObject gameObject { get; }
|
||||
}
|
||||
|
||||
public abstract class BaseEntity<T1,T2> : 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<UnityEngine.UI.Image>();
|
||||
m_selectionImg.color = new Color(0, 1, 0, 0.2f);
|
||||
m_selectionImg.color = new Color(0, 1, 0, 0.15f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<Image>(out m_previewImage))
|
||||
{
|
||||
m_previewImage = gameObject.AddComponent<Image>();
|
||||
}
|
||||
|
||||
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<Image>(out m_previewImage))
|
||||
{
|
||||
m_previewImage = gameObject.AddComponent<Image>();
|
||||
}
|
||||
|
||||
LoadImageFromFile(ElementInfo.imgPath);
|
||||
ApplyTransform(transform);
|
||||
}
|
||||
|
||||
// ²éÕÒʱµ÷ÓÃ
|
||||
public void ClearFillTransform() => this.needFillTransform = false;
|
||||
|
||||
public override void ApplyTransform(Transform tf)
|
||||
{
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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<ImageEntity> m_imageEntities;
|
||||
private List<TextEntity> m_textEntities;
|
||||
private List<TextMeshProEntity> m_tmpEntities;
|
||||
private List<IEntity> m_textEntities;
|
||||
private List<IEntity> 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<UnityEngine.UI.Text>(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<TMPro.TextMeshProUGUI>(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<LayoutInfo.ElementInfo>())
|
||||
@ -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);
|
||||
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user