Created
November 18, 2023 19:18
-
-
Save Cayahuanca/f2a50173c8417451fb5740db5e3e6378 to your computer and use it in GitHub Desktop.
Code to manually crash Unity Editor.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Diagnostics; | |
using UnityEditor; | |
using UnityEngine; | |
using UnityEngine.Diagnostics; | |
namespace Praecipua.EE | |
{ | |
public class UnityCrasher : EditorWindow | |
{ | |
[MenuItem("Window/Praecipua/[Danger] Crash Unity")] | |
static void ShowWindow() | |
{ | |
GetWindow<UnityCrasher>("Crash Unity"); | |
} | |
private void OnGUI() | |
{ | |
EditorGUILayout.Space(); | |
EditorGUILayout.LabelField("[Warning] This tools crashes Unity.", EditorStyles.boldLabel); | |
EditorGUILayout.Space(20); | |
if (GUILayout.Button("Access Violation")) | |
{ | |
Utils.ForceCrash(ForcedCrashCategory.AccessViolation); | |
} | |
EditorGUILayout.HelpBox("Cause a crash by performing an invalid memory access.\n無効なメモリアクセスを実行してクラッシュを引き起こします。", MessageType.Warning); | |
EditorGUILayout.Space(); | |
if (GUILayout.Button("Fatal Error")) | |
{ | |
Utils.ForceCrash(ForcedCrashCategory.FatalError); | |
} | |
EditorGUILayout.HelpBox("Cause a crash using Unity's native fatal error implementation.\nUnity の致命的なエラー実装を使用してクラッシュを引き起こします。", MessageType.Warning); | |
EditorGUILayout.Space(); | |
if (GUILayout.Button("Abort")) | |
{ | |
Utils.ForceCrash(ForcedCrashCategory.Abort); | |
} | |
EditorGUILayout.HelpBox("Cause a crash by calling the abort() function.\nabort() 関数を呼び出してクラッシュを引き起こします。", MessageType.Warning); | |
EditorGUILayout.Space(); | |
if (GUILayout.Button("Pure Virtual Function Call")) | |
{ | |
Utils.ForceCrash(ForcedCrashCategory.PureVirtualFunction); | |
} | |
EditorGUILayout.HelpBox("Cause a crash by calling a pure virtual function to raise an exception.\n純粋仮想関数を呼び出して例外を発生させることでクラッシュを引き起こします。", MessageType.Warning); | |
EditorGUILayout.Space(20); | |
if (GUILayout.Button("Native Assert")) | |
{ | |
Utils.NativeAssert("Native Assert called from UnityCrasher"); | |
} | |
EditorGUILayout.Space(); | |
if (GUILayout.Button("Native Error")) | |
{ | |
Utils.NativeError("Native Error called from UnityCrasher"); | |
} | |
EditorGUILayout.Space(); | |
if (GUILayout.Button("Native Log")) | |
{ | |
Utils.NativeWarning("Native Warning called from UnityCrasher"); | |
} | |
EditorGUILayout.Space(20); | |
if (GUILayout.Button("Open Unity Log File")) | |
{ | |
OpenLogFile(); | |
} | |
EditorGUILayout.Space(); | |
if (GUILayout.Button("Open Backuped Scene Directory")) | |
{ | |
OpenBuckupedSceneDir(); | |
} | |
EditorGUILayout.HelpBox("If you have never entered Play mode after starting Unity this time, a backup scene file will not be generated.\n今回の Unity 起動後に、Play モードに一度も入っていない場合、バックアップシーンファイルは生成されません。", MessageType.Info); | |
} | |
private void OpenLogFile() | |
{ | |
// Mac と Linux は非対応 | |
string logFilePath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData) + @"\Unity\Editor\Editor.log"; | |
try | |
{ | |
Process.Start(logFilePath); | |
} | |
catch (System.Exception e) | |
{ | |
UnityEngine.Debug.LogError("Failed to open log file: " + e.Message); | |
} | |
} | |
private void OpenBuckupedSceneDir() | |
{ | |
// Mac と Linux は非対応 | |
string projectFolderPath = Application.dataPath.Replace("/Assets", ""); | |
// Backup Scenes フォルダへのパス | |
string backupScenesFolderPath = System.IO.Path.Combine(projectFolderPath, "Temp", "__Backupscenes"); | |
try | |
{ | |
// フォルダをエクスプローラーで開く | |
Process.Start(backupScenesFolderPath); | |
} | |
catch (System.Exception e) | |
{ | |
UnityEngine.Debug.LogError("Failed to open folder: " + e.Message); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment