using System; using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; using UnityEngine.UI; ///最上面 ///功能:扫描地图、打开地图、关闭地图、放弃设置 public class UIMapPanel : MonoBehaviour { public List allMaps = new List(); public Dropdown dropMap; private int _curOpenMapId; private bool _saving; public int CurOpenMapId => _curOpenMapId; // Start is called before the first frame update void Start() { _saving = false; _curOpenMapId = -1; UIWindow.Instance.uiCreateMap.onCreatedMapCallback += OnCreatedMap; } void OnDataLoaded() { string[] AllFilePath = Directory.GetDirectories(Application.dataPath + "/GameAssets/Maps"); for (int i = 0; i < AllFilePath.Length; i++) { string[] pathSplit = AllFilePath[i].Split('/'); string[] pathSplit2 = pathSplit[pathSplit.Length - 1].Split('\\'); allMaps.Add(pathSplit2[pathSplit2.Length - 1]); } } public void ScanMap() { allMaps.Clear(); OnDataLoaded(); dropMap.options.Clear(); for (int i=0; i 0) { UIWindow.Instance.ShowMessage("请先关闭已有地图"); return; } int mapId = 0; mapId = Convert.ToInt32(dropMap.options[dropMap.value].text); UIWindow.Instance.uiCreateMap.LoadMapRegions(mapId); UIWindow.Instance.uiCellInfo.LoadCells(); UIWindow.Instance.uiCellInfo.ShowCells(); UIWindow.Instance.uiEditMapConfig.LoadMapConfig(mapId); UIWindow.Instance.uiMonstersPanel.LoadMonsterConfig(mapId); UIWindow.Instance.uiNpcsPanel.LoadNpcsConfig(mapId); UIWindow.Instance.uiTriggersPanel.LoadTriggersConfig(mapId); UIWindow.Instance.uiFuBensPanel.LoadFuBenConfig(mapId); UIWindow.Instance.uiJuBaosPanel.LoadJuBaoConfig(mapId); _curOpenMapId = mapId; //MapManager.Instance.LoadMapSprite(); } public void CloseMap() { MapManager.Instance.CloseMap(); _curOpenMapId = -1; UIWindow.Instance.HideMouseOver(); } public bool HasMap(string mapId) { return allMaps.Find(s => s == mapId) != null; } public void ResetMap() { if (dropMap.options.Count == 0) { UIWindow.Instance.ShowMessage("请先扫描地图"); return; } if (_curOpenMapId < 0) { UIWindow.Instance.ShowMessage("没有地图"); return; } //先关闭地图 CloseMap(); UIWindow.Instance.uiEditMapConfig.Cleanup(); //再打开地图 OpenMap(); } private void Update() { if (Input.GetKey(KeyCode.LeftControl) && Input.GetKey(KeyCode.S)) { if (_saving) return; SaveAll(); } } public void SaveAll() { _saving = true; Debug.Log("正在保存所有数据..."); UIWindow.Instance.uiCreateMap.SaveRegions(); UIWindow.Instance.uiCellEditor.SaveCells(); UIWindow.Instance.uiEditMapConfig.SaveMapConfig(); UIWindow.Instance.uiMonstersPanel.SaveMonsterConfig(); UIWindow.Instance.uiNpcsPanel.SaveNpcsConfig(); UIWindow.Instance.uiTriggersPanel.SaveTriggersConfig(); UIWindow.Instance.uiJuBaosPanel.SaveJuBaoConfig(); UIWindow.Instance.uiFuBensPanel.SaveFuBenConfig(); UIWindow.Instance.ShowMessage("保存成功"); _saving = false; } }