Эх сурвалжийг харах

编辑器ctrlD功能兼容

wgl 7 сар өмнө
parent
commit
ec5e33ca65

+ 47 - 64
ActionTowerDefense/Assets/GameLevelEditor/GameMap/CoreScripts/Editor/GameMapEditor.cs

@@ -866,33 +866,55 @@ public class GameMapEditor : EditorWindow
 			EditorGUILayout.LabelField("Spawn Times", EditorStyles.boldLabel);
 			EditorGUILayout.LabelField("Spawn Times", EditorStyles.boldLabel);
 			GUILayout.Space(5f);
 			GUILayout.Space(5f);
 
 
-			List<SpawnTime> spawnTimes = layer.spawnTimes;
-			for(int i = 0; i < spawnTimes.Count; i++)
+			//List<SpawnTime> spawnTimes = layer.spawnTimes;
+			List<SpawnTime> spawnTimes = new List<SpawnTime>();
+			int[] grids = layer.grid;
+			for(int i = 0; i < grids.Length; i++)
             {
             {
-				SpawnTime spawnTime = spawnTimes[i];
-				if (asset.tileAsset.GetTile(spawnTime.id) == null) 
-				{
-					for (int j = 0; j < spawnTime.pos.Count; j++)
-					{
-						layer.grid[spawnTime.pos[j]] = -1;
-					}
-					spawnTimes.RemoveAt(i);
+				if(grids[i] == -1)
+                {
 					continue;
 					continue;
-				}
-				EditorGUILayout.LabelField($"{asset.tileAsset.GetTile(spawnTime.id).name} - {spawnTime.pos.Count}", EditorStyles.boldLabel);
-				spawnTime.startTime = EditorGUILayout.IntField("Start Time", spawnTime.startTime);
-				spawnTime.endTime = EditorGUILayout.IntField("End Time", spawnTime.endTime);
-				spawnTime.num = EditorGUILayout.IntField("Number", spawnTime.num);
-				spawnTimes[i] = spawnTime;
-				if (GUILayout.Button("Remove"))
-				{
-					for (int j = 0; j < spawnTime.pos.Count; j++)
-                    {
-						layer.grid[spawnTime.pos[j]] = -1;
-					}
-					spawnTimes.RemoveAt(i);
-				}
+                }
+				SpawnTime spawnTime = new SpawnTime();
+				if (spawnTimes.Exists(x => x.id == grids[i]))
+                {
+					spawnTime = spawnTimes.First(x => x.id == grids[i]);
+					spawnTime.pos.Add(i);
+                }
+                else
+                {
+					
+					spawnTime.id = grids[i];
+					spawnTime.pos = new List<int> { i};
+					spawnTimes.Add(spawnTime);
+                }
 			}
 			}
+            for (int i = 0; i < spawnTimes.Count; i++)
+            {
+                SpawnTime spawnTime = spawnTimes[i];
+                if (asset.tileAsset.GetTile(spawnTime.id) == null)
+                {
+                    for (int j = 0; j < spawnTime.pos.Count; j++)
+                    {
+                        layer.grid[spawnTime.pos[j]] = -1;
+                    }
+                    spawnTimes.RemoveAt(i);
+                    continue;
+                }
+                EditorGUILayout.LabelField($"{asset.tileAsset.GetTile(spawnTime.id).name} - {spawnTime.pos.Count}", EditorStyles.boldLabel);
+                spawnTime.startTime = EditorGUILayout.IntField("Start Time", spawnTime.startTime);
+                spawnTime.endTime = EditorGUILayout.IntField("End Time", spawnTime.endTime);
+                spawnTime.num = EditorGUILayout.IntField("Number", spawnTime.num);
+                spawnTimes[i] = spawnTime;
+                if (GUILayout.Button("Remove"))
+                {
+                    for (int j = 0; j < spawnTime.pos.Count; j++)
+                    {
+                        layer.grid[spawnTime.pos[j]] = -1;
+                    }
+                    spawnTimes.RemoveAt(i);
+                }
+            }
 
 
 
 
         }
         }
@@ -1593,47 +1615,8 @@ public class GameMapEditor : EditorWindow
 				{
 				{
                     if (currLayer >= 0)
                     if (currLayer >= 0)
                     {
                     {
-						//Undo.RecordObject(asset, id == -1 ? "Clear Tile" : "Place Tile");
-						int lastId = grid[idx];
+						Undo.RecordObject(asset, id == -1 ? "Clear Tile" : "Place Tile");
 						grid[idx] = id;
 						grid[idx] = id;
-
-						List<SpawnTime> spawnTimes = asset.maps[mapIdx].layers[currLayer].spawnTimes;
-						if(id == -1)
-                        {
-							for (int i = 0; i < spawnTimes.Count; i++)
-							{
-								if (spawnTimes[i].id == lastId)
-								{
-									spawnTimes[i].pos.Remove(idx);
-									if(spawnTimes[i].pos.Count <= 0)
-                                    {
-										spawnTimes.RemoveAt(i);
-                                    }
-									break;
-								}
-							}
-						}
-                        else
-                        {
-							bool hasFind = false;
-							for(int i = 0; i < spawnTimes.Count; i++)
-                            {
-								if(spawnTimes[i].id == id)
-                                {
-									spawnTimes[i].pos.Add(idx);
-									hasFind = true;
-									break;
-								}
-                            }
-                            if (!hasFind)
-                            {
-								SpawnTime spawnTime = new SpawnTime();
-								spawnTime.id = id;
-								spawnTime.pos = new List<int> { idx };
-								spawnTimes.Add(spawnTime);
-                            }
-                        }
-
 						doRepaint = true;
 						doRepaint = true;
 						GUI.changed = true;
 						GUI.changed = true;
 					}
 					}