125 lines
4.5 KiB
C#
125 lines
4.5 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);
|
|
// 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);
|
|
panelCache.layoutInfo = CacheScriptObject.PaserLayout(m_layoutInfoFilePath, targetImgDirPath);
|
|
|
|
if (m_panelCache != null)
|
|
{
|
|
panelCache.rotScaleInfos = m_panelCache.rotScaleInfos;
|
|
panelCache.imgDirPathTimestamp = m_panelCache.imgDirPathTimestamp;
|
|
|
|
// 清理多余数据
|
|
panelCache.InitRotScaleInfos();
|
|
}
|
|
|
|
// 保存缓存
|
|
GlobalManager.Instance.SaveCache(m_prefab, panelCache);
|
|
|
|
var entityManager = stageManager.CreateSubManager<EntityManager>();
|
|
// stageManager.CreateSubManager<SelectionManager>();
|
|
|
|
entityManager.InitAllEntity(panelCache);
|
|
if (!string.IsNullOrEmpty(m_srcImgDirPath))
|
|
entityManager.AddCheckImgDirPath(m_srcImgDirPath);
|
|
CloseWindow();
|
|
}
|
|
|
|
[Button("清理缓存", ButtonSizes.Medium)]
|
|
private void ClearCache()
|
|
{
|
|
if (m_panelCache != null)
|
|
{
|
|
m_panelCache.ClearRotScaleInfos();
|
|
|
|
GlobalManager.Instance.SaveCache(m_prefab, m_panelCache);
|
|
}
|
|
}
|
|
|
|
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 |