using System.Collections.Generic; using System.IO; using UnityEditor; using UnityEngine; using ChillConnect; namespace ChillConnect.Editor { public class ArrowLevelGeneratorWindow : EditorWindow { private int _startLevelId = 1001; private int _generateCount = 100; private string _outputPath = "Assets/StreamingAssets/all_levels.json"; private Vector2 _scrollPos; private List _generatedLevels = new List(); [MenuItem("Tools/箭头游戏/关卡生成器")] public static void ShowWindow() { GetWindow("箭头关卡生成器"); } private void OnGUI() { GUILayout.Label("基础设置", EditorStyles.boldLabel); _startLevelId = EditorGUILayout.IntField("起始关卡ID", _startLevelId); _generateCount = EditorGUILayout.IntSlider("生成关卡数量", _generateCount, 1, 200); _outputPath = EditorGUILayout.TextField("输出路径", _outputPath); GUILayout.Space(10); if (GUILayout.Button("一键生成 100 关(含预设难度+图案关)", GUILayout.Height(40))) { GenerateAllLevels(); } GUILayout.Space(10); if (GUILayout.Button("导出到 JSON 文件")) { ExportToJson(); } GUILayout.Space(10); GUILayout.Label($"已生成关卡数:{_generatedLevels.Count}", EditorStyles.boldLabel); _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos); foreach (var level in _generatedLevels) { EditorGUILayout.LabelField( $"关卡 {level.levelId} | {level.gridRows}x{level.gridCols} | 箭头数:{level.arrows.Count}"); } EditorGUILayout.EndScrollView(); } private void GenerateAllLevels() { _generatedLevels.Clear(); int levelId = _startLevelId; for (int i = 0; i < _generateCount; i++) { // 获取当前关卡难度预设 var preset = LevelDifficultyPreset.GetPreset(i + 1); // 生成关卡 var level = ArrowLevelGenerator.GenerateLevel(levelId, preset); if (level != null) { _generatedLevels.Add(level); Debug.Log($"生成成功:关卡 {levelId},箭头数 {level.arrows.Count}"); } else { Debug.LogError($"关卡 {levelId} 生成失败,已跳过"); } levelId++; } EditorUtility.DisplayDialog("生成完成", $"成功生成 {_generatedLevels.Count} 个关卡", "确定"); } private void ExportToJson() { if (_generatedLevels.Count == 0) { EditorUtility.DisplayDialog("提示", "请先生成关卡", "确定"); return; } var root = new EditorAllLevelRoot { levels = _generatedLevels }; string json = JsonUtility.ToJson(root, true); string fullPath = Path.Combine(Application.dataPath, _outputPath.Replace("Assets/", "")); File.WriteAllText(fullPath, json); AssetDatabase.Refresh(); EditorUtility.DisplayDialog("导出成功", $"已导出到:{fullPath}", "确定"); } } }