Version: 2020.2
public static void Exit (int returnValue);

描述

退出 Unity 编辑器应用程序。

调用此函数将立即退出,而不要求保存更改,因此您可能会丢失数据! 此函数对于退出发生特定错误的命令行进程极为有用。


另请参阅:Unity 命令行参数

// Simple script that lets you create a new
// Scene, create a cube and an empty game object in the Scene
// Save the Scene and close the editor

using UnityEditor; using UnityEditor.SceneManagement;

public class ExampleClass { [MenuItem("Examples/Chain Actions and close")] static void EditorPlaying() { var newScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);

EditorApplication.ExecuteMenuItem("GameObject/3D Object/Cube"); EditorApplication.ExecuteMenuItem("GameObject/Create Empty");

EditorSceneManager.SaveScene(newScene, "Assets/MyNewScene.unity"); EditorApplication.Exit(0); } }