using System; using System.Collections.Generic; using System.IO; using System.Linq; using Sirenix.OdinInspector; using Sirenix.OdinInspector.Editor; using UnityEditor; using UnityEngine; namespace Editor { public class LoadMapWindows : OdinEditorWindow { [MenuItem("Tools/LevelEditor")] private static void OpenWindow() { var loadMapWindow = GetWindow(); loadMapWindow.Show(); loadMapWindow.MapsList = new List(); List pathes = Directory.GetDirectories("Assets/Resources/Maps").ToList(); var editor = Transform.FindObjectOfType(); if (editor == null) { Debug.LogError("Не найден на сцене объект HexMapEditor"); return; } pathes.ForEach(x => { loadMapWindow.MapsList.Add(new Maps(x, editor, DeleteMap)); }); } [TableList(IsReadOnly = true, DrawScrollView = false, AlwaysExpanded = true, HideToolbar = true)] public List MapsList; private static void DeleteMap(Maps maps) { GetWindow().MapsList.Remove(maps); } public class Maps { private HexMapEditor _editor; private Action OnMapDeleted; public Maps(string path, HexMapEditor editor, Action onMapDeleted) { this.path = path; _editor = editor; OnMapDeleted += onMapDeleted; } [Button("Load")] public void LoadMap() { _editor.LoadMap(path); } [Button("Remove")] public void RemoveMap() { Directory.Delete(path, true); File.Delete($"{path}.meta"); AssetDatabase.Refresh(); OnMapDeleted.Invoke(this); } [InlineProperty()] public string path; } } }