#if UNITY_EDITOR using System; using UnityEditor; using UnityEngine; namespace FishNet.Editing { [InitializeOnLoad] public class PlayModeTracker { static PlayModeTracker() { EditorApplication.playModeStateChanged += OnPlayModeStateChanged; } ~PlayModeTracker() { EditorApplication.playModeStateChanged -= OnPlayModeStateChanged; } /// /// DateTime when the editor last exited playmode. /// private static DateTime _quitTime = DateTime.MaxValue; /// /// True if the editor has exited playmode within past. /// /// /// internal static bool QuitRecently(float past) { past *= 1000; return ((DateTime.Now - _quitTime).TotalMilliseconds < past); } private static void OnPlayModeStateChanged(PlayModeStateChange stateChange) { switch (stateChange) { case (PlayModeStateChange.ExitingPlayMode): _quitTime = DateTime.Now; break; } } } } #endif