Version: 2020.3
언어: 한국어
public static bool SaveScene (SceneManagement.Scene scene, string dstScenePath= "", bool saveAsCopy= false);

파라미터

scene The Scene to be saved.
dstScenePath The file path to save the Scene to. If the path is empty, the current open Scene is overwritten. If it has not yet been saved at all, a save dialog is shown.
saveAsCopy If set to true, the Scene is saved without changing the current Scene, and without clearing the unsaved changes marker.

반환

bool True if the save succeeded, otherwise false.

설명

Save a Scene.

All paths are relative to the project folder, such as: "Assets/MyScenes/MyScene.unity". Folders specified in the path must already exist before calling the function. If no path is specified, the path of the current open Scene is used, except if it was never saved before, in which case a save dialog is shown.

The function returns false if the save failed. This can happen if the specified path is invalid or if the user cancels in the case of a save dialog.

See Also: EditorSceneManager.GetActiveScene

Example:
Simple Editor Window that saves each 300 seconds the current Scene.

Note: This saves the Scene whether it is marked dirty or not.

using UnityEditor;
using UnityEngine;
using System.Collections;
using UnityEditor.SceneManagement;

public class SimpleAutoSave : EditorWindow { public float saveTime = 300; public float nextSave = 0; [MenuItem("Example/Simple autoSave")] static void Init() { SimpleAutoSave window = (SimpleAutoSave)EditorWindow.GetWindowWithRect(typeof(SimpleAutoSave), new Rect(0, 0, 200, 50)); window.Show(); }

void OnGUI() { EditorGUILayout.LabelField("Save Each:", saveTime + " Secs"); float timeToSave = nextSave - (float)EditorApplication.timeSinceStartup; EditorGUILayout.LabelField("Next Save:", timeToSave.ToString() + " Sec"); Repaint(); if (EditorApplication.timeSinceStartup > nextSave) { string[] path = EditorSceneManager.GetActiveScene().path.Split(char.Parse("/")); path[path.Length - 1] = "AutoSave_" + path[path.Length - 1]; bool saveOK = EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene(), string.Join("/", path)); Debug.Log("Saved Scene " + (saveOK ? "OK" : "Error!")); nextSave = (float)EditorApplication.timeSinceStartup + saveTime; } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961