2024-10-23 17:30:59 +00:00
|
|
|
|
#if UNITY_EDITOR
|
2024-11-04 18:05:34 +00:00
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
[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;
|
2024-11-04 18:05:34 +00:00
|
|
|
|
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
|
|
|
|
{
|
2024-11-04 18:05:34 +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-04 18:05:34 +00:00
|
|
|
|
if (m_panelCache == null)
|
2024-10-09 16:12:59 +00:00
|
|
|
|
{
|
2024-11-04 18:05:34 +00:00
|
|
|
|
var targetImgDirPath = PanelCache.GetTargetImgDirPath(m_layoutInfoFilePath);
|
2024-11-07 16:16:28 +00:00
|
|
|
|
float distanceDifference = GlobalManager.Instance.setting.distanceDifference;
|
|
|
|
|
CacheScriptObject.CalcRotScaleInfos(m_srcImgDirPath, targetImgDirPath, distanceDifference, (rotScaleInfos) =>
|
2024-11-04 18:05:34 +00:00
|
|
|
|
{
|
|
|
|
|
if (!stageManager) return;
|
2024-10-29 17:51:06 +00:00
|
|
|
|
|
2024-11-04 18:05:34 +00:00
|
|
|
|
var panelCache = new PanelCache(m_srcImgDirPath, m_layoutInfoFilePath);
|
2024-10-29 17:51:06 +00:00
|
|
|
|
|
2024-11-04 18:05:34 +00:00
|
|
|
|
panelCache.rotScaleInfos = rotScaleInfos;
|
|
|
|
|
panelCache.layoutInfo = CacheScriptObject.PaserLayout(m_layoutInfoFilePath, targetImgDirPath);
|
2024-10-21 16:20:39 +00:00
|
|
|
|
|
2024-11-04 18:05:34 +00:00
|
|
|
|
// 保存缓存
|
|
|
|
|
GlobalManager.Instance.SaveCache(m_prefab, panelCache);
|
2024-10-09 16:12:59 +00:00
|
|
|
|
|
2024-11-04 18:05:34 +00:00
|
|
|
|
var entityManager = stageManager.CreateSubManager<EntityManager>();
|
|
|
|
|
entityManager.InitAllEntity(panelCache);
|
2024-10-29 17:51:06 +00:00
|
|
|
|
|
2024-11-04 18:05:34 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
CloseWindow();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
var entityManager = stageManager.CreateSubManager<EntityManager>();
|
|
|
|
|
entityManager.InitAllEntity(m_panelCache);
|
|
|
|
|
CloseWindow();
|
2024-10-08 15:19:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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-10-08 15:19:05 +00:00
|
|
|
|
var cache = GlobalManager.Instance.cache;
|
2024-11-04 18:05:34 +00:00
|
|
|
|
if (cache.panelCaches.TryGetValue(m_prefab, out m_panelCache))
|
2024-10-08 15:19:05 +00:00
|
|
|
|
{
|
2024-11-04 18:05:34 +00:00
|
|
|
|
m_srcImgDirPath = m_panelCache.srcImgDirPath;
|
|
|
|
|
m_layoutInfoFilePath = m_panelCache.layoutInfoFilePath;
|
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
|