unity每次编辑代码的时候,都需要保存,unity右下角的小圆圈总是转个不停,那么每次编辑代码后,unity到底需要多久时间呢,下面就有代码可以获取 保存时间。
using UnityEngine;
using UnityEditor;
using UnityEditor.Compilation;
[InitializeOnLoad]
public static class GetInitEditorTime
{
private static double _startTime;
static GetInitEditorTime()
{
CompilationPipeline.compilationStarted += OnCompilationStarted;
CompilationPipeline.compilationFinished += OnCompilationFinished;
}
static void OnCompilationStarted(object obj)
{
_startTime = EditorApplication.timeSinceStartup;
}
static void OnCompilationFinished(object obj)
{
double elapsedTime = EditorApplication.timeSinceStartup - _startTime;
Debug.Log($" script save time:{elapsedTime:F2} s");
}
}
保存结束的时候就可以打印保存的时间。