Skip to content

Commit

Permalink
fix: handle back button for first state
Browse files Browse the repository at this point in the history
  • Loading branch information
HarrisonHough committed Jun 10, 2024
1 parent ac0d942 commit 43f7e0f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private void Initialize()

private void OnStateChanged(StateType current, StateType previous)
{
backButton.gameObject.SetActive(!CanShowBackButton(current));
backButton.gameObject.SetActive(current != startingState);
saveButton.gameObject.SetActive(current == StateType.Editor);

if (current == StateType.End)
Expand All @@ -112,11 +112,6 @@ private void OnStateChanged(StateType current, StateType previous)
}
}

private bool CanShowBackButton(StateType current)
{
return current == StateType.LoginWithCodeFromEmail || current == StateType.AvatarSelection;
}

public void OnCustomizeDraft(string avatarId)
{
StartOnCustomize(avatarId, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public abstract class StateMachine : MonoBehaviour

protected Action<StateType, StateType> StateChanged;
private StateType currentState;

protected void Initialize(List<State> states)
{
foreach (var state in states)
Expand All @@ -34,7 +34,7 @@ public void SetState(StateType stateType)
SetState(stateTypeMap[stateType].NextState);
return;
}

previousStates.Push(previousState);
}

Expand All @@ -56,7 +56,11 @@ public void GoToPreviousState()
var previousState = currentState;

DeactivateState(stateTypeMap[previousState]);


if (previousStates.Count == 0)
{
return;
}
currentState = previousStates.Pop();
if (currentState != StateType.None)
{
Expand All @@ -70,7 +74,7 @@ private void ActivateState(State state)
state.gameObject.SetActive(true);
state.ActivateState();
}

private void DeactivateState(State state)
{
state.gameObject.SetActive(false);
Expand Down

0 comments on commit 43f7e0f

Please sign in to comment.