private static void Initialize() { #if UNITY_EDITOR if (EditorApplication.isCompiling || EditorApplication.isUpdating) { EditorApplication.delayCall += Initialize; return; } #endif isQuitting = false; if (initialized) { return; } initialized = true; #if UNITY_EDITOR #if UNITY_2018_1_OR_NEWER EditorApplication.quitting += SetApplicationIsQuitting; #endif #else eventCatcher = InvisibleComponentProvider.GetOrCreate <MonoBehaviourEventCatcher>("ApplicationUtility/MonoBehaviourEventCatcher"); eventCatcher.OnApplicationQuitting += SetApplicationIsQuitting; #endif #if UNITY_EDITOR EditorApplication.update += UpdateApplicationHasFocus; #else eventCatcher.OnApplicationLostFocus += HandleOnApplicationLostFocus; eventCatcher.OnApplicationGainedFocus += HandleOnApplicationGainedFocus; #endif }
protected UnityEventFunctionsListener(UnityEventFunctions subscribeToEvents) { #if DEV_MODE && PI_ASSERTATIONS Debug.Assert(subscribeToEvents != UnityEventFunctions.None, GetType().Name); #endif if (eventCatcher == null) { eventCatcher = InvisibleComponentProvider.GetOrCreate <MonoBehaviourEventCatcher>("EventFunctionsListener/MonoBehaviourEventCatcher"); // can be null if application is quitting if (eventCatcher == null) { #if DEV_MODE && PI_ASSERTATIONS Debug.Assert(ApplicationUtility.IsQuitting); #endif return; } } subscribedEvents = subscribeToEvents; if (subscribedEvents.HasFlag(UnityEventFunctions.Update)) { eventCatcher.OnUpdate += Update; } if (subscribedEvents.HasFlag(UnityEventFunctions.OnApplicationQuit)) { eventCatcher.OnApplicationQuitting += OnApplicationQuit; } if (subscribedEvents.HasFlag(UnityEventFunctions.OnApplicationGainedFocus)) { eventCatcher.OnApplicationGainedFocus += OnApplicationGainedFocus; } if (subscribedEvents.HasFlag(UnityEventFunctions.OnApplicationLostFocus)) { eventCatcher.OnApplicationLostFocus += OnApplicationLostFocus; } }