/// <summary>
        /// Unregisters the sub component.
        /// </summary>
        /// <param name="subComponent">Sub component.</param>
        public virtual void UnregisterSubComponent(WindowObjectElement subComponent, System.Action callback = null, bool immediately = true)
        {
#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 (subComponent.GetComponentState())
            {
            case WindowObjectState.Showing:
            case WindowObjectState.Shown:

                // after OnShowEnd
                subComponent.DoWindowClose();
                subComponent.DoWindowInactive();
                subComponent.DoHideBegin(AppearanceParameters.Default().ReplaceForced(forced: true).ReplaceImmediately(immediately));
                subComponent.DoHideEnd(AppearanceParameters.Default().ReplaceForced(forced: true).ReplaceImmediately(immediately));
                subComponent.DoDeinit();

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

                break;

            case WindowObjectState.Hiding:

                // after OnHideBegin
                subComponent.DoWindowClose();
                subComponent.DoWindowInactive();
                subComponent.DoHideEnd(AppearanceParameters.Default().ReplaceForced(forced: true).ReplaceImmediately(immediately));
                subComponent.DoDeinit();

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

                break;

            case WindowObjectState.Hidden:

                // after OnHideEnd
                subComponent.DoWindowClose();
                subComponent.DoWindowInactive();
                subComponent.DoDeinit();

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

                break;
            }

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