diff --git a/DomainReloadTool.cs b/DomainReloadTool.cs new file mode 100644 index 0000000..5181070 --- /dev/null +++ b/DomainReloadTool.cs @@ -0,0 +1,79 @@ +using UnityEditor; +using UnityEditor.Compilation; +using UnityEngine; + +namespace DragonSoul.Editor; + +public class DomainReloadTool +{ + private const string logColor = "{0}"; + private const string ReloadKey = "DomainReloadTool.Reload"; + private const string ReloadDomainTimerKey = "DomainReloadTool.ReloadDomainTimer"; + private const string CompileDomainTimerKey = "DomainReloadTool.CompileDomainTimer"; + + [InitializeOnLoadMethod] + static void Init() + { + + CompilationPipeline.compilationStarted += OnCompilationStarted; + CompilationPipeline.compilationFinished += OnCompilationFinished; + + AssemblyReloadEvents.beforeAssemblyReload += OnBeforeAssemblyReload; + AssemblyReloadEvents.afterAssemblyReload += OnAfterAssemblyReload; + + EditorApplication.playModeStateChanged += EditorApplication_playModeStateChanged; + } + + private static void OnCompilationStarted(object obj) + { + + Debug.LogFormat(logColor, "Begin Compile Domain..."); + //记录时间 + SessionState.SetInt(CompileDomainTimerKey, (int)(EditorApplication.timeSinceStartup * 1000)); + } + private static void OnCompilationFinished(object obj) + { + var timeMS = (int)(EditorApplication.timeSinceStartup * 1000) - SessionState.GetInt(CompileDomainTimerKey, 0); + Debug.LogFormat(logColor, $"End Compile Domain : {timeMS} ms"); + } + + + private static void EditorApplication_playModeStateChanged(PlayModeStateChange state) + { + switch (state) + { + case PlayModeStateChange.ExitingEditMode: + if (!SessionState.GetBool(ReloadKey, false)) + ForceReloadDomain(); + break; + case PlayModeStateChange.EnteredPlayMode: + break; + case PlayModeStateChange.ExitingPlayMode: + SessionState.SetBool(ReloadKey, false); + break; + case PlayModeStateChange.EnteredEditMode: + break; + } + } + + //开始reload domain + private static void OnBeforeAssemblyReload() + { + Debug.LogFormat(logColor, "Begin Reload Domain..."); + //记录时间 + SessionState.SetInt(ReloadDomainTimerKey, (int)(EditorApplication.timeSinceStartup * 1000)); + } + + //结束reload domain + private static void OnAfterAssemblyReload() + { + var timeMS = (int)(EditorApplication.timeSinceStartup * 1000) - SessionState.GetInt(ReloadDomainTimerKey, 0); + Debug.LogFormat(logColor, $"End Reload Domain : {timeMS} ms"); + SessionState.SetBool(ReloadKey, true); + } + + private static void ForceReloadDomain() + { + EditorUtility.RequestScriptReload(); + } +} \ No newline at end of file diff --git a/NuGetForUnity.4.1.1.unitypackage b/NuGetForUnity.4.1.1.unitypackage new file mode 100644 index 0000000..679ff16 Binary files /dev/null and b/NuGetForUnity.4.1.1.unitypackage differ diff --git a/unity读取word excel pdf ppt.rar b/unity读取word excel pdf ppt.rar new file mode 100644 index 0000000..ef2c7b0 Binary files /dev/null and b/unity读取word excel pdf ppt.rar differ