Last active
January 4, 2020 16:50
-
-
Save mao-test-h/fca8eb21b743ba09c5d51f3816ab6a83 to your computer and use it in GitHub Desktop.
コンパイル時間計測 (Unity2018/2019対応版)
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
// referred to: | |
// http://baba-s.hatenablog.com/entry/2019/05/22/084000 | |
// https://forum.unity.com/threads/editorapplication-iscompiling-is-always-false.770126/ | |
using UnityEngine; | |
using UnityEditor; | |
#if UNITY_2019_1_OR_NEWER | |
using UnityEditor.Compilation; | |
#endif | |
namespace Tools.Editor | |
{ | |
[InitializeOnLoad] | |
class CompileTime : EditorWindow | |
{ | |
static bool isTrackingTime; | |
static double startTime; | |
static void ShowLog(ref double compileTime) | |
=> Debug.Log($"Script compilation time: \n {compileTime:0.000}s"); | |
#if UNITY_2019_1_OR_NEWER | |
static CompileTime() | |
{ | |
CompilationPipeline.compilationStarted += StartCompile; | |
CompilationPipeline.compilationFinished += FinishCompile; | |
} | |
static void StartCompile(object value) | |
{ | |
startTime = EditorApplication.timeSinceStartup; | |
} | |
static void FinishCompile(object value) | |
{ | |
var finishTime = EditorApplication.timeSinceStartup; | |
var compileTime = finishTime - startTime; | |
ShowLog(ref compileTime); | |
} | |
#else | |
static CompileTime() | |
{ | |
EditorApplication.update += Update; | |
startTime = EditorPrefs.GetFloat("CompileStartTime", 0); | |
if (startTime > 0) | |
{ | |
isTrackingTime = true; | |
} | |
} | |
static void Update() | |
{ | |
if (EditorApplication.isCompiling && !isTrackingTime) | |
{ | |
startTime = EditorApplication.timeSinceStartup; | |
EditorPrefs.SetFloat("CompileStartTime", (float) startTime); | |
isTrackingTime = true; | |
} | |
else if (!EditorApplication.isCompiling && isTrackingTime) | |
{ | |
var finishTime = EditorApplication.timeSinceStartup; | |
isTrackingTime = false; | |
var compileTime = finishTime - startTime; | |
EditorPrefs.DeleteKey("CompileStartTime"); | |
ShowLog(ref compileTime); | |
} | |
} | |
#endif | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment