Browse Source

报错保留原先数据

wgl 5 months ago
parent
commit
aa809c4502

+ 53 - 44
ActionTowerDefense/Assets/GameLevelEditor/GameMap/CoreScripts/Editor/GameMapEditor.cs

@@ -1035,57 +1035,66 @@ public class GameMapEditor : EditorWindow
 		{
 			EditorGUILayout.LabelField("Spawn Times", EditorStyles.boldLabel);
 			GUILayout.Space(5f);
-			int[] grids = layer.grid;
-			for(int i = 0; i < grids.Length; i++)
-            {
-				if(grids[i] == -1)
-                {
-					continue;
-                }
-				SpawnTime spawnTime = new SpawnTime();
-                if (newSpawnTimes.ContainsKey(grids[i]))
-                {
-					spawnTime = newSpawnTimes[grids[i]];
-					spawnTime.pos.Add(i);
-                }
-                else
-                {
-					spawnTime.id = grids[i];
-					spawnTime.pos = new List<int> { i };
-					newSpawnTimes.Add(grids[i], spawnTime);
-                }
-			}
-			
-            if (newSpawnTimes.Count >= 1)
-            {
-				Dictionary<int, SpawnTime> copyNewSpawnTime = new Dictionary<int, SpawnTime>(newSpawnTimes);
-				foreach(var item in copyNewSpawnTime)
-                {
-					SpawnTime newSpawnTime = item.Value;
-					EditorGUILayout.LabelField($"{asset.tileAsset.GetTile(newSpawnTime.id).name} - {newSpawnTime.pos.Count}", EditorStyles.boldLabel);
-                    if (layer.spawnTimes.ContainsKey(item.Key))
-                    {
-						newSpawnTime.startTime = EditorGUILayout.IntField("Start Time", layer.spawnTimes[item.Key].startTime);
-						newSpawnTime.endTime = EditorGUILayout.IntField("End Time", layer.spawnTimes[item.Key].endTime);
-						newSpawnTime.num = EditorGUILayout.IntField("Number", layer.spawnTimes[item.Key].num);
-                    }
-                    else
-                    {
-						newSpawnTime.startTime = EditorGUILayout.IntField("Start Time", 0);
-						newSpawnTime.endTime = EditorGUILayout.IntField("End Time", 0);
-						newSpawnTime.num = EditorGUILayout.IntField("Number", 0);
+			try
+			{
+				int[] grids = layer.grid;
+				for (int i = 0; i < grids.Length; i++)
+				{
+					if (grids[i] == -1)
+					{
+						continue;
+					}
+					SpawnTime spawnTime = new SpawnTime();
+					if (newSpawnTimes.ContainsKey(grids[i]))
+					{
+						spawnTime = newSpawnTimes[grids[i]];
+						spawnTime.pos.Add(i);
 					}
+					else
+					{
+						spawnTime.id = grids[i];
+						spawnTime.pos = new List<int> { i };
+						newSpawnTimes.Add(grids[i], spawnTime);
+					}
+				}
 
-					if (GUILayout.Button("Remove"))
+				if (newSpawnTimes.Count >= 1)
+				{
+					Dictionary<int, SpawnTime> copyNewSpawnTime = new Dictionary<int, SpawnTime>(newSpawnTimes);
+					foreach (var item in copyNewSpawnTime)
 					{
-						for (int j = 0; j < newSpawnTime.pos.Count; j++)
+						SpawnTime newSpawnTime = item.Value;
+						EditorGUILayout.LabelField($"{asset.tileAsset.GetTile(newSpawnTime.id).name} - {newSpawnTime.pos.Count}", EditorStyles.boldLabel);
+						if (layer.spawnTimes.ContainsKey(item.Key))
+						{
+							newSpawnTime.startTime = EditorGUILayout.IntField("Start Time", layer.spawnTimes[item.Key].startTime);
+							newSpawnTime.endTime = EditorGUILayout.IntField("End Time", layer.spawnTimes[item.Key].endTime);
+							newSpawnTime.num = EditorGUILayout.IntField("Number", layer.spawnTimes[item.Key].num);
+						}
+						else
+						{
+							newSpawnTime.startTime = EditorGUILayout.IntField("Start Time", 0);
+							newSpawnTime.endTime = EditorGUILayout.IntField("End Time", 0);
+							newSpawnTime.num = EditorGUILayout.IntField("Number", 0);
+						}
+
+						if (GUILayout.Button("Remove"))
 						{
-							layer.grid[newSpawnTime.pos[j]] = -1;
+							for (int j = 0; j < newSpawnTime.pos.Count; j++)
+							{
+								layer.grid[newSpawnTime.pos[j]] = -1;
+							}
 						}
+						newSpawnTimes[item.Key] = newSpawnTime;
 					}
-					newSpawnTimes[item.Key] = newSpawnTime;
 				}
-            }
+			}
+			catch (Exception e)
+            {
+				Debug.LogError(e);
+				newSpawnTimes = layer.spawnTimes;
+			}
+
         }
 		EditorGUILayout.EndVertical();