Explorar el Código

波次命名;上下移动

wgl hace 7 meses
padre
commit
38b3fa8905

+ 37 - 2
ActionTowerDefense/Assets/GameLevelEditor/GameMap/CoreScripts/Editor/GameMapEditor.cs

@@ -745,7 +745,7 @@ public class GameMapEditor : EditorWindow
 
 				// 绘制图层列表
 				EditorGUILayout.Space();
-				for (int i = -1; i < asset.maps[mapIdx].layers.Length; i++)
+				for (int i = 0; i < asset.maps[mapIdx].layers.Length; i++)
 				{
 					DrawLayerEntry(i);
 				}
@@ -769,15 +769,50 @@ public class GameMapEditor : EditorWindow
 			layerHidden[idx + 1] = !GUILayout.Toggle(!layerHidden[idx + 1], GC_Viz, EditorStyles.miniButton, GUILayout.Width(25));
 
 			// 选择图层
-			if (GUILayout.Toggle((idx == currLayer), "Layer " + (idx + 1), EditorStyles.miniButton))
+			if (GUILayout.Toggle((idx == currLayer), asset.maps[mapIdx].layers[idx].name, EditorStyles.miniButton))
 			{
 				currLayer = idx;
 				doRepaint = true; // 触发重绘以显示图层信息
 			}
+
+			// 上移按钮
+			GUI.enabled = idx > 0; // 只有不是第一个图层时才能上移
+			if (GUILayout.Button("▲", EditorStyles.miniButtonLeft, GUILayout.Width(20)))
+			{
+				Undo.RecordObject(asset, "Move Layer Up");
+				SwapLayers(idx, idx - 1);
+				currLayer = idx - 1; // 更新当前选中图层
+				doRepaint = true;
+			}
+
+			// 下移按钮
+			GUI.enabled = idx < asset.maps[mapIdx].layers.Length - 1; // 只有不是最后一个图层时才能下移
+			if (GUILayout.Button("▼", EditorStyles.miniButtonRight, GUILayout.Width(20)))
+			{
+				Undo.RecordObject(asset, "Move Layer Down");
+				SwapLayers(idx, idx + 1);
+				currLayer = idx + 1; // 更新当前选中图层
+				doRepaint = true;
+			}
+			GUI.enabled = true; // 恢复按钮状态
 		}
 		EditorGUILayout.EndHorizontal();
 	}
 
+	private void SwapLayers(int indexA, int indexB)
+	{
+		if (indexA < 0 || indexB < 0 || indexA >= asset.maps[mapIdx].layers.Length || indexB >= asset.maps[mapIdx].layers.Length)
+			return;
+
+		// 交换两个图层
+		GameMapLayer temp = asset.maps[mapIdx].layers[indexA];
+		asset.maps[mapIdx].layers[indexA] = asset.maps[mapIdx].layers[indexB];
+		asset.maps[mapIdx].layers[indexB] = temp;
+
+		// 标记资源为脏数据,以便保存更改
+		EditorUtility.SetDirty(asset);
+	}
+
 	private void DrawLayerInfo(GameMapLayer layer)
 	{
 		EditorGUILayout.LabelField("Layer Information", EditorStyles.boldLabel);