|
|
@@ -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;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|