/// <summary>
        /// Unregisters the sub component.
        /// </summary>
        /// <param name="subComponent">Sub component.</param>
        public void UnregisterSubComponent(WindowObjectElement subComponent, System.Action callback = null)
        {
#if UNITY_EDITOR
            if (Application.isPlaying == false)
            {
                return;
            }
#endif

            var sendCallback = true;

            //Debug.Log("UNREGISTER: " + subComponent + " :: " + this.GetComponentState() + "/" + subComponent.GetComponentState());

            subComponent.rootComponent = null;
            this.subComponents.Remove(subComponent);

            switch (this.GetComponentState())
            {
            case WindowObjectState.Shown:

                // after OnShowEnd
                subComponent.OnWindowInactive();
                subComponent.DoHideBegin(AppearanceParameters.Default().ReplaceCallback(() => {
                    subComponent.DoHideEnd(AppearanceParameters.Default());
                    subComponent.DoDeinit();

                    if (callback != null)
                    {
                        callback();
                    }
                }));

                sendCallback = false;

                break;

            case WindowObjectState.Hiding:

                // after OnHideBegin
                subComponent.OnWindowInactive();
                subComponent.DoHideBegin(AppearanceParameters.Default());

                sendCallback = false;
                if (callback != null)
                {
                    callback();
                }

                break;

            case WindowObjectState.Hidden:

                // after OnHideEnd
                subComponent.OnWindowInactive();
                subComponent.DoHideBegin(AppearanceParameters.Default().ReplaceCallback(() => {
                    subComponent.DoHideEnd(AppearanceParameters.Default());
                    subComponent.DoDeinit();

                    if (callback != null)
                    {
                        callback();
                    }
                }));

                sendCallback = false;

                break;
            }

            if (sendCallback == true && callback != null)
            {
                callback();
            }
        }