这里如果能帮到你那就再好不过了
最近拼UI的时候按到撤回键,unity崩溃了?!我没绷住破口大骂。这个也是老问题了,unity在撤回创建物体(Create Cude 这种)就会崩溃,这个问题已经吞掉我几个UI了。
找了撤销的资料来研究,写了一个脚本,在检测到创建物体等操作时,会直接清除撤销历史(反正你撤销了也会崩溃)
using UnityEditor;
using UnityEngine;
using static UnityEditor.Undo;
[InitializeOnLoad]
public class CustomUndo : MonoBehaviour
{
static CustomUndo()
{
EditorApplication.hierarchyChanged += PerformUndoWithConfirmation;
}
private static void PerformUndoWithConfirmation()
{
if (Undo.GetCurrentGroupName().Contains("Create ")|| Undo.GetCurrentGroupName().Contains("Paste "))
{
Undo.ClearAll();
}
}
}
这是效果,你把ctrl+z按烂都不会崩溃了