Pārlūkot izejas kodu

编辑器波次编辑位置移动

wgl 7 mēneši atpakaļ
vecāks
revīzija
47a014204a

+ 85 - 16
ActionTowerDefense/Assets/GameLevelEditor/GameMap/CoreScripts/Editor/GameMapEditor.cs

@@ -3,6 +3,7 @@ using System.Reflection;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEditor;
+using System.Linq;
 
 public class GameMapEditor : EditorWindow
 {
@@ -190,13 +191,33 @@ public class GameMapEditor : EditorWindow
 
 		Undo.undoRedoPerformed -= OnUnRedo;
 		Undo.undoRedoPerformed += OnUnRedo;
+		ForceClearUndoStack();
 	}
 
 	private void OnDisable()
 	{
+		ForceClearUndoStack();
 		Undo.undoRedoPerformed -= OnUnRedo;
 	}
 
+	public static void ForceClearUndoStack()
+	{
+		// 创建临时对象
+		var tempObj = new GameObject("Undo_Cleaner");
+
+		// 记录临时对象的创建
+		Undo.RegisterCreatedObjectUndo(tempObj, "Create Cleaner");
+
+		// 立即销毁临时对象
+		Undo.DestroyObjectImmediate(tempObj);
+
+		// 清除撤销历史
+		Undo.ClearAll();
+
+		// 强制刷新撤销栈
+		Undo.IncrementCurrentGroup();
+	}
+
 	private void OnFocus()
 	{
 		wantsMouseMove = true;
@@ -844,22 +865,28 @@ public class GameMapEditor : EditorWindow
 		{
 			EditorGUILayout.LabelField("Spawn Times", EditorStyles.boldLabel);
 			GUILayout.Space(5f);
-			for (int i = 0; i < layer.spawnTimes.Count; i++)
-			{
-				SpawnTime spawnTime = layer.spawnTimes[i];
-				spawnTime.name = EditorGUILayout.TextField("Tile Name", layer.spawnTimes[i].name);
-				spawnTime.startTime = EditorGUILayout.IntField("Start Time", layer.spawnTimes[i].startTime);
-				spawnTime.endTime = EditorGUILayout.IntField("End Time", layer.spawnTimes[i].endTime);
-				spawnTime.num = EditorGUILayout.IntField("Number", layer.spawnTimes[i].num);
-				layer.spawnTimes[i] = spawnTime;
 
+			List<SpawnTime> spawnTimes = layer.spawnTimes;
+			for(int i = 0; i < spawnTimes.Count; i++)
+            {
+				SpawnTime spawnTime = spawnTimes[i];
+				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"))
 				{
-					layer.spawnTimes.RemoveAt(i);
-					i--;
+					for (int j = 0; j < spawnTime.pos.Count; j++)
+                    {
+						layer.grid[spawnTime.pos[j]] = -1;
+					}
+					spawnTimes.RemoveAt(i);
 				}
 			}
-		}
+
+
+        }
 		EditorGUILayout.EndVertical();
 
 
@@ -1510,9 +1537,9 @@ public class GameMapEditor : EditorWindow
 
 	private void GridClick(Rect mainRect, GameMap map, Event ev)
 	{
+		
         int[] grid = (currLayer < 0 ? map.grid : map.layers[currLayer].grid);
         int idx = MousePosToGridIdx(map, ev);
-
 		if (ev.modifiers == EventModifiers.Shift && ev.button == 0)
 		{   // mark tiles in grid
 			if (idx >= 0 && idx < grid.Length)
@@ -1555,10 +1582,52 @@ public class GameMapEditor : EditorWindow
 				if (ev.button == 0 && !autoTileSelected) id = (tileIdx >= 0 && tileIdx < asset.tileAsset.tiles.Count ? asset.tileAsset.tiles[tileIdx].id : -1);
 				if (grid[idx] != id)
 				{
-					Undo.RecordObject(asset, id == -1 ? "Clear Tile" : "Place Tile");
-					grid[idx] = id;
-					doRepaint = true;
-					GUI.changed = true;
+                    if (currLayer >= 0)
+                    {
+						//Undo.RecordObject(asset, id == -1 ? "Clear Tile" : "Place Tile");
+						int lastId = grid[idx];
+						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;
+						GUI.changed = true;
+					}
 				}
 			}
 		}

+ 3 - 2
ActionTowerDefense/Assets/GameLevelEditor/GameMap/CoreScripts/GameMapLayer.cs

@@ -4,7 +4,8 @@ using UnityEngine;
 [Serializable]
 public struct SpawnTime
 {
-	public string name;
+	public int id;
+	public List<int> pos;
 	public int startTime;
 	public int endTime;
 	public int num;
@@ -24,7 +25,7 @@ public class GameMapLayer
 	public float Hp = 1;
 	public float moveSpeed = 1;
 	public float attack = 1;
-	public List<SpawnTime> spawnTimes;
+	public List<SpawnTime> spawnTimes = new List<SpawnTime>();
 
 
 	// ----------------------------------------------------------------------------------------------------------------

+ 2 - 2
ActionTowerDefense/Assets/GameLevelEditor/GameMap/Sample/Scripts/Main.cs

@@ -38,8 +38,8 @@ public class Main : MonoBehaviour
 
 	private void Start()
 	{
-		refreshHasOut(0);
-		LoadMap(0);
+		//refreshHasOut(0);
+		//LoadMap(0);
 	}
 
     private void Update()

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
ActionTowerDefense/Assets/GameLevelEditor/maps.asset


+ 1 - 1
ActionTowerDefense/Assets/GameLevelEditor/tiles.asset

@@ -70,7 +70,7 @@ MonoBehaviour:
     radius: {x: 2, y: 0}
     name: "\u9053\u58EB"
     index: -1
-    hasOut: 1
+    hasOut: 0
     parameter:
       HP: 100
       MinMoveSpeed: 3

+ 32 - 32
ActionTowerDefense/Assets/Scripts/EnemyCreater.cs

@@ -15,7 +15,7 @@ public struct CreaterControl
     public GameMapLayer mapLayer;
     public SpawnTime spawnTime;
     public int waveStartTime;
-    public Vector3 pos;
+    public List<Vector3> pos;
 }
 
 
@@ -70,41 +70,36 @@ public class EnemyCreater : MonoBehaviour
         GameMap map = mapsAsset.maps[mapIdx];
 
         int startTime = 0;
-        
-        for (int i = 1; i < map.LayerCount; i++)
+
+        for (int i = 0; i < map.layers.Count(); i++)
         {
-            int[] grid = map.GetlayerData(i);
-            int idx = 0;
-            
-            for (int y = 0; y < map.height; y++)
+            GameMapLayer layer = map.layers[i];
+            List<SpawnTime> spawnTimes = layer.spawnTimes;
+            for(int j = 0; j < spawnTimes.Count; j++)
             {
-                for (int x = 0; x < map.width; x++)
+                SpawnTime spawnTime = layer.spawnTimes[i];
+                CreaterControl createrControl = new();
+                createrControl.isCreated = false;
+                GameMapTile t = mapsAsset.tileAsset.GetTile(spawnTime.id);
+                createrControl.tile = t;
+                createrControl.spawnTime = spawnTime;
+                createrControl.pos = new List<Vector3>();
+                for (int k = 0; k < spawnTime.pos.Count(); k++)
                 {
-                    
-                    GameMapTile t = mapsAsset.tileAsset.GetTile(grid[idx++]);
-                    if (t == null) continue;
-                    //foreach (SpawnTimeList spawnTimes in t.spawnTime)
-                    //{
-                    //    if (spawnTimes.curLayer == map.layers[i - 1].name)
-                    //    {
-                    //        for (int j = 0; j < spawnTimes.spawnTimes.Length; j++)
-                    //        {
-                    //            CreaterControl createrControl = new();
-                    //            createrControl.isCreated = false;
-                    //            createrControl.tile = t;
-                    //            createrControl.spawnTime = spawnTimes.spawnTimes[j];
-                    //            createrControl.pos = new Vector3(x + UnityEngine.Random.Range(-t.radius.x / 2, t.radius.x / 2), y + UnityEngine.Random.Range(-t.radius.y / 2, t.radius.y / 2), 0);
-                    //            createrControl.waveStartTime = startTime;
-                    //            createrControl.mapLayer = map.layers[i - 1];
-                    //            createCharacter.Add(createrControl);
-
-                    //        }
-                    //        break;
-                    //    }
-                    //}
+
+                    int posInt = spawnTime.pos[k];
+                    float posX = posInt % map.width;
+                    posX = posX + UnityEngine.Random.Range(-t.radius.x / 2, t.radius.x / 2);
+                    float posY = posInt / map.width;
+                    posY = posY + UnityEngine.Random.Range(-t.radius.y / 2, t.radius.y / 2);
+                    posY = posY < 0 ? 0 : posY;
+                    createrControl.pos.Add(new Vector3(posX, posY, 0));
                 }
+                createrControl.waveStartTime = startTime;
+                createrControl.mapLayer = layer;
+                createCharacter.Add(createrControl);
             }
-            startTime += map.layers[i - 1].duration;
+            startTime += map.layers[i].duration;
         }
     }
 
@@ -132,7 +127,12 @@ public class EnemyCreater : MonoBehaviour
                 return;
             }
             GameMapLayer gameMapLayer = createrControl.mapLayer;
-            CreateEnemy(createrControl.tile, createrControl.pos, gameMapLayer.Hp, gameMapLayer.moveSpeed, gameMapLayer.attack);
+            for(int j= 0; j < createrControl.pos.Count; j++)
+            {
+                CreateEnemy(createrControl.tile, createrControl.pos[j], gameMapLayer.Hp, gameMapLayer.moveSpeed, gameMapLayer.attack);
+
+            }
+           
             if(spawnTime.num == 1)
             {
                 return;

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels