版本: Unity 6 (6000.0)
语言英语
  • C#

EditorApplication.timeSinceStartup

建议修改

成功!

感谢您帮助我们提高 Unity 文档的质量。虽然我们无法接受所有提交,但我们确实阅读了用户提出的每项修改建议,并在适用情况下进行更新。

关闭

提交失败

由于某些原因,您的修改建议无法提交。请<a>稍后再试</a>。感谢您抽出时间帮助我们提高 Unity 文档的质量。

关闭

取消

public static double timeSinceStartup;

描述

编辑器启动以来的时间。(只读)

此属性包含编辑器启动以来的时间(以秒为单位)。与Time.realtimeSinceStartup不同,它在启动播放模式时不会重置。

其他资源:Time.realtimeSinceStartup


每 300 秒保存当前场景的简单编辑器窗口。

// Simple editor window that autosaves the working Scene
// Make sure to have this window opened to be able to execute the auto save.

using UnityEngine; using UnityEditor; using UnityEngine.SceneManagement; using UnityEditor.SceneManagement;

public class SimpleAutoSave : EditorWindow { static float saveTime = 300.0f; static double nextSave = 0;

static int autoSaveLabel = 1;

[MenuItem("Examples/Simple autoSave")] static void Init() { SimpleAutoSave window = (SimpleAutoSave)GetWindowWithRect( typeof(SimpleAutoSave), new Rect(0, 0, 160, 60)); window.Show(); }

void OnGUI() { EditorGUI.LabelField(new Rect(10, 10, 80, 20), "Save Each:"); EditorGUI.LabelField(new Rect(80, 10, 80, 20), saveTime + " secs");

double timeToSave = nextSave - EditorApplication.timeSinceStartup;

EditorGUI.LabelField(new Rect(10, 30, 80, 20), "Next Save:"); EditorGUI.LabelField(new Rect(80, 30, 80, 20), timeToSave.ToString("N1") + " secs");

this.Repaint();

// when time has reach zero then save the Scene if (EditorApplication.timeSinceStartup > nextSave) { Scene scene = SceneManager.GetActiveScene(); string name = scene.name + autoSaveLabel;

EditorSceneManager.SaveScene(scene, "Assets/wibble/" + name + ".unity", true); autoSaveLabel = autoSaveLabel + 1; nextSave = EditorApplication.timeSinceStartup + saveTime;

Debug.Log("Saved Scene: " + name); } } }