Переглянути джерело

关卡编辑器maps数量和出怪表sheet数量相对应

wgl 6 місяців тому
батько
коміт
665ecd438f

+ 12 - 2
ActionTowerDefense/Assets/GameLevelEditor/GameMap/CoreScripts/Editor/GameMapEdPopup.cs

@@ -69,7 +69,7 @@ public class GameMapEdPopup : PopupWindowContent
 				Undo.RecordObject(Asset, "Remove Game Map");
 				int key = list.index;
 				Asset.RemoveMapAtIndex(list.index);
-				contentRect = new Rect(0f, 18f, popupSz.x - 20f, Mathf.Max(popupSz.y - 18, EditorGUIUtility.singleLineHeight * Asset.maps.Count + 5));
+				ChangeContentRect();
 				if(key == 0)
                 {
 					OnMapSelected(0);
@@ -88,7 +88,7 @@ public class GameMapEdPopup : PopupWindowContent
 		{
 			Undo.RecordObject(Asset, "Add Game Map");
 			Asset.AddMap();
-			contentRect = new Rect(0f, 18f, popupSz.x - 20f, Mathf.Max(popupSz.y - 18, EditorGUIUtility.singleLineHeight * Asset.maps.Count + 5));
+			ChangeContentRect();
 			OnMapSelected(Asset.maps.Count - 1);
 		}
 	}
@@ -103,5 +103,15 @@ public class GameMapEdPopup : PopupWindowContent
 		OnMapSelected(list.index);
 	}
 
+	public void ChangeContentRect()
+    {
+		contentRect = new Rect(0f, 18f, popupSz.x - 20f, Mathf.Max(popupSz.y - 18, EditorGUIUtility.singleLineHeight * Asset.maps.Count + 5));
+	}
+
+	public void ChangeMapSelected(int id)
+    {
+		OnMapSelected(id);
+	}
+
 	// ----------------------------------------------------------------------------------------------------------------
 }

+ 45 - 14
ActionTowerDefense/Assets/GameLevelEditor/GameMap/CoreScripts/Editor/GameMapEditor.cs

@@ -4,7 +4,9 @@ using System.Collections.Generic;
 using UnityEngine;
 using UnityEditor;
 using System.Linq;
-
+using cfg;
+using SimpleJSON;
+using System.IO;
 
 public class GameMapEditor : EditorWindow
 {
@@ -120,7 +122,7 @@ public class GameMapEditor : EditorWindow
     private static readonly GUIContent GC_LayersHead = new GUIContent("波次");
     private static readonly GUIContent GC_TilesHead = new GUIContent("兵种");
 	private static readonly GUIContent GC_new = new GUIContent("new");
-	private static readonly GUIContent GC_rename = new GUIContent("ren", "Rename");
+	private static readonly GUIContent GC_rename = new GUIContent("rename");
 	private static readonly GUIContent GC_apply = new GUIContent("apply");
 	private static readonly GUIContent GC_clear = new GUIContent("x", "Clear tile selection. Draw empty tiles.");
 	private static readonly GUIContent GC_add = new GUIContent("+", "Add");
@@ -129,8 +131,8 @@ public class GameMapEditor : EditorWindow
 	private static readonly GUIContent GC_movR = new GUIContent(">", "Move selected");
 	private static readonly GUIContent GC_BackCol = new GUIContent("BackColor");
 	private static readonly GUIContent GC_GridCol = new GUIContent("GridColor");
-	private static readonly GUIContent GC_Solid = new GUIContent("Outside is Solid");
-	private static readonly GUIContent GC_AutoSz = new GUIContent("Auto-tile Size");
+	//private static readonly GUIContent GC_Solid = new GUIContent("Outside is Solid");
+	//private static readonly GUIContent GC_AutoSz = new GUIContent("Auto-tile Size");
 	private static readonly GUIContent GC_EditAuto = new GUIContent("Setup Auto-tile");
     private static readonly GUIContent GC_Viz = new GUIContent("*", "Toggle layer visblity in editor");
 
@@ -622,16 +624,7 @@ public class GameMapEditor : EditorWindow
 			r.x = r.xMax - 200f; r.width = 100f; r.height = 15f;
             if (GUI.Button(r, GC_ExcelReload))
             {
-				List<string> excelWorksheets = ExcelEditor.ReadExcelSheetsInfo(enemyExcelPath);
-				for (int i = 0; i < excelWorksheets.Count; i++)
-				{
-					asset.maps[i].ident = excelWorksheets[i];
-					int.TryParse(ExcelEditor.GetCellData(enemyExcelPath, excelWorksheets[i], "C6"), out int width);
-					int.TryParse(ExcelEditor.GetCellData(enemyExcelPath, excelWorksheets[i], "D6"), out int height);
-					asset.maps[i].Resize(width, height);
-				}
-				mapSize_w = asset.maps[mapIdx].width;
-				mapSize_h = asset.maps[mapIdx].height;
+				ReloadExcel(enemyExcelPath);
 			}
 			r.x = r.xMax; r.width = 100f; r.height = 15f;
 			if (GUI.Button(r, GC_MapSelect))
@@ -703,6 +696,44 @@ public class GameMapEditor : EditorWindow
 		EditorGUILayout.EndVertical();
 	}
 
+	private JSONNode Loader(string fileName)
+	{
+		return JSON.Parse(File.ReadAllText("GenerateDatas/json/" + fileName + ".json"));
+	}
+
+	private void ReloadExcel(string path)
+    {
+		List<string> excelWorksheets = ExcelEditor.ReadExcelSheetsInfo(path);
+		Tables allCfgData = new Tables(Loader);
+		List<SingleCreateEnemyConfig> cfgCreateEnemy = allCfgData.CfgCreateEnemy.DataList;
+
+        if (mapIdx >= excelWorksheets.Count)
+        {
+			mapsPopup.ChangeMapSelected(excelWorksheets.Count - 1);
+		}
+		if (asset.maps.Count > excelWorksheets.Count)
+        {
+			
+			for(int i = asset.maps.Count - 1; i>= excelWorksheets.Count; i--)
+            {
+				asset.RemoveMapAtIndex(i);
+            }
+        }
+		for (int i = 0; i < excelWorksheets.Count; i++)
+		{
+            if (i >= asset.maps.Count)
+            {
+				asset.AddMap();
+            }
+			asset.maps[i].ident = excelWorksheets[i];
+			int.TryParse(ExcelEditor.GetCellData(path, excelWorksheets[i], "C6"), out int width);
+			int.TryParse(ExcelEditor.GetCellData(path, excelWorksheets[i], "D6"), out int height);
+			asset.maps[i].Resize(width, height);
+		}
+		mapsPopup.ChangeContentRect();
+		mapSize_w = asset.maps[mapIdx].width;
+		mapSize_h = asset.maps[mapIdx].height;
+	}
 
 
 	private void OnMapSelected(int idx)

BIN
ActionTowerDefense/Luban/Config/Datas/出怪表.xlsx