/// <summary> /// Force the state to enter specific state /// </summary> /// <param name="newActivestate"></param> protected virtual void SetCurrentState(GameStateType newActivestate) { if (newActivestate == null) { return; } if (currentState != null) { currentState.OnExitState(); } currentState = newActivestate; newActivestate.OnEnterState(); OnStateChangeEvent?.Invoke(currentState); Debug.Log($"[{ToString()}]: Changed state to '{currentState}'"); }
public void ChangeState(PanelType targetType, bool addToStack = true) { if (isChangingState) { return; } if (targetType == currentType) { return; } if (addToStack) { panelStack.Push(currentType); } if (targetType == PanelType.HOMEPANEL) { panelStack.Clear(); } GUIPanel currentPanel = GetPanel(currentType); GUIPanel targetPanel = GetPanel(targetType); if (currentPanel != null && targetPanel != null && !targetPanel.isPopup || (currentPanel != null && currentPanel.isPopup)) { float waitTime = currentPanel.Hide(); if (waitTime != 0) { isChangingState = true; StartCoroutine(WaitForCurrentStateToHide(waitTime)); } } OnStateChangeEvent?.Invoke(currentType, targetType); previousType = currentType; currentType = targetType; if (!isChangingState) { OnCurrentStateHidden(); } }
public void AddStateChangeEvent(OnStateChangeEvent _event) { onStateChangeEvent += _event; }