コード例 #1
0
        /// <inheritdoc/>
        public void OnLayout()
        {
            // Swap onNextLayoutDelayed with an empty list before invoking actions in onNextLayout or
            // onNextLayoutDelayed. This is to avoid possible infinite loops and other problems if an
            // invoked action should add new actions to onNextLayoutDelayed.
            var applyTargeted = onNextLayoutDelayed;

            onNextLayoutDelayed           = onNextLayoutDelayedSwapTarget;
            onNextLayoutDelayedSwapTarget = applyTargeted;

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(onNextLayoutDelayed.Count == 0);
                        #endif

            if (onNextLayout != null)
            {
                                #if DEV_MODE && DEBUG_ON_NEXT_LAYOUT_DETAILED
                Debug.Log("Applying OnNextLayout Action: " + StringUtils.ToString(onNextLayout));
                                #endif

                // Copy onNextLayout to method-level variable and set it to null
                // before invoking the action. This is to avoid possible infinite loops
                // and other problems if an invoked action should add new actions to onNextLayout.
                //var apply = onNextLayout;
                //onNextLayout = null;
                //apply();

                var invocationList = onNextLayout.GetInvocationList();
                onNextLayout = null;
                Exception exception = null;
                for (int n = 0, count = invocationList.Length; n < count; n++)
                {
                    try
                    {
                        var invoke = invocationList[n] as Action;
                        invoke();
                    }
                    catch (Exception e)
                    {
                                                #if DEV_MODE
                        if (!ExitGUIUtility.IsExitGUIException(exception))
                        {
                            Debug.LogError(e);
                        }
                                                #endif

                        exception = e;
                    }
                }

                if (exception != null && ExitGUIUtility.ShouldRethrowException(exception))
                {
                    throw exception;
                }
            }

            int applyTargetedCount = applyTargeted.Count;
            if (applyTargetedCount > 0)
            {
                for (int n = 0; n < applyTargetedCount; n++)
                {
                    var apply = applyTargeted.Dequeue();

                                        #if DEV_MODE && DEBUG_ON_NEXT_LAYOUT_DETAILED
                    Debug.Log("Applying OnNextLayout DelayedAction: " + StringUtils.ToString(apply));
                                        #endif

                    // Only invoke targeted action if target drawers instance still exist.
                    apply.InvokeIfInstanceReferenceIsValid();
                }

                                #if DEV_MODE && PI_ASSERTATIONS
                Debug.Assert(applyTargeted.Count == 0);
                                #endif
            }

            if (keyHeldDown != KeyCode.None)
            {
                GUI.changed = true;
                if (Platform.Time > sendNextHoldEventAt)
                {
                    sendNextHoldEventAt = Platform.Time + KeyHoldSendEventInterval;
                    OnKeyDown(Event.KeyboardEvent(keyHeldDownName));
                }
            }
        }