Exemplo n.º 1
0
        internal static void BeginContainerGUI(GUILayoutUtility.LayoutCache cache, Event evt, IMGUIContainer container)
        {
            bool useOwnerObjectGUIState = container.useOwnerObjectGUIState;

            if (useOwnerObjectGUIState)
            {
                GUIUtility.BeginContainerFromOwner(container.elementPanel.ownerObject);
            }
            else
            {
                GUIUtility.BeginContainer(container.guiState);
            }
            UIElementsUtility.s_ContainerStack.Push(container);
            GUIUtility.s_SkinMode   = (int)container.contextType;
            GUIUtility.s_OriginalID = container.elementPanel.ownerObject.GetInstanceID();
            bool flag = Event.current == null;

            if (flag)
            {
                Event.current = evt;
            }
            else
            {
                Event.current.CopyFrom(evt);
            }
            bool flag2 = UIElementsUtility.s_BeginContainerCallback != null;

            if (flag2)
            {
                UIElementsUtility.s_BeginContainerCallback(container);
            }
            GUI.enabled = container.enabledInHierarchy;
            GUILayoutUtility.BeginContainer(cache);
            GUIUtility.ResetGlobalState();
        }
        static void OnGraphicsResourcesRecreate(bool recreate)
        {
            if (!recreate)
            {
                UIRenderDevice.PrepareForGfxDeviceRecreate();
            }

            var it = UIElementsUtility.GetPanelsIterator();

            while (it.MoveNext())
            {
                if (recreate)
                {
                    it.Current.Value.atlas?.Reset();
                }
                else
                {
                    (it.Current.Value.GetUpdater(VisualTreeUpdatePhase.Repaint) as UIRRepaintUpdater)?.DestroyRenderChain();
                }
            }

            if (!recreate)
            {
                UIRenderDevice.FlushAllPendingDeviceDisposes();
            }
            else
            {
                UIRenderDevice.WrapUpGfxDeviceRecreate();
            }
        }
Exemplo n.º 3
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }

            if (disposing)
            {
                if (panelDebug != null)
                {
                    panelDebug.DetachAllDebuggers();
                    panelDebug = null;
                }
                if (ownerObject != null)
                {
                    UIElementsUtility.RemoveCachedPanel(ownerObject.GetInstanceID());
                }
            }
            else
            {
                DisposeHelper.NotifyMissingDispose(this);
            }

            yogaConfig = null;
            disposed   = true;
        }
Exemplo n.º 4
0
        internal static void EndContainerGUI(Event evt, Rect layoutSize)
        {
            bool flag = Event.current.type == EventType.Layout && UIElementsUtility.s_ContainerStack.Count > 0;

            if (flag)
            {
                GUILayoutUtility.LayoutFromContainer(layoutSize.width, layoutSize.height);
            }
            GUILayoutUtility.SelectIDList(GUIUtility.s_OriginalID, false);
            GUIContent.ClearStaticCache();
            bool flag2 = UIElementsUtility.s_ContainerStack.Count > 0;

            if (flag2)
            {
                IMGUIContainer obj   = UIElementsUtility.s_ContainerStack.Peek();
                bool           flag3 = UIElementsUtility.s_EndContainerCallback != null;
                if (flag3)
                {
                    UIElementsUtility.s_EndContainerCallback(obj);
                }
            }
            evt.CopyFrom(Event.current);
            bool flag4 = UIElementsUtility.s_ContainerStack.Count > 0;

            if (flag4)
            {
                GUIUtility.EndContainer();
                UIElementsUtility.s_ContainerStack.Pop();
            }
        }
        static void SortPanels()
        {
            s_SortedRuntimePanels.Clear();
            UIElementsUtility.GetAllPanels(s_SortedRuntimePanels, ContextType.Player);

            s_SortedRuntimePanels.Sort((a, b) =>
            {
                var runtimePanelA = a as BaseRuntimePanel;
                var runtimePanelB = b as BaseRuntimePanel;

                if (runtimePanelA == null || runtimePanelB == null)
                {
                    // Should never happen, so just being safe (after all there's a cast happening).
                    return(0);
                }

                var diff = runtimePanelA.sortingPriority - runtimePanelB.sortingPriority;

                if (Mathf.Approximately(0, diff))
                {
                    // They're the same value, compare their count (panels created first show up first).
                    return(runtimePanelA.m_RuntimePanelCreationIndex.CompareTo(runtimePanelB.m_RuntimePanelCreationIndex));
                }

                return((diff < 0) ? -1 : 1);
            });

            s_PanelOrderingDirty = false;
        }
 private static void RegisterCachedPanelInternal(int instanceID, IPanel panel)
 {
     UIElementsUtility.RegisterCachedPanel(instanceID, panel as Panel);
     if (!s_RegisteredPlayerloopCallback)
     {
         s_RegisteredPlayerloopCallback = true;
         RegisterPlayerloopCallback();
     }
 }
 public static void DisposeRuntimePanel(ScriptableObject ownerObject)
 {
     Panel panel;
     if (UIElementsUtility.TryGetPanel(ownerObject.GetInstanceID(), out panel))
     {
         panel.Dispose();
         RemoveCachedPanelInternal(ownerObject.GetInstanceID());
     }
 }
Exemplo n.º 8
0
 void IUIElementsUtility.UpdateSchedulers()
 {
     UIElementsUtility.s_PanelsIterationList.Clear();
     UIElementsUtility.GetAllPanels(UIElementsUtility.s_PanelsIterationList, ContextType.Editor);
     foreach (Panel current in UIElementsUtility.s_PanelsIterationList)
     {
         current.timerEventScheduler.UpdateScheduledEvents();
         current.UpdateAnimations();
         current.UpdateBindings();
     }
 }
 private static void RemoveCachedPanelInternal(int instanceID)
 {
     UIElementsUtility.RemoveCachedPanel(instanceID);
     // un-register the playerloop callback as the last panel gets un-registered
     UIElementsUtility.GetAllPanels(panelsIteration, ContextType.Player);
     if (panelsIteration.Count == 0)
     {
         s_RegisteredPlayerloopCallback = false;
         UnregisterPlayerloopCallback();
     }
 }
Exemplo n.º 10
0
 private static void RegisterCachedPanelInternal(int instanceID, IPanel panel)
 {
     UIElementsUtility.RegisterCachedPanel(instanceID, panel as Panel);
     s_PanelOrderingDirty = true;
     if (!s_RegisteredPlayerloopCallback)
     {
         s_RegisteredPlayerloopCallback = true;
         RegisterPlayerloopCallback();
         Canvas.SetExternalCanvasEnabled(true);
     }
 }
Exemplo n.º 11
0
        private Vector2 GetTextureDisplaySize(Sprite sprite)
        {
            var result = Vector2.zero;

            if (sprite != null)
            {
                float scale = UIElementsUtility.PixelsPerUnitScaleForElement(this, sprite);
                result = (Vector2)(sprite.bounds.size * sprite.pixelsPerUnit) * scale;
            }
            return(result);
        }
Exemplo n.º 12
0
 public static void RepaintOverlayPanels()
 {
     UIElementsUtility.GetAllPanels(panelsIteration);
     foreach (var panel in panelsIteration)
     {
         // at the moment, all runtime panels who do not use a rendertexure are rendered as overlays.
         // later on, they'll be filtered based on render mode
         if (panel.contextType == ContextType.Player && (panel as RuntimePanel).targetTexture == null)
         {
             panel.Repaint(Event.current);
         }
     }
 }
 public static void RepaintOverlayPanels()
 {
     UIElementsUtility.GetAllPanels(panelsIteration, ContextType.Player);
     foreach (RuntimePanel panel in panelsIteration)
     {
         if (!panel.drawToCameras && panel.targetTexture == null)
         {
             using (s_RepaintProfilerMarker.Auto())
                 panel.Repaint(Event.current);
             (panel.panelDebug?.debuggerOverlayPanel as Panel)?.Repaint(Event.current);
         }
     }
 }
