com.soviby.unity.ui.ugui-to.../Assets/Editor/Windows/PanelCacheWindow.cs

117 lines
3.9 KiB
C#
Raw Normal View History

2024-10-23 17:30:59 +00:00
#if UNITY_EDITOR
using System;
2024-10-23 17:30:59 +00:00
using System.Collections.Generic;
2024-10-09 16:12:59 +00:00
using System.IO;
2024-10-08 15:19:05 +00:00
using Sirenix.OdinInspector;
using Sirenix.OdinInspector.Editor;
using Unity.Mathematics;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
namespace UguiToolkit.Editor.Windows
{
2024-10-28 16:31:38 +00:00
public class PanelCacheWindow : BaseWindow<PanelCacheWindow>
2024-10-08 15:19:05 +00:00
{
2024-12-09 11:18:10 +00:00
[LabelText("是否竖版"), OnValueChanged(nameof(OnIsVerticalChanged)),SerializeField]
private bool m_isVertical = false;
2024-12-06 10:46:00 +00:00
2024-12-09 11:18:10 +00:00
[Title("psd导出数据设置")]
[LabelText("项目中切图文件夹"), FolderPath, SerializeField]
2024-12-06 10:46:00 +00:00
private string m_srcImgDirPath;
2024-12-09 11:18:10 +00:00
[LabelText("layout.txt文件"), Sirenix.OdinInspector.FilePath(AbsolutePath = true, Extensions = "layout.txt"), SerializeField]
2024-10-08 15:19:05 +00:00
private string m_layoutInfoFilePath;
2024-12-09 11:18:10 +00:00
2024-10-08 15:19:05 +00:00
private PrefabStage m_prefabStage;
private GameObject m_prefab;
private PanelCache m_panelCache;
2024-10-08 15:19:05 +00:00
[Button("开启助手", ButtonSizes.Medium)]
2024-10-28 16:31:38 +00:00
private void DoStart()
2024-10-08 15:19:05 +00:00
{
var stageManager = UguiToolkit.StageManager.CreateStageManager(m_prefabStage.scene, m_prefabStage.prefabContentsRoot, m_prefab);
stageManager.gameObject.AddComponent<UnityMainThreadDispatcher>();
2024-10-28 16:31:38 +00:00
// 打开编辑界面
EditWindow.ShowWindow(null);
2024-10-08 15:19:05 +00:00
2024-11-28 17:06:27 +00:00
var targetImgDirPath = PanelCache.GetTargetImgDirPath(m_layoutInfoFilePath);
2024-12-09 11:18:10 +00:00
var panelCache = new PanelCache(m_layoutInfoFilePath, m_srcImgDirPath, m_isVertical);
2024-11-28 17:06:27 +00:00
panelCache.layoutInfo = CacheScriptObject.PaserLayout(m_layoutInfoFilePath, targetImgDirPath);
2024-12-06 10:46:00 +00:00
if (m_panelCache != null)
{
panelCache.rotScaleInfos = m_panelCache.rotScaleInfos;
panelCache.imgDirPathTimestamp = m_panelCache.imgDirPathTimestamp;
// 清理多余数据
panelCache.InitRotScaleInfos();
}
2024-11-28 17:06:27 +00:00
// 保存缓存
GlobalManager.Instance.SaveCache(m_prefab, panelCache);
var entityManager = stageManager.CreateSubManager<EntityManager>();
2024-12-06 10:46:00 +00:00
// stageManager.CreateSubManager<SelectionManager>();
2024-11-28 17:06:27 +00:00
entityManager.InitAllEntity(panelCache);
2024-12-06 10:46:00 +00:00
if (!string.IsNullOrEmpty(m_srcImgDirPath))
entityManager.AddCheckImgDirPath(m_srcImgDirPath);
2024-11-28 17:06:27 +00:00
CloseWindow();
2024-10-08 15:19:05 +00:00
}
2024-12-06 10:46:00 +00:00
[Button("清理缓存", ButtonSizes.Medium)]
private void ClearCache()
{
if (m_panelCache != null)
{
m_panelCache.ClearRotScaleInfos();
GlobalManager.Instance.SaveCache(m_prefab, m_panelCache);
}
}
2024-12-09 11:18:10 +00:00
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;
}
}
2024-10-28 16:31:38 +00:00
public override string GettitleContent()
2024-10-08 15:19:05 +00:00
{
2024-10-28 16:31:38 +00:00
return "请选择信息后开启助手";
}
public override void Init(WindowArgs args = null)
{
var _args = args as PanelCacheWindowArgs;
m_prefabStage = _args.stage;
m_prefab = AssetDatabase.LoadAssetAtPath<GameObject>(_args.stage.assetPath);
2024-12-09 11:18:10 +00:00
UpdatePanelCache();
2024-10-08 15:19:05 +00:00
}
2024-10-28 16:31:38 +00:00
public class PanelCacheWindowArgs : WindowArgs
2024-10-08 15:19:05 +00:00
{
2024-10-28 16:31:38 +00:00
public PrefabStage stage;
2024-10-08 15:19:05 +00:00
}
}
2024-10-23 17:30:59 +00:00
}
#endif