fix:1、删除sdk相关。2、添加tips界面,修复bug
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ChillConnect.Editor
|
||||
{
|
||||
[System.Serializable]
|
||||
public class EditorLevelConfig
|
||||
{
|
||||
public int levelId;
|
||||
public string levelName;
|
||||
public int gridRows;
|
||||
public int gridCols;
|
||||
public int pointSpacing;
|
||||
public List<EditorArrowConfig> arrows;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class EditorArrowConfig
|
||||
{
|
||||
public int id;
|
||||
public int startPoint;
|
||||
public List<string> path;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class EditorAllLevelRoot
|
||||
{
|
||||
public List<EditorLevelConfig> levels;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9188e4d5fc904730b169ca235b32903b
|
||||
timeCreated: 1781601766
|
||||
@@ -0,0 +1,271 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
using ChillConnect;
|
||||
|
||||
namespace ChillConnect.Editor
|
||||
{
|
||||
public static class ArrowLevelGenerator
|
||||
{
|
||||
private const int MaxGenerateAttempts = 500; // 单关最大尝试次数
|
||||
private static readonly string[] Directions = { "up", "down", "left", "right" };
|
||||
|
||||
/// <summary>
|
||||
/// 生成单个关卡
|
||||
/// </summary>
|
||||
public static EditorLevelConfig GenerateLevel(int levelId, LevelDifficultyPreset preset)
|
||||
{
|
||||
for (int attempt = 0; attempt < MaxGenerateAttempts; attempt++)
|
||||
{
|
||||
EditorLevelConfig level = new EditorLevelConfig
|
||||
{
|
||||
levelId = levelId,
|
||||
levelName = $"第{levelId - 1000}关",
|
||||
gridRows = preset.gridRows,
|
||||
gridCols = preset.gridCols,
|
||||
pointSpacing = 60,
|
||||
arrows = new List<EditorArrowConfig>()
|
||||
};
|
||||
|
||||
bool[,] occupied = new bool[preset.gridRows, preset.gridCols];
|
||||
int arrowId = 1;
|
||||
int failedCount = 0;
|
||||
|
||||
// 逐个生成箭头,直到达到目标数量或多次失败
|
||||
while (level.arrows.Count < preset.arrowCount && failedCount < 100)
|
||||
{
|
||||
if (TryGenerateArrow(preset, occupied, level.gridRows, level.gridCols,
|
||||
out EditorArrowConfig arrow))
|
||||
{
|
||||
arrow.id = arrowId++;
|
||||
level.arrows.Add(arrow);
|
||||
|
||||
// 标记占用
|
||||
MarkOccupied(arrow, occupied, level.gridCols);
|
||||
}
|
||||
else
|
||||
{
|
||||
failedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
// 箭头数太少,放弃本次
|
||||
if (level.arrows.Count < preset.minArrowCount)
|
||||
continue;
|
||||
|
||||
// 可解性校验
|
||||
if (CheckSolvable(level))
|
||||
{
|
||||
return level;
|
||||
}
|
||||
}
|
||||
|
||||
Debug.LogWarning($"关卡 {levelId} 达到最大尝试次数仍未生成合格关卡");
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试生成单个合法箭头
|
||||
/// </summary>
|
||||
private static bool TryGenerateArrow(LevelDifficultyPreset preset, bool[,] occupied,
|
||||
int rows, int cols, out EditorArrowConfig arrow)
|
||||
{
|
||||
arrow = null;
|
||||
|
||||
// 随机起点
|
||||
int startRow = Random.Range(0, rows);
|
||||
int startCol = Random.Range(0, cols);
|
||||
if (occupied[startRow, startCol])
|
||||
return false;
|
||||
|
||||
// 随机路径长度和折数
|
||||
int pathLength = Random.Range(preset.minPathLength, preset.maxPathLength + 1);
|
||||
int maxTurns = preset.maxTurnCount;
|
||||
int turns = 0;
|
||||
|
||||
List<string> path = new List<string>();
|
||||
List<(int r, int c)> pathPoints = new List<(int r, int c)> { (startRow, startCol) };
|
||||
|
||||
string lastDir = Directions[Random.Range(0, Directions.Length)];
|
||||
int curRow = startRow;
|
||||
int curCol = startCol;
|
||||
|
||||
for (int i = 0; i < pathLength; i++)
|
||||
{
|
||||
string curDir = lastDir;
|
||||
|
||||
// 有概率转向
|
||||
if (i > 0 && turns < maxTurns && Random.value < preset.turnProbability)
|
||||
{
|
||||
// 随机换一个方向(不能回头)
|
||||
List<string> validDirs = new List<string>(Directions);
|
||||
validDirs.Remove(GetOppositeDir(lastDir));
|
||||
curDir = validDirs[Random.Range(0, validDirs.Count)];
|
||||
turns++;
|
||||
}
|
||||
|
||||
// 计算下一点
|
||||
(int nr, int nc) = MoveDir(curRow, curCol, curDir);
|
||||
|
||||
// 越界或已占用,终止
|
||||
if (nr < 0 || nr >= rows || nc < 0 || nc >= cols || occupied[nr, nc])
|
||||
break;
|
||||
|
||||
path.Add(curDir);
|
||||
pathPoints.Add((nr, nc));
|
||||
curRow = nr;
|
||||
curCol = nc;
|
||||
lastDir = curDir;
|
||||
}
|
||||
|
||||
// 路径太短,无效
|
||||
if (path.Count < 1)
|
||||
return false;
|
||||
|
||||
// 构造箭头
|
||||
arrow = new EditorArrowConfig
|
||||
{
|
||||
startPoint = startRow * cols + startCol,
|
||||
path = path
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 标记箭头占用的网格点
|
||||
/// </summary>
|
||||
private static void MarkOccupied(EditorArrowConfig arrow, bool[,] occupied, int totalCols)
|
||||
{
|
||||
int pointId = arrow.startPoint;
|
||||
int row = pointId / totalCols;
|
||||
int col = pointId % totalCols;
|
||||
occupied[row, col] = true;
|
||||
|
||||
foreach (string dir in arrow.path)
|
||||
{
|
||||
(row, col) = MoveDir(row, col, dir);
|
||||
occupied[row, col] = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 可解性校验:贪心模拟消除法
|
||||
/// </summary>
|
||||
public static bool CheckSolvable(EditorLevelConfig level)
|
||||
{
|
||||
int rows = level.gridRows;
|
||||
int cols = level.gridCols;
|
||||
|
||||
// 复制占用矩阵
|
||||
bool[,] occupied = new bool[rows, cols];
|
||||
foreach (var arrow in level.arrows)
|
||||
{
|
||||
MarkOccupied(arrow, occupied, cols);
|
||||
}
|
||||
|
||||
List<EditorArrowConfig> remaining = new List<EditorArrowConfig>(level.arrows);
|
||||
int roundCount = 0;
|
||||
const int maxRounds = 200;
|
||||
|
||||
while (remaining.Count > 0 && roundCount < maxRounds)
|
||||
{
|
||||
roundCount++;
|
||||
List<EditorArrowConfig> canRemove = new List<EditorArrowConfig>();
|
||||
|
||||
foreach (var arrow in remaining)
|
||||
{
|
||||
if (CanArrowFlyOut(arrow, occupied, rows, cols))
|
||||
{
|
||||
canRemove.Add(arrow);
|
||||
}
|
||||
}
|
||||
|
||||
if (canRemove.Count == 0)
|
||||
return false; // 死局
|
||||
|
||||
// 消除第一个可消除的箭头,释放占用
|
||||
var toRemove = canRemove[0];
|
||||
ReleaseOccupied(toRemove, occupied, cols);
|
||||
remaining.Remove(toRemove);
|
||||
}
|
||||
|
||||
return remaining.Count == 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断箭头是否能直接飞出(前方无阻挡)
|
||||
/// </summary>
|
||||
private static bool CanArrowFlyOut(EditorArrowConfig arrow, bool[,] occupied, int rows, int cols)
|
||||
{
|
||||
// 获取最终射出方向
|
||||
string finalDir = arrow.path[arrow.path.Count - 1];
|
||||
|
||||
// 获取箭头头部位置(路径终点)
|
||||
int pointId = arrow.startPoint;
|
||||
int row = pointId / cols;
|
||||
int col = pointId % cols;
|
||||
|
||||
foreach (string dir in arrow.path)
|
||||
{
|
||||
(row, col) = MoveDir(row, col, dir);
|
||||
}
|
||||
|
||||
// 沿射出方向一路检查到边界
|
||||
while (true)
|
||||
{
|
||||
(row, col) = MoveDir(row, col, finalDir);
|
||||
|
||||
if (row < 0 || row >= rows || col < 0 || col >= cols)
|
||||
return true; // 飞出边界
|
||||
|
||||
if (occupied[row, col])
|
||||
return false; // 前方有阻挡
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放箭头占用
|
||||
/// </summary>
|
||||
private static void ReleaseOccupied(EditorArrowConfig arrow, bool[,] occupied, int totalCols)
|
||||
{
|
||||
int pointId = arrow.startPoint;
|
||||
int row = pointId / totalCols;
|
||||
int col = pointId % totalCols;
|
||||
occupied[row, col] = false;
|
||||
|
||||
foreach (string dir in arrow.path)
|
||||
{
|
||||
(row, col) = MoveDir(row, col, dir);
|
||||
occupied[row, col] = false;
|
||||
}
|
||||
}
|
||||
|
||||
#region 工具方法
|
||||
private static (int r, int c) MoveDir(int row, int col, string dir)
|
||||
{
|
||||
switch (dir)
|
||||
{
|
||||
case "up": return (row - 1, col);
|
||||
case "down": return (row + 1, col);
|
||||
case "left": return (row, col - 1);
|
||||
case "right": return (row, col + 1);
|
||||
default: return (row, col);
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetOppositeDir(string dir)
|
||||
{
|
||||
switch (dir)
|
||||
{
|
||||
case "up": return "down";
|
||||
case "down": return "up";
|
||||
case "left": return "right";
|
||||
case "right": return "left";
|
||||
default: return dir;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f1de2afcf128468783594983d832f7a2
|
||||
timeCreated: 1781601376
|
||||
@@ -0,0 +1,106 @@
|
||||
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<EditorLevelConfig> _generatedLevels = new List<EditorLevelConfig>();
|
||||
|
||||
[MenuItem("Tools/箭头游戏/关卡生成器")]
|
||||
public static void ShowWindow()
|
||||
{
|
||||
GetWindow<ArrowLevelGeneratorWindow>("箭头关卡生成器");
|
||||
}
|
||||
|
||||
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}", "确定");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 338d551bc0c34285a64c42de35c20a1b
|
||||
timeCreated: 1781601358
|
||||
@@ -1,214 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public static class BatchAllLevelsToOneFile
|
||||
{
|
||||
// 全局网格配置(和游戏一致)
|
||||
private static int GridRows = 10;
|
||||
private static int GridCols = 10;
|
||||
private const int PointSpacing = 60;
|
||||
|
||||
// 关卡范围
|
||||
private const int StartLevelId = 1;
|
||||
private const int TotalLevelCount = 100;
|
||||
|
||||
// 颜色池、方向池
|
||||
private static readonly List<string> ColorPool = new List<string>
|
||||
{
|
||||
"#FF3333", "#3399FF", "#33FF66", "#FFFF33", "#CC66FF"
|
||||
};
|
||||
private static readonly List<string> DirPool = new List<string>
|
||||
{
|
||||
"up", "down", "left", "right"
|
||||
};
|
||||
|
||||
[MenuItem("关卡工具/生成全部100关 → 合并到单文件 all_levels.json")]
|
||||
public static void GenerateAllLevelsToOneJson()
|
||||
{
|
||||
AllLevelRoot root = new AllLevelRoot();
|
||||
root.levels = new List<LevelConfig>();
|
||||
|
||||
for (int i = 0; i < TotalLevelCount; i++)
|
||||
{
|
||||
int levelIndex = i + 1;
|
||||
GetGridSize(levelIndex);
|
||||
int currentLevelId = StartLevelId + i;
|
||||
int diffGroup = GetDifficultyGroup(levelIndex);
|
||||
|
||||
LevelConfig oneLevel = BuildOneLevel(currentLevelId, levelIndex, diffGroup);
|
||||
root.levels.Add(oneLevel);
|
||||
|
||||
Debug.Log($"已组装关卡: {currentLevelId}");
|
||||
}
|
||||
|
||||
// 写入单文件
|
||||
string savePath = Path.Combine(Application.streamingAssetsPath, "all_levels.json");
|
||||
string json = JsonUtility.ToJson(root, prettyPrint: true);
|
||||
File.WriteAllText(savePath, json);
|
||||
|
||||
EditorUtility.DisplayDialog("完成",
|
||||
$"共 {TotalLevelCount} 关已合并到单个文件\n路径: StreamingAssets/all_levels.json", "确定");
|
||||
}
|
||||
|
||||
|
||||
private static void GetGridSize(int levelIndex)
|
||||
{
|
||||
if (levelIndex <= 20)
|
||||
{
|
||||
GridRows = 10;
|
||||
GridCols = 10;
|
||||
}
|
||||
else if (levelIndex <= 40)
|
||||
{
|
||||
GridRows = 15;
|
||||
GridCols = 15;
|
||||
}
|
||||
else if (levelIndex <= 60)
|
||||
{
|
||||
GridRows = 20;
|
||||
GridCols = 20;
|
||||
}
|
||||
else if (levelIndex <= 80)
|
||||
{
|
||||
GridRows = 30;
|
||||
GridCols = 30;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 难度分组 1~5
|
||||
private static int GetDifficultyGroup(int levelIndex)
|
||||
{
|
||||
if (levelIndex <= 20) return 1;
|
||||
if (levelIndex <= 40) return 2;
|
||||
if (levelIndex <= 60) return 3;
|
||||
if (levelIndex <= 80) return 4;
|
||||
return 5;
|
||||
}
|
||||
|
||||
// 构建单关数据
|
||||
private static LevelConfig BuildOneLevel(int levelId, int levelIndex, int diffGroup)
|
||||
{
|
||||
LevelConfig cfg = new LevelConfig
|
||||
{
|
||||
levelId = levelId,
|
||||
levelName = $"第{levelIndex}关",
|
||||
gridRows = GridRows,
|
||||
gridCols = GridCols,
|
||||
pointSpacing = PointSpacing,
|
||||
arrows = new List<ArrowConfig>()
|
||||
};
|
||||
|
||||
int arrowCount = GetArrowCountByDiff(diffGroup);
|
||||
HashSet<int> usedPoints = new HashSet<int>();
|
||||
|
||||
for (int aIdx = 0; aIdx < arrowCount; aIdx++)
|
||||
{
|
||||
ArrowConfig arrow = CreateSingleArrow(diffGroup, usedPoints, aIdx + 1);
|
||||
cfg.arrows.Add(arrow);
|
||||
}
|
||||
return cfg;
|
||||
}
|
||||
|
||||
private static int GetArrowCountByDiff(int diff)
|
||||
{
|
||||
return diff switch
|
||||
{
|
||||
1 => Random.Range(3, 10),
|
||||
2 => Random.Range(5, 15),
|
||||
3 => Random.Range(7, 20),
|
||||
4 => Random.Range(10, 25),
|
||||
5 => Random.Range(15, 30),
|
||||
_ => 1
|
||||
};
|
||||
}
|
||||
|
||||
private static int GetPathLengthByDiff(int diff)
|
||||
{
|
||||
return diff switch
|
||||
{
|
||||
1 => 0,
|
||||
2 => Random.Range(3, 5),
|
||||
3 => Random.Range(3, 8),
|
||||
4 => Random.Range(3, 10),
|
||||
5 => Random.Range(3, 15),
|
||||
_ => 0
|
||||
};
|
||||
}
|
||||
|
||||
private static ArrowConfig CreateSingleArrow(int diff, HashSet<int> usedPoints, int arrowId)
|
||||
{
|
||||
ArrowConfig arrow = new ArrowConfig
|
||||
{
|
||||
id = arrowId,
|
||||
path = new List<string>(),
|
||||
color = ColorPool[Random.Range(0, ColorPool.Count)]
|
||||
};
|
||||
|
||||
int startPoint = GetRandomEmptyPoint(usedPoints);
|
||||
arrow.startPoint = startPoint;
|
||||
usedPoints.Add(startPoint);
|
||||
|
||||
int pathLen = GetPathLengthByDiff(diff);
|
||||
if (pathLen > 0)
|
||||
{
|
||||
arrow.path = GenerateRandomPath(pathLen);
|
||||
}
|
||||
|
||||
return arrow;
|
||||
}
|
||||
|
||||
private static List<string> GenerateRandomPath(int length)
|
||||
{
|
||||
List<string> path = new List<string>();
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
path.Add(DirPool[Random.Range(0, DirPool.Count)]);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
private static int GetRandomEmptyPoint(HashSet<int> used)
|
||||
{
|
||||
int maxPoint = GridRows * GridCols - 1;
|
||||
int pointId;
|
||||
do
|
||||
{
|
||||
pointId = Random.Range(0, maxPoint + 1);
|
||||
} while (used.Contains(pointId));
|
||||
return pointId;
|
||||
}
|
||||
|
||||
#region 序列化实体(新增根节点 + 原有关卡/箭头结构)
|
||||
[Serializable]
|
||||
public class AllLevelRoot
|
||||
{
|
||||
public List<LevelConfig> levels;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class LevelConfig
|
||||
{
|
||||
public int levelId;
|
||||
public string levelName;
|
||||
public int gridRows;
|
||||
public int gridCols;
|
||||
public int pointSpacing;
|
||||
public List<ArrowConfig> arrows;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class ArrowConfig
|
||||
{
|
||||
public int id;
|
||||
public int startPoint;
|
||||
public List<string> path;
|
||||
public string color;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: efc085dd10631ca48a50c72036c3514f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,35 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EditorTools
|
||||
{
|
||||
/// <summary>
|
||||
/// 编辑器内单个箭头数据
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class EditorArrowData
|
||||
{
|
||||
public int arrowId;
|
||||
public int startPoint;
|
||||
public int endPoint;
|
||||
public string colorHex = "#FFFFFF";
|
||||
public List<string> pathDirs = new List<string>();
|
||||
|
||||
// 路径点位序列 (ID列表)
|
||||
public List<int> pointIds = new List<int>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关卡总配置(编辑器用)
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class EditorLevelData
|
||||
{
|
||||
public int levelId = 1001;
|
||||
public string levelName = "可视化编辑关卡";
|
||||
public int gridRows = 10;
|
||||
public int gridCols = 10;
|
||||
public int pointSpacing = 60;
|
||||
public List<EditorArrowData> arrows = new List<EditorArrowData>();
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a26e6efd7d7cca34ab027117de8c8caf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,285 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EditorTools
|
||||
{
|
||||
public class GridPathEditorWindow : EditorWindow
|
||||
{
|
||||
private EditorLevelData _levelData = new EditorLevelData();
|
||||
|
||||
// 绘制区域参数
|
||||
private Vector2 _scrollPos;
|
||||
private const float CellSize = 24f;
|
||||
private const float DrawOffsetX = 20f;
|
||||
private const float DrawOffsetY = 20f;
|
||||
|
||||
// 当前正在编辑的箭头
|
||||
private int _curEditArrowIndex = -1;
|
||||
private List<int> _tempPathPoints = new List<int>();
|
||||
|
||||
// 颜色预设
|
||||
private readonly Color _gridLineColor = new Color(0.4f, 0.4f, 0.4f);
|
||||
private readonly Color _startCellColor = new Color(0.2f, 0.8f, 0.2f);
|
||||
private readonly Color _pathCellColor = new Color(0.2f, 0.5f, 1f);
|
||||
private readonly Color _endCellColor = new Color(1f, 0.4f, 0.2f);
|
||||
|
||||
[MenuItem("工具/网格路径配置编辑器")]
|
||||
public static void OpenWindow()
|
||||
{
|
||||
var win = GetWindow<GridPathEditorWindow>("网格路径编辑器");
|
||||
win.minSize = new Vector2(600, 500);
|
||||
win.Show();
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
EditorGUILayout.BeginVertical("Box");
|
||||
DrawLevelSetting();
|
||||
EditorGUILayout.Space();
|
||||
DrawArrowList();
|
||||
EditorGUILayout.Space();
|
||||
DrawGridCanvas();
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
|
||||
#region 1. 关卡基础设置
|
||||
private void DrawLevelSetting()
|
||||
{
|
||||
GUILayout.Label("【关卡基础设置】", EditorStyles.boldLabel);
|
||||
_levelData.levelId = EditorGUILayout.IntField("关卡ID", _levelData.levelId);
|
||||
_levelData.levelName = EditorGUILayout.TextField("关卡名称", _levelData.levelName);
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
_levelData.gridRows = EditorGUILayout.IntField("网格行数", _levelData.gridRows);
|
||||
_levelData.gridCols = EditorGUILayout.IntField("网格列数", _levelData.gridCols);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
_levelData.pointSpacing = EditorGUILayout.IntField("点位间距(px)", _levelData.pointSpacing);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button("➕ 新增箭头"))
|
||||
{
|
||||
AddNewArrow();
|
||||
}
|
||||
if (GUILayout.Button("💾 导出JSON"))
|
||||
{
|
||||
ExportJson();
|
||||
}
|
||||
if (GUILayout.Button("🗑️ 清空当前路径"))
|
||||
{
|
||||
_tempPathPoints.Clear();
|
||||
_curEditArrowIndex = -1;
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 2. 箭头列表
|
||||
private void DrawArrowList()
|
||||
{
|
||||
GUILayout.Label("【箭头列表(选中后绘制路径)】", EditorStyles.boldLabel);
|
||||
_scrollPos = EditorGUILayout.BeginScrollView(_scrollPos, GUILayout.Height(120));
|
||||
|
||||
for (int i = 0; i < _levelData.arrows.Count; i++)
|
||||
{
|
||||
var arrow = _levelData.arrows[i];
|
||||
EditorGUILayout.BeginHorizontal("Box");
|
||||
|
||||
if (GUILayout.Toggle(_curEditArrowIndex == i, $"ID:{arrow.arrowId}", GUILayout.Width(60)))
|
||||
{
|
||||
SelectArrow(i);
|
||||
}
|
||||
|
||||
arrow.colorHex = EditorGUILayout.TextField(arrow.colorHex, GUILayout.Width(80));
|
||||
EditorGUILayout.LabelField($"起点:{arrow.startPoint} 终点:{arrow.endPoint}", GUILayout.Width(160));
|
||||
|
||||
if (GUILayout.Button("删除", GUILayout.Width(50)))
|
||||
{
|
||||
_levelData.arrows.RemoveAt(i);
|
||||
if (_curEditArrowIndex >= _levelData.arrows.Count)
|
||||
_curEditArrowIndex = -1;
|
||||
break;
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
EditorGUILayout.EndScrollView();
|
||||
}
|
||||
|
||||
private void AddNewArrow()
|
||||
{
|
||||
int newId = _levelData.arrows.Count + 1;
|
||||
_levelData.arrows.Add(new EditorArrowData
|
||||
{
|
||||
arrowId = newId,
|
||||
colorHex = "#FFFFFF"
|
||||
});
|
||||
}
|
||||
|
||||
private void SelectArrow(int idx)
|
||||
{
|
||||
_curEditArrowIndex = idx;
|
||||
_tempPathPoints.Clear();
|
||||
var arr = _levelData.arrows[idx];
|
||||
_tempPathPoints.AddRange(arr.pointIds);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 3. 网格画布 + 点击选点
|
||||
private void DrawGridCanvas()
|
||||
{
|
||||
GUILayout.Label("【网格画布 - 点击格子绘制路径】", EditorStyles.boldLabel);
|
||||
|
||||
int rows = _levelData.gridRows;
|
||||
int cols = _levelData.gridCols;
|
||||
|
||||
Rect totalRect = EditorGUILayout.GetControlRect(false, (rows + 1) * CellSize);
|
||||
float startX = totalRect.x + DrawOffsetX;
|
||||
float startY = totalRect.y + DrawOffsetY;
|
||||
|
||||
// 绘制网格 + 监听点击
|
||||
for (int r = 0; r < rows; r++)
|
||||
{
|
||||
for (int c = 0; c < cols; c++)
|
||||
{
|
||||
int pointId = LevelJsonExporter.RowColToPointId(r, c, cols);
|
||||
Rect cellRect = new Rect(
|
||||
startX + c * CellSize,
|
||||
startY + r * CellSize,
|
||||
CellSize - 2,
|
||||
CellSize - 2
|
||||
);
|
||||
|
||||
// 格子背景色
|
||||
Color cellColor = Color.white;
|
||||
if (_tempPathPoints.Count > 0)
|
||||
{
|
||||
if (_tempPathPoints[0] == pointId)
|
||||
cellColor = _startCellColor;
|
||||
else if (_tempPathPoints[_tempPathPoints.Count - 1] == pointId)
|
||||
cellColor = _endCellColor;
|
||||
else if (_tempPathPoints.Contains(pointId))
|
||||
cellColor = _pathCellColor;
|
||||
}
|
||||
|
||||
// 绘制格子底色
|
||||
EditorGUI.DrawRect(cellRect, cellColor);
|
||||
|
||||
// ===== 纯GUI绘制边框,全版本通用 =====
|
||||
Color oldColor = GUI.color;
|
||||
GUI.color = _gridLineColor;
|
||||
// 上边框
|
||||
DrawLineGUI(new Vector2(cellRect.xMin, cellRect.yMin), new Vector2(cellRect.xMax, cellRect.yMin));
|
||||
// 右边框
|
||||
DrawLineGUI(new Vector2(cellRect.xMax, cellRect.yMin), new Vector2(cellRect.xMax, cellRect.yMax));
|
||||
// 下边框
|
||||
DrawLineGUI(new Vector2(cellRect.xMax, cellRect.yMax), new Vector2(cellRect.xMin, cellRect.yMax));
|
||||
// 左边框
|
||||
DrawLineGUI(new Vector2(cellRect.xMin, cellRect.yMax), new Vector2(cellRect.xMin, cellRect.yMin));
|
||||
GUI.color = oldColor;
|
||||
|
||||
// 点位ID文字
|
||||
GUI.color = Color.black;
|
||||
GUI.Label(cellRect, pointId.ToString(), EditorStyles.miniLabel);
|
||||
GUI.color = Color.white;
|
||||
|
||||
// 鼠标点击
|
||||
if (Event.current.type == EventType.MouseDown && cellRect.Contains(Event.current.mousePosition))
|
||||
{
|
||||
OnCellClick(pointId);
|
||||
Event.current.Use();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 纯GUI线条绘制(兼容所有Unity版本)
|
||||
private void DrawLineGUI(Vector2 p1, Vector2 p2)
|
||||
{
|
||||
Handles.color = GUI.color;
|
||||
Handles.DrawAAPolyLine(1, p1, p2);
|
||||
}
|
||||
|
||||
private void OnCellClick(int clickPointId)
|
||||
{
|
||||
// 必须先选中一个箭头才能画路径
|
||||
if (_curEditArrowIndex < 0 || _curEditArrowIndex >= _levelData.arrows.Count)
|
||||
{
|
||||
EditorUtility.DisplayDialog("提示", "请先在上方选中一个箭头", "确定");
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. 空路径 = 设为起点
|
||||
// 2. 已有点位 = 追加下一个路径点(只能相邻移动)
|
||||
if (_tempPathPoints.Count == 0)
|
||||
{
|
||||
_tempPathPoints.Add(clickPointId);
|
||||
}
|
||||
else
|
||||
{
|
||||
int lastId = _tempPathPoints[_tempPathPoints.Count - 1];
|
||||
if (IsAdjacent(lastId, clickPointId, _levelData.gridCols))
|
||||
{
|
||||
_tempPathPoints.Add(clickPointId);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorUtility.DisplayDialog("提示", "只能点击相邻格子!", "确定");
|
||||
}
|
||||
}
|
||||
|
||||
// 实时同步到当前箭头数据
|
||||
SyncTempPathToArrow();
|
||||
}
|
||||
|
||||
/// <summary>判断两个点位是否上下左右相邻</summary>
|
||||
private bool IsAdjacent(int idA, int idB, int totalCol)
|
||||
{
|
||||
LevelJsonExporter.PointIdToRowCol(idA, totalCol, out int r1, out int c1);
|
||||
LevelJsonExporter.PointIdToRowCol(idB, totalCol, out int r2, out int c2);
|
||||
|
||||
int dr = Mathf.Abs(r1 - r2);
|
||||
int dc = Mathf.Abs(c1 - c2);
|
||||
return (dr == 1 && dc == 0) || (dr == 0 && dc == 1);
|
||||
}
|
||||
|
||||
/// <summary>临时路径 → 箭头正式数据(自动生成direction、start/end)</summary>
|
||||
private void SyncTempPathToArrow()
|
||||
{
|
||||
var arrow = _levelData.arrows[_curEditArrowIndex];
|
||||
arrow.pointIds.Clear();
|
||||
arrow.pathDirs.Clear();
|
||||
|
||||
arrow.pointIds.AddRange(_tempPathPoints);
|
||||
if (_tempPathPoints.Count == 0) return;
|
||||
|
||||
arrow.startPoint = _tempPathPoints[0];
|
||||
arrow.endPoint = _tempPathPoints[_tempPathPoints.Count - 1];
|
||||
|
||||
// 逐段生成方向列表
|
||||
for (int i = 0; i < _tempPathPoints.Count - 1; i++)
|
||||
{
|
||||
string dir = LevelJsonExporter.GetDirection(_tempPathPoints[i], _tempPathPoints[i + 1], _levelData.gridCols);
|
||||
if (!string.IsNullOrEmpty(dir))
|
||||
arrow.pathDirs.Add(dir);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 4. 导出JSON
|
||||
private void ExportJson()
|
||||
{
|
||||
if (_levelData.arrows.Count == 0)
|
||||
{
|
||||
EditorUtility.DisplayDialog("提示", "暂无箭头数据", "确定");
|
||||
return;
|
||||
}
|
||||
|
||||
string json = LevelJsonExporter.BuildLevelJson(_levelData);
|
||||
LevelJsonExporter.SaveToStreamingAssets(json);
|
||||
EditorUtility.DisplayDialog("导出完成", "JSON 已生成到 StreamingAssets/level_1001.json", "确定");
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c9307857b7d4263a329a46d2dda9a31
|
||||
timeCreated: 1781254588
|
||||
@@ -0,0 +1,158 @@
|
||||
using ChillConnect;
|
||||
namespace ChillConnect.Editor
|
||||
{
|
||||
[System.Serializable]
|
||||
public class LevelDifficultyPreset
|
||||
{
|
||||
public int gridRows;
|
||||
public int gridCols;
|
||||
public int arrowCount; // 目标箭头数
|
||||
public int minArrowCount; // 最小接受箭头数
|
||||
public int minPathLength; // 单箭头最小长度(格数)
|
||||
public int maxPathLength; // 单箭头最大长度
|
||||
public int maxTurnCount; // 最大折数
|
||||
public float turnProbability; // 每步转向概率
|
||||
public bool isPatternLevel; // 是否图案关
|
||||
|
||||
/// <summary>
|
||||
/// 根据关卡序号(从1开始)获取对应难度预设
|
||||
/// </summary>
|
||||
public static LevelDifficultyPreset GetPreset(int levelIndex)
|
||||
{
|
||||
LevelDifficultyPreset preset = new LevelDifficultyPreset();
|
||||
|
||||
// ===== 第1-2关:起步适应 8x8 =====
|
||||
if (levelIndex <= 2)
|
||||
{
|
||||
preset.gridRows = 8;
|
||||
preset.gridCols = 8;
|
||||
preset.arrowCount = 7;
|
||||
preset.minArrowCount = 5;
|
||||
preset.minPathLength = 2;
|
||||
preset.maxPathLength = 4;
|
||||
preset.maxTurnCount = 0; // 纯直线
|
||||
preset.turnProbability = 0f;
|
||||
preset.isPatternLevel = false;
|
||||
}
|
||||
// ===== 第3关:难度突变 13x13 =====
|
||||
else if (levelIndex == 3)
|
||||
{
|
||||
preset.gridRows = 13;
|
||||
preset.gridCols = 13;
|
||||
preset.arrowCount = 14;
|
||||
preset.minArrowCount = 10;
|
||||
preset.minPathLength = 2;
|
||||
preset.maxPathLength = 5;
|
||||
preset.maxTurnCount = 0;
|
||||
preset.turnProbability = 0f;
|
||||
preset.isPatternLevel = false;
|
||||
}
|
||||
// ===== 第4关:第一个图案关 =====
|
||||
else if (levelIndex == 4)
|
||||
{
|
||||
preset.gridRows = 13;
|
||||
preset.gridCols = 13;
|
||||
preset.arrowCount = 12;
|
||||
preset.minArrowCount = 10;
|
||||
preset.minPathLength = 2;
|
||||
preset.maxPathLength = 6;
|
||||
preset.maxTurnCount = 0;
|
||||
preset.turnProbability = 0f;
|
||||
preset.isPatternLevel = true;
|
||||
}
|
||||
// ===== 第5-10关:快速跃升期 =====
|
||||
else if (levelIndex <= 10)
|
||||
{
|
||||
preset.gridRows = 13;
|
||||
preset.gridCols = 13;
|
||||
preset.arrowCount = 14 + (levelIndex - 5) * 1;
|
||||
preset.minArrowCount = preset.arrowCount - 3;
|
||||
preset.minPathLength = 2;
|
||||
preset.maxPathLength = 6;
|
||||
preset.maxTurnCount = 1;
|
||||
preset.turnProbability = 0.15f;
|
||||
preset.isPatternLevel = levelIndex == 8;
|
||||
}
|
||||
// ===== 第11-15关:进阶爬坡 =====
|
||||
else if (levelIndex <= 15)
|
||||
{
|
||||
preset.gridRows = 13;
|
||||
preset.gridCols = 13;
|
||||
preset.arrowCount = 20 + (levelIndex - 11);
|
||||
preset.minArrowCount = preset.arrowCount - 3;
|
||||
preset.minPathLength = 2;
|
||||
preset.maxPathLength = 7;
|
||||
preset.maxTurnCount = 1;
|
||||
preset.turnProbability = 0.2f;
|
||||
preset.isPatternLevel = levelIndex == 13;
|
||||
}
|
||||
// ===== 第15关突变:折数提升 =====
|
||||
else if (levelIndex <= 25)
|
||||
{
|
||||
preset.gridRows = 13;
|
||||
preset.gridCols = 13;
|
||||
preset.arrowCount = 22 + (levelIndex - 15);
|
||||
preset.minArrowCount = preset.arrowCount - 4;
|
||||
preset.minPathLength = 2;
|
||||
preset.maxPathLength = 7;
|
||||
preset.maxTurnCount = 2;
|
||||
preset.turnProbability = 0.25f;
|
||||
preset.isPatternLevel = levelIndex == 19;
|
||||
}
|
||||
// ===== 第26-35关 =====
|
||||
else if (levelIndex <= 35)
|
||||
{
|
||||
preset.gridRows = 14;
|
||||
preset.gridCols = 14;
|
||||
preset.arrowCount = 25 + (levelIndex - 26);
|
||||
preset.minArrowCount = preset.arrowCount - 4;
|
||||
preset.minPathLength = 2;
|
||||
preset.maxPathLength = 8;
|
||||
preset.maxTurnCount = 2;
|
||||
preset.turnProbability = 0.28f;
|
||||
preset.isPatternLevel = levelIndex == 26 || levelIndex == 33;
|
||||
}
|
||||
// ===== 第36-50关:高难起步 =====
|
||||
else if (levelIndex <= 50)
|
||||
{
|
||||
preset.gridRows = 14;
|
||||
preset.gridCols = 14;
|
||||
preset.arrowCount = 28 + (levelIndex - 36);
|
||||
preset.minArrowCount = preset.arrowCount - 5;
|
||||
preset.minPathLength = 2;
|
||||
preset.maxPathLength = 8;
|
||||
preset.maxTurnCount = 2;
|
||||
preset.turnProbability = 0.3f;
|
||||
preset.isPatternLevel = levelIndex == 41 || levelIndex == 49;
|
||||
}
|
||||
// ===== 第50关突变:15x15 =====
|
||||
else if (levelIndex <= 75)
|
||||
{
|
||||
preset.gridRows = 15;
|
||||
preset.gridCols = 15;
|
||||
preset.arrowCount = 30 + (levelIndex - 50) / 2;
|
||||
preset.minArrowCount = preset.arrowCount - 5;
|
||||
preset.minPathLength = 2;
|
||||
preset.maxPathLength = 9;
|
||||
preset.maxTurnCount = 3;
|
||||
preset.turnProbability = 0.32f;
|
||||
preset.isPatternLevel = levelIndex == 57 || levelIndex == 65 || levelIndex == 72;
|
||||
}
|
||||
// ===== 第76-100关:终极挑战 16x16 =====
|
||||
else
|
||||
{
|
||||
preset.gridRows = 16;
|
||||
preset.gridCols = 16;
|
||||
preset.arrowCount = 32 + (levelIndex - 75) / 3;
|
||||
preset.minArrowCount = preset.arrowCount - 6;
|
||||
preset.minPathLength = 2;
|
||||
preset.maxPathLength = 9;
|
||||
preset.maxTurnCount = 3;
|
||||
preset.turnProbability = 0.35f;
|
||||
preset.isPatternLevel = levelIndex == 80 || levelIndex == 87 || levelIndex == 93 || levelIndex == 100;
|
||||
}
|
||||
|
||||
return preset;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 67fd199fe89b44419a7b51e08285ba5a
|
||||
timeCreated: 1781601394
|
||||
@@ -1,106 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EditorTools
|
||||
{
|
||||
// 导出JSON 根实体
|
||||
[System.Serializable]
|
||||
public class ExportLevelRoot
|
||||
{
|
||||
public int levelId;
|
||||
public string levelName;
|
||||
public int gridRows;
|
||||
public int gridCols;
|
||||
public int pointSpacing;
|
||||
public List<ExportArrowItem> arrows;
|
||||
}
|
||||
|
||||
// 导出JSON 单条箭头实体
|
||||
[System.Serializable]
|
||||
public class ExportArrowItem
|
||||
{
|
||||
public int id;
|
||||
public int startPoint;
|
||||
public int endPoint;
|
||||
public string color;
|
||||
public List<string> path;
|
||||
}
|
||||
|
||||
public static class LevelJsonExporter
|
||||
{
|
||||
/// <summary>
|
||||
/// 行列转点位ID(和游戏代码完全一致)
|
||||
/// </summary>
|
||||
public static int RowColToPointId(int row, int col, int totalCol)
|
||||
{
|
||||
return row * totalCol + col;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 点位ID转行列(和游戏代码完全一致)
|
||||
/// </summary>
|
||||
public static void PointIdToRowCol(int pointId, int totalCol, out int row, out int col)
|
||||
{
|
||||
row = pointId / totalCol;
|
||||
col = pointId % totalCol;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据前后两个点位,计算移动方向
|
||||
/// </summary>
|
||||
public static string GetDirection(int fromId, int toId, int totalCol)
|
||||
{
|
||||
PointIdToRowCol(fromId, totalCol, out int fRow, out int fCol);
|
||||
PointIdToRowCol(toId, totalCol, out int tRow, out int tCol);
|
||||
|
||||
if (tRow < fRow) return "up";
|
||||
if (tRow > fRow) return "down";
|
||||
if (tCol < fCol) return "left";
|
||||
if (tCol > fCol) return "right";
|
||||
return "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成最终JSON字符串(纯实体类序列化,全版本兼容)
|
||||
/// </summary>
|
||||
public static string BuildLevelJson(EditorLevelData levelData)
|
||||
{
|
||||
ExportLevelRoot root = new ExportLevelRoot();
|
||||
root.levelId = levelData.levelId;
|
||||
root.levelName = levelData.levelName;
|
||||
root.gridRows = levelData.gridRows;
|
||||
root.gridCols = levelData.gridCols;
|
||||
root.pointSpacing = levelData.pointSpacing;
|
||||
|
||||
root.arrows = new List<ExportArrowItem>();
|
||||
foreach (var editorArr in levelData.arrows)
|
||||
{
|
||||
ExportArrowItem item = new ExportArrowItem();
|
||||
item.id = editorArr.arrowId;
|
||||
item.startPoint = editorArr.startPoint;
|
||||
item.endPoint = editorArr.endPoint;
|
||||
item.color = editorArr.colorHex;
|
||||
item.path = new List<string>(editorArr.pathDirs);
|
||||
root.arrows.Add(item);
|
||||
}
|
||||
|
||||
return JsonUtility.ToJson(root, prettyPrint: true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存JSON到StreamingAssets
|
||||
/// </summary>
|
||||
public static bool SaveToStreamingAssets(string json, string fileName = "level_1001.json")
|
||||
{
|
||||
string folder = Application.streamingAssetsPath;
|
||||
if (!Directory.Exists(folder))
|
||||
Directory.CreateDirectory(folder);
|
||||
|
||||
string fullPath = Path.Combine(folder, fileName);
|
||||
File.WriteAllText(fullPath, json);
|
||||
Debug.Log($"[导出成功] {fullPath}");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d01c5dd341d401bac259daf47388bee
|
||||
timeCreated: 1781254572
|
||||
Reference in New Issue
Block a user