Exemplo n.º 14
0
 internal static void GetAllPanels(List <Panel> panels, ContextType contextType)
 {
     Dictionary <int, Panel> .Enumerator panelsIterator = UIElementsUtility.GetPanelsIterator();
     while (panelsIterator.MoveNext())
     {
         KeyValuePair <int, Panel> current = panelsIterator.Current;
         bool flag = current.Value.contextType == contextType;
         if (flag)
         {
             current = panelsIterator.Current;
             panels.Add(current.Value);
         }
     }
 }
Exemplo n.º 15
0
        void IUIElementsUtility.UpdateSchedulers()
        {
            // Since updating schedulers jumps into user code, the panels list might change while we're iterating,
            // we make a copy first.
            UIElementsUtility.GetAllPanels(s_PanelsIterationList, ContextType.Editor);

            foreach (var panel in s_PanelsIterationList)
            {
                // Dispatch all timer update messages to each scheduled item
                panel.timerEventScheduler.UpdateScheduledEvents();
                panel.UpdateAnimations();
                panel.UpdateBindings();
            }
        }
 public static void RepaintOverlayPanels()
 {
     UIElementsUtility.GetAllPanels(panelsIteration, ContextType.Player);
     foreach (var panel in panelsIteration)
     {
         // at the moment, all runtime panels who do not use a rendertexure are rendered as overlays.
         // later on, they'll be filtered based on render mode
         if ((panel as RuntimePanel).targetTexture == null)
         {
             using (s_RepaintProfilerMarker.Auto())
                 panel.Repaint(Event.current);
             (panel.panelDebug?.debuggerOverlayPanel as Panel)?.Repaint(Event.current);
         }
     }
 }
Exemplo n.º 17
0
        internal static Panel FindOrCreateEditorPanel(ScriptableObject ownerObject)
        {
            Panel panel;
            bool  flag = !UIElementsUtility.s_UIElementsCache.TryGetValue(ownerObject.GetInstanceID(), out panel);

            if (flag)
            {
                panel = Panel.CreateEditorPanel(ownerObject);
                UIElementsUtility.RegisterCachedPanel(ownerObject.GetInstanceID(), panel);
            }
            else
            {
                Debug.Assert(ContextType.Editor == panel.contextType, "Panel is not an editor panel.");
            }
            return(panel);
        }
Exemplo n.º 18
0
 void IUIElementsUtility.RequestRepaintForPanels(Action <ScriptableObject> repaintCallback)
 {
     Dictionary <int, Panel> .Enumerator panelsIterator = UIElementsUtility.GetPanelsIterator();
     while (panelsIterator.MoveNext())
     {
         KeyValuePair <int, Panel> current = panelsIterator.Current;
         Panel value = current.Value;
         bool  flag  = value.contextType != ContextType.Editor;
         if (!flag)
         {
             bool isDirty = value.isDirty;
             if (isDirty)
             {
                 repaintCallback(value.ownerObject);
             }
         }
     }
 }
Exemplo n.º 19
0
        static void SortPanels()
        {
            s_SortedRuntimePanels.Clear();
            UIElementsUtility.GetAllPanels(s_SortedRuntimePanels, ContextType.Player);

            s_SortedRuntimePanels.Sort((a, b) =>
            {
                var diff = a.sortingPriority - b.sortingPriority;

                if (Mathf.Approximately(0, diff))
                {
                    return(0);
                }

                return((diff < 0) ? -1 : 1);
            });

            s_PanelOrderingDirty = false;
        }
