#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("是否竖版"), OnValueChanged(nameof(OnIsVerticalChanged)),SerializeField] private bool m_isVertical = false; [Title("psd导出数据设置")] [LabelText("项目中切图文件夹"), FolderPath, SerializeField] private string m_srcImgDirPath; [LabelText("layout.txt文件"), Sirenix.OdinInspector.FilePath(AbsolutePath = true, 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); var targetImgDirPath = PanelCache.GetTargetImgDirPath(m_layoutInfoFilePath); var panelCache = new PanelCache(m_layoutInfoFilePath, m_srcImgDirPath, m_isVertical); 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(); // stageManager.CreateSubManager(); 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); } } 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; } } 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); UpdatePanelCache(); } public class PanelCacheWindowArgs : WindowArgs { public PrefabStage stage; } } } #endif