public void CloseVM(VMBase instance, Action callback = null)
        {
            if (ActiveVMColl.Count == 0)
            {
                Debug.LogWarningFormat(instance, "{0} cannot be closed because VM list is empty", instance.GetType());
                return;
            }

            ActiveVMColl.Remove(instance);

            if (_toggleDebug)
            {
                Debug.Log("Close Top VM called, closing window: " + instance.GetType());
            }

            if (_closeVMColl.Contains(instance))
            {
                Debug.LogWarningFormat("Close VM list already contains window: " + instance.GetType());
                return;
            }

            _closeVMColl.Add(instance);

            if (_closeVMColl.Count >= 2)
            {
                return;
            }

            StartCloseVM(callback);
        }
        private void OnVMDestroyed(VMBase vm)
        {
            if (VMList == null)
            {
                return;
            }

            VMList.Remove(vm);
        }
        private void ONVMStateChanged(VMBase closedVM, EVMState curState)
        {
            if (!curState.Equals(EVMState.Deactive))
            {
                return;
            }

            StartCloseVM(null);
        }
        private void OnNewVMInitCompleted(VMBase vm)
        {
            if (VMList == null)
            {
                VMList = new List <VMBase>();
            }

            VMList.Add(vm);

            OnVMInitCompleted?.Invoke(vm);
        }
        private void Init()
        {
            if (_cachedViewModel == null)
            {
                _cachedViewModel = GetComponentInParent <VMBase>();
            }

            _cachedViewModel.OnPropertyChanged += OnPropertyChanged;

            _cachedVMProperty = BindingExtensions.GetPropertyInfoOf <TPLD>(_cachedViewModel);

            _propertyChangeValidator = new PropertyChangeValidator();
        }
        public bool IsAnyVMActive(params Type[] vmTypeCollection)
        {
            foreach (Type type in vmTypeCollection)
            {
                VMBase targetUI = ActiveVMColl.FirstOrDefault(val => val.GetType().Equals(type));

                if (targetUI != null)
                {
                    return(true);
                }
            }

            return(false);
        }
        public bool IsAnyVMActive(out List <VMBase> activeVMCollection, params Type[] vmTypeCollection)
        {
            activeVMCollection = new List <VMBase>();

            foreach (Type type in vmTypeCollection)
            {
                VMBase targetUI = ActiveVMColl.FirstOrDefault(val => val.GetType().Equals(type));

                if (targetUI != null)
                {
                    activeVMCollection.Add(targetUI);
                }
            }

            return(activeVMCollection.Count > 0);
        }
        private void Init()
        {
            if (_cachedViewModel == null)
            {
                _cachedViewModel = GetComponentInParent <VMBase>();
            }

            _cachedViewModel.OnPropertyChanged += OnPropertyChanged;

            _cachedViewModel.OnVMStateChanged += OnVMStateChanged;

            _cachedVMProperty = BindingExtensions.GetPropertyInfoOf <TPLD>(_cachedViewModel);

            _cachedMethodInfoColl = new Dictionary <string, MethodInfo>();
            foreach (string methodName in _viewModelMethodNameColl)
            {
                _cachedMethodInfoColl.Add(methodName, BindingExtensions.GetMethodInfoOf(_cachedViewModel, methodName));
            }

            _propertyChangeValidator = new PropertyChangeValidator();
        }
        public void OpenVM(VMBase vmRequestedToActivate)
        {
            if (ActiveVMColl.Contains(vmRequestedToActivate))
            {
                return;
            }

            if (ActiveVMColl.Count > 0)
            {
                if (vmRequestedToActivate.DisableVMsUnderneath)
                {
                    foreach (var underneathVM in ActiveVMColl)
                    {
                        if (underneathVM != vmRequestedToActivate)
                        {
                            _closeVMColl.Add(underneathVM);
                        }

                        if (underneathVM.DisableVMsUnderneath)
                        {
                            break;
                        }
                    }
                }

                vmRequestedToActivate.transform.SetAsLastSibling();
            }

            _nextOpeningVMColl.Add(vmRequestedToActivate);

            if (!_isDeactivationFinished)
            {
                return;
            }

            StartCloseVM(null);
        }