Exemplo n.º 20
0
        private static void RemoveCachedPanelInternal(int instanceID)
        {
            UIElementsUtility.RemoveCachedPanel(instanceID);

            s_PanelOrderingDirty = true;

            // We don't call GetSortedPanels() here to avoid always sorting when we remove multiple panels in a row
            // the ordering is dirty anyways, it will eventually get recreated
            s_SortedRuntimePanels.Clear();
            UIElementsUtility.GetAllPanels(s_SortedRuntimePanels, ContextType.Player);

            // un-register the playerloop callback as the last panel gets un-registered
            if (s_SortedRuntimePanels.Count == 0)
            {
                s_RegisteredPlayerloopCallback = false;
                UnregisterPlayerloopCallback();
                Canvas.SetExternalCanvasEnabled(false);
            }
        }
        public static IPanel FindOrCreateRuntimePanel(ScriptableObject ownerObject)
        {
            Panel panel;
            if (!UIElementsUtility.TryGetPanel(ownerObject.GetInstanceID(), out panel))
            {
                panel = new RuntimePanel(ownerObject, s_RuntimeDispatcher)
                {
                    IMGUIEventInterests = new EventInterests { wantsMouseMove = true, wantsMouseEnterLeaveWindow = true }
                };

                RegisterCachedPanelInternal(ownerObject.GetInstanceID(), panel);
            }
            else
            {
                Debug.Assert(ContextType.Player == panel.contextType, "Panel is not a runtime panel.");
            }

            return panel;
        }
Exemplo n.º 22
0
        public static BaseRuntimePanel FindOrCreateRuntimePanel(ScriptableObject ownerObject,
                                                                CreateRuntimePanelDelegate createDelegate)
        {
            if (UIElementsUtility.TryGetPanel(ownerObject.GetInstanceID(), out Panel cachedPanel))
            {
                if (cachedPanel is BaseRuntimePanel runtimePanel)
                {
                    return(runtimePanel);
                }
                RemoveCachedPanelInternal(ownerObject.GetInstanceID()); // Maybe throw exception instead?
            }

            var panel = createDelegate(ownerObject);

            panel.IMGUIEventInterests = new EventInterests {
                wantsMouseMove = true, wantsMouseEnterLeaveWindow = true
            };
            RegisterCachedPanelInternal(ownerObject.GetInstanceID(), panel);
            onCreatePanel?.Invoke(panel);
            return(panel);
        }
        void IUIElementsUtility.RequestRepaintForPanels(Action <ScriptableObject> repaintCallback)
        {
            var iterator = UIElementsUtility.GetPanelsIterator();

            while (iterator.MoveNext())
            {
                var panel = iterator.Current.Value;

                // Game panels' scheduler are ticked by the engine
                if (panel.contextType != ContextType.Editor)
                {
                    continue;
                }

                // Dispatch might have triggered a repaint request.
                if (panel.isDirty)
                {
                    repaintCallback(panel.ownerObject);
                }
            }
        }
Exemplo n.º 24
0
        private static bool DoDispatch(BaseVisualElementPanel panel)
        {
            bool result = false;
            bool flag   = UIElementsUtility.s_EventInstance.type == EventType.Repaint;

            if (flag)
            {
                using (UIElementsUtility.s_RepaintProfilerMarker.Auto())
                {
                    panel.Repaint(UIElementsUtility.s_EventInstance);
                }
                IPanelDebug expr_46 = panel.panelDebug;
                Panel       expr_57 = ((expr_46 != null) ? expr_46.debuggerOverlayPanel : null) as Panel;
                if (expr_57 != null)
                {
                    expr_57.Repaint(UIElementsUtility.s_EventInstance);
                }
                result = (panel.IMGUIContainersCount > 0);
            }
            else
            {
                panel.ValidateLayout();
                using (EventBase eventBase = UIElementsUtility.CreateEvent(UIElementsUtility.s_EventInstance))
                {
                    bool flag2 = UIElementsUtility.s_EventInstance.type == EventType.Used || UIElementsUtility.s_EventInstance.type == EventType.Layout || UIElementsUtility.s_EventInstance.type == EventType.ExecuteCommand || UIElementsUtility.s_EventInstance.type == EventType.ValidateCommand;
                    using (UIElementsUtility.s_EventProfilerMarker.Auto())
                    {
                        panel.SendEvent(eventBase, flag2 ? DispatchMode.Immediate : DispatchMode.Default);
                    }
                    bool isPropagationStopped = eventBase.isPropagationStopped;
                    if (isPropagationStopped)
                    {
                        panel.visualTree.IncrementVersion(VersionChangeType.Repaint);
                        result = true;
                    }
                }
            }
            return(result);
        }
Exemplo n.º 25
0
        bool IUIElementsUtility.ProcessEvent(int instanceID, IntPtr nativeEventPtr, ref bool eventHandled)
        {
            Panel panel;
            bool  flag = nativeEventPtr != IntPtr.Zero && UIElementsUtility.s_UIElementsCache.TryGetValue(instanceID, out panel);
            bool  result;

            if (flag)
            {
                bool flag2 = panel.contextType == ContextType.Editor;
                if (flag2)
                {
                    UIElementsUtility.s_EventInstance.CopyFromPtr(nativeEventPtr);
                    eventHandled = UIElementsUtility.DoDispatch(panel);
                }
                result = true;
            }
            else
            {
                result = false;
            }
            return(result);
        }
        private static void OnGraphicsResourcesRecreate(bool recreate)
        {
            bool flag = !recreate;

            if (flag)
            {
                UIRenderDevice.PrepareForGfxDeviceRecreate();
            }
            Dictionary <int, Panel> .Enumerator panelsIterator = UIElementsUtility.GetPanelsIterator();
            while (panelsIterator.MoveNext())
            {
                KeyValuePair <int, Panel> current = panelsIterator.Current;
                UIRRepaintUpdater         expr_32 = current.Value.GetUpdater(VisualTreeUpdatePhase.Repaint) as UIRRepaintUpdater;
                RenderChain renderChain           = (expr_32 != null) ? expr_32.renderChain : null;
                if (recreate)
                {
                    if (renderChain != null)
                    {
                        renderChain.AfterRenderDeviceRelease();
                    }
                }
                else if (renderChain != null)
                {
                    renderChain.BeforeRenderDeviceRelease();
                }
            }
            bool flag2 = !recreate;

            if (flag2)
            {
                UIRenderDevice.FlushAllPendingDeviceDisposes();
            }
            else
            {
                UIRenderDevice.WrapUpGfxDeviceRecreate();
            }
        }
        protected virtual void Dispose(bool disposing)
        {
            bool disposed = this.disposed;

            if (!disposed)
            {
                if (disposing)
                {
                    bool flag = this.panelDebug != null;
                    if (flag)
                    {
                        this.panelDebug.DetachAllDebuggers();
                        this.panelDebug = null;
                    }
                    bool flag2 = this.ownerObject != null;
                    if (flag2)
                    {
                        UIElementsUtility.RemoveCachedPanel(this.ownerObject.GetInstanceID());
                    }
                }
                this.yogaConfig = null;
                this.disposed   = true;
            }
        }
Exemplo n.º 28
0
        public void ReplayEvents(List <EventDebuggerEventRecord> eventBases)
        {
            if (eventBases == null)
            {
                return;
            }

            foreach (var eventBase in eventBases)
            {
                Event newEvent = new Event
                {
                    button        = eventBase.button,
                    clickCount    = eventBase.clickCount,
                    modifiers     = eventBase.modifiers,
                    mousePosition = eventBase.mousePosition,
                };

                if (eventBase.eventTypeId == MouseMoveEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.MouseMove;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.MouseMove), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == MouseDownEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.MouseDown;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.MouseDown), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == MouseUpEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.MouseUp;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.MouseUp), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == ContextClickEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.ContextClick;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.ContextClick), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == MouseEnterWindowEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.MouseEnterWindow;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.MouseEnterWindow), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == MouseLeaveWindowEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.MouseLeaveWindow;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.MouseLeaveWindow), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == WheelEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type  = EventType.ScrollWheel;
                    newEvent.delta = eventBase.delta;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.ScrollWheel), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == KeyDownEvent.TypeId())
                {
                    newEvent.type      = EventType.KeyDown;
                    newEvent.character = eventBase.character;
                    newEvent.keyCode   = eventBase.keyCode;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.KeyDown), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == KeyUpEvent.TypeId())
                {
                    newEvent.type      = EventType.KeyUp;
                    newEvent.character = eventBase.character;
                    newEvent.keyCode   = eventBase.keyCode;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.KeyUp), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == DragUpdatedEvent.TypeId())
                {
                    newEvent.type = EventType.DragUpdated;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.DragUpdated), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == DragPerformEvent.TypeId())
                {
                    newEvent.type = EventType.DragPerform;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.DragPerform), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == DragExitedEvent.TypeId())
                {
                    newEvent.type = EventType.DragExited;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.DragExited), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == ValidateCommandEvent.TypeId())
                {
                    newEvent.type        = EventType.ValidateCommand;
                    newEvent.commandName = eventBase.commandName;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.ValidateCommand), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == ExecuteCommandEvent.TypeId())
                {
                    newEvent.type        = EventType.ExecuteCommand;
                    newEvent.commandName = eventBase.commandName;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.ExecuteCommand), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == IMGUIEvent.TypeId())
                {
                    Debug.Log("Skipped IMGUI event (" + eventBase.eventBaseName + "): " + eventBase);
                    continue;
                }
                else
                {
                    Debug.Log("Skipped event (" + eventBase.eventBaseName + "): " + eventBase);
                    continue;
                }

                Debug.Log("Replayed event (" + eventBase.eventBaseName + "): " + newEvent);
            }
        }
 public static EventBase CreateEvent(Event systemEvent)
 {
     Debug.Assert(s_RuntimeDispatcher != null, "Call UIElementsRuntimeUtility.InitRuntimeEventSystem before sending any event.");
     return(UIElementsUtility.CreateEvent(systemEvent, systemEvent.rawType));
 }
Exemplo n.º 30
0
        private void DoOnGUI(Event evt, Matrix4x4 parentTransform, Rect clippingRect, bool isComputingLayout, Rect layoutSize, Action onGUIHandler, bool canAffectFocus = true)
        {
            // Extra checks are needed here because client code might have changed the IMGUIContainer
            // since we enter HandleIMGUIEvent()
            if (onGUIHandler == null ||
                panel == null)
            {
                return;
            }

            // Save the GUIClip count to make sanity checks after calling the OnGUI handler
            int guiClipCount = GUIClip.Internal_GetCount();

            SaveGlobals();

            // Save a copy of the container size.
            var previousMeasuredWidth  = layoutMeasuredWidth;
            var previousMeasuredHeight = layoutMeasuredHeight;

            UIElementsUtility.BeginContainerGUI(cache, evt, this);

            // For the IMGUI, we need to update the GUI.color with the actual play mode tint ...
            // In fact, this is taken from EditorGUIUtility.ResetGUIState().
            // Here, the play mode tint is either white (no tint, or not in play mode) or the right color (if in play mode)
            GUI.color = UIElementsUtility.editorPlayModeTintColor;
            // From now on, Event.current is either evt or a copy of evt.
            // Since Event.current may change while being processed, we do not rely on evt below but use Event.current instead.

            if (Event.current.type != EventType.Layout)
            {
                if (lostFocus)
                {
                    if (focusController != null)
                    {
                        // We dont want to clear the GUIUtility.keyboardControl if another IMGUIContainer
                        // just set it in the if (receivedFocus) block below. So we only clear it if own it.
                        if (GUIUtility.OwnsId(GUIUtility.keyboardControl))
                        {
                            GUIUtility.keyboardControl           = 0;
                            focusController.imguiKeyboardControl = 0;
                        }
                    }
                    lostFocus = false;
                }

                if (receivedFocus)
                {
                    if (hasFocusableControls)
                    {
                        if (focusChangeDirection != FocusChangeDirection.unspecified && focusChangeDirection != FocusChangeDirection.none)
                        {
                            // We got here by tabbing.

                            // We assume we are using the VisualElementFocusRing.
                            if (focusChangeDirection == VisualElementFocusChangeDirection.left)
                            {
                                GUIUtility.SetKeyboardControlToLastControlId();
                            }
                            else if (focusChangeDirection == VisualElementFocusChangeDirection.right)
                            {
                                GUIUtility.SetKeyboardControlToFirstControlId();
                            }
                        }
                        else if (GUIUtility.keyboardControl == 0 && m_IsFocusDelegated)
                        {
                            // Since GUIUtility.keyboardControl == 0, we got focused in some other way than by clicking inside us
                            // (for example it could be by clicking in an element that delegates focus to us).
                            // Give GUIUtility.keyboardControl to our first control.
                            GUIUtility.SetKeyboardControlToFirstControlId();
                        }
                    }

                    if (focusController != null)
                    {
                        if (focusController.imguiKeyboardControl != GUIUtility.keyboardControl && focusChangeDirection != FocusChangeDirection.unspecified)
                        {
                            newKeyboardFocusControlID = GUIUtility.keyboardControl;
                        }

                        focusController.imguiKeyboardControl = GUIUtility.keyboardControl;
                    }

                    receivedFocus        = false;
                    focusChangeDirection = FocusChangeDirection.unspecified;
                }
                // We intentionally don't send the NewKeyboardFocus command here since it creates an issue with the AutomatedWindow
                // newKeyboardFocusControlID = GUIUtility.keyboardControl;
            }

            EventType originalEventType = Event.current.type;

            bool isExitGUIException = false;

            try
            {
                using (new GUIClip.ParentClipScope(parentTransform, clippingRect))
                {
                    using (k_OnGUIMarker.Auto())
                    {
                        onGUIHandler();
                    }
                }
            }
            catch (Exception exception)
            {
                // only for layout events: we always intercept any exceptions to not interrupt event processing
                if (originalEventType == EventType.Layout)
                {
                    isExitGUIException = GUIUtility.IsExitGUIException(exception);
                    if (!isExitGUIException)
                    {
                        Debug.LogException(exception);
                    }
                }
                else
                {
                    // rethrow event if not in layout
                    throw;
                }
            }
            finally
            {
                if (Event.current.type != EventType.Layout && canAffectFocus)
                {
                    int currentKeyboardFocus = GUIUtility.keyboardControl;
                    int result = GUIUtility.CheckForTabEvent(Event.current);
                    if (focusController != null)
                    {
                        if (result < 0)
                        {
                            // If CheckForTabEvent returns -1 or -2, we have reach the end/beginning of its control list.
                            // We should switch the focus to the next VisualElement.
                            Focusable currentFocusedElement = focusController.GetLeafFocusedElement();
                            Focusable nextFocusedElement    = focusController.FocusNextInDirection(result == -1
                                ? VisualElementFocusChangeDirection.right
                                : VisualElementFocusChangeDirection.left);

                            if (currentFocusedElement == this)
                            {
                                if (nextFocusedElement == this)
                                {
                                    // We will still have the focus. We should cycle around our controls.
                                    if (result == -2)
                                    {
                                        GUIUtility.SetKeyboardControlToLastControlId();
                                    }
                                    else if (result == -1)
                                    {
                                        GUIUtility.SetKeyboardControlToFirstControlId();
                                    }

                                    newKeyboardFocusControlID            = GUIUtility.keyboardControl;
                                    focusController.imguiKeyboardControl = GUIUtility.keyboardControl;
                                }
                                else
                                {
                                    // We will lose the focus. Set the focused element ID to 0 until next
                                    // IMGUIContainer have a chance to set it to its own control.
                                    // Doing this will ensure we draw ourselves without any focused control.
                                    GUIUtility.keyboardControl           = 0;
                                    focusController.imguiKeyboardControl = 0;
                                }
                            }
                        }
                        else if (result > 0)
                        {
                            // A positive result indicates that the focused control has changed to one of our elements; result holds the control id.
                            focusController.imguiKeyboardControl = GUIUtility.keyboardControl;
                            newKeyboardFocusControlID            = GUIUtility.keyboardControl;
                        }
                        else if (result == 0)
                        {
                            // This means the event is not a tab. Synchronize our focus info with IMGUI.

                            if (originalEventType == EventType.MouseDown && !focusOnlyIfHasFocusableControls)
                            {
                                focusController.SyncIMGUIFocus(GUIUtility.keyboardControl, this, true);
                            }
                            else if ((currentKeyboardFocus != GUIUtility.keyboardControl) || (originalEventType == EventType.MouseDown))
                            {
                                focusController.SyncIMGUIFocus(GUIUtility.keyboardControl, this, false);
                            }
                            else if (GUIUtility.keyboardControl != focusController.imguiKeyboardControl)
                            {
                                // Here we want to resynchronize our internal state ...
                                newKeyboardFocusControlID = GUIUtility.keyboardControl;

                                if (focusController.GetLeafFocusedElement() == this)
                                {
                                    // In this case, the focused element is the right one in the Focus Controller... we are just updating the internal imguiKeyboardControl
                                    focusController.imguiKeyboardControl = GUIUtility.keyboardControl;
                                }
                                else
                                {
                                    // In this case, the focused element is NOT the right one in the Focus Controller... we also have to refocus...
                                    focusController.SyncIMGUIFocus(GUIUtility.keyboardControl, this, false);
                                }
                            }
                        }
                    }
                    // Cache the fact that we have focusable controls or not.
                    hasFocusableControls = GUIUtility.HasFocusableControls();
                }
            }

            // This will copy Event.current into evt.
            UIElementsUtility.EndContainerGUI(evt, layoutSize);
            RestoreGlobals();

            // See if the container size has changed. This is to make absolutely sure the VisualElement resizes
            // if the IMGUI content resizes.
            if (evt.type == EventType.Layout &&
                (!Mathf.Approximately(previousMeasuredWidth, layoutMeasuredWidth) || !Mathf.Approximately(previousMeasuredHeight, layoutMeasuredHeight)))
            {
                if (isComputingLayout && clippingRect == Rect.zero)
                {
                    this.schedule.Execute(() => IncrementVersion(VersionChangeType.Layout));
                }
                else
                {
                    IncrementVersion(VersionChangeType.Layout);
                }
            }

            if (!isExitGUIException)
            {
                // This is the same logic as GUIClipState::EndOnGUI
                if (evt.type != EventType.Ignore && evt.type != EventType.Used)
                {
                    int currentCount = GUIClip.Internal_GetCount();
                    if (currentCount > guiClipCount)
                    {
                        Debug.LogError("GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced.");
                    }
                    else if (currentCount < guiClipCount)
                    {
                        Debug.LogError("GUI Error: You are popping more GUIClips than you are pushing. Make sure they are balanced.");
                    }
                }
            }

            // Clear extraneous GUIClips
            while (GUIClip.Internal_GetCount() > guiClipCount)
            {
                GUIClip.Internal_Pop();
            }

            if (evt.type == EventType.Used)
            {
                IncrementVersion(VersionChangeType.Repaint);
            }
        }