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

89 lines
3.1 KiB
C#

#if UNITY_EDITOR
using System;
using System.Collections.Generic;
using System.IO;
using Sirenix.OdinInspector;
using Sirenix.OdinInspector.Editor;
using Unity.Mathematics;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
namespace UguiToolkit.Editor.Windows
{
public class PanelCacheWindow : BaseWindow<PanelCacheWindow>
{
[LabelText("源图片文件夹路径"), FolderPath, SerializeField]
private string m_srcImgDirPath;
[LabelText("目标图片信息文件(psd导出)"), Sirenix.OdinInspector.FilePath(Extensions = "layout.txt"), SerializeField]
private string m_layoutInfoFilePath;
private PrefabStage m_prefabStage;
private GameObject m_prefab;
private PanelCache m_panelCache;
[Button("开启助手", ButtonSizes.Medium)]
private void DoStart()
{
var stageManager = UguiToolkit.StageManager.CreateStageManager(m_prefabStage.scene, m_prefabStage.prefabContentsRoot, m_prefab);
stageManager.gameObject.AddComponent<UnityMainThreadDispatcher>();
// 打开编辑界面
EditWindow.ShowWindow(null);
if (m_panelCache == null)
{
var targetImgDirPath = PanelCache.GetTargetImgDirPath(m_layoutInfoFilePath);
CacheScriptObject.CalcRotScaleInfos(m_srcImgDirPath, targetImgDirPath, (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();
}
}
public override string GettitleContent()
{
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);
var cache = GlobalManager.Instance.cache;
if (cache.panelCaches.TryGetValue(m_prefab, out m_panelCache))
{
m_srcImgDirPath = m_panelCache.srcImgDirPath;
m_layoutInfoFilePath = m_panelCache.layoutInfoFilePath;
}
}
public class PanelCacheWindowArgs : WindowArgs
{
public PrefabStage stage;
}
}
}
#endif