#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 { [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(); // 打开编辑界面 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.InitAllEntity(panelCache); }); CloseWindow(); } else { var entityManager = stageManager.CreateSubManager(); 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(_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