Game States and Screens
In short
The game is always in exactly one
GameState.UIRoot.OnGUIdraws the matching view; the 3D scene behind it is set up by whoever changed the state. Overlays (dev menu, NET TEST, Fit Mode, settings popups, pause, fade, FPS counter) are drawn by their owners on top.
How it works
States and views
GameState | View class | What it shows | Entered by |
|---|---|---|---|
MainMenu | MainMenuView | Title screen: top bar, leaderboards, daily challenge, batter, mode card, PLAY! / CONTINUE / PLAY CO-OP. | GameRoot.GoToMainMenu |
MapSelect | MapSelectView | Pick a map and difficulty; PLAY BALL! starts a solo run. | GameRoot.OpenMapSelect |
RunMap | RunMapView (+ BuildPanel) | Between innings: the inning, its pitcher, goal, PLAY BALL!, SAVE & QUIT / ABANDON RUN (co-op: LEAVE GAME). | RunManager.ShowMap, CoopRun.ShowMap |
AtBat | HudView | In-round HUD. Also the batting cage. | RunManager.PlayCurrentRound, CoopRun (your turn), BattingCage.StartSession |
Shop | ShopView (+ BuildPanel) | Offers, REROLL, NEXT INNING (co-op: READY). | RunManager.OpenShop, CoopRun.OpenShop |
RunOver | RunOverView | Results, XP bars, RUN IT BACK / PICK A MAP / MAIN MENU (co-op: MAIN MENU only). | RunManager.EndRun, CoopRun.EndRun |
Customize | CustomizeView | Dress-up screen and the Fit Mode host. | GameRoot.EnterCustomize |
Lobby | LobbyView | Co-op host / join, players, START RUN. | GameRoot.EnterLobby |
CoopWatch | CoopWatchView (+ HudView while AtBat.IsSpectating) | Someone else is batting. | CoopRun |
Intro | IntroOverlayView | The match intro before a run’s first inning: cold open, park tour, map card, pitcher and batter cards, face-off, PLAY BALL! (Cutscenes). | RunManager.PlayCurrentRound (inning 1, once per run), CoopRun.PlayMatchIntro, MatchIntroDirector.Preview |
Outro | OutroOverlayView | BOSS DOWN, MAP BEATEN or GAME OVER (Cutscenes). | OutroDirector.Begin (at the midpoint of its entry wipe), OutroDirector.Preview |
Index | IndexView | The INDEX screen: tabs BATTERS, PITCHERS, BALLPARKS, EQUIPMENT, FOOD, SPECIAL BALLS under the lobby top bar (Index Screen). | GameRoot.EnterIndex (INDEX tab in LobbyNav) |
Transitions
stateDiagram-v2 [*] --> MainMenu: GameRoot.Awake MainMenu --> MapSelect: PLAY! (no saved run) MainMenu --> RunMap: CONTINUE (resume run.json) / DAILY CHALLENGE MainMenu --> Shop: CONTINUE (checkpoint was in the shop) MainMenu --> Customize: CUSTOMIZE tab Customize --> MainMenu: PLAY tab / Esc MainMenu --> Lobby: PLAY CO-OP MainMenu --> AtBat: BATTING CAGE popup (pick a park) MapSelect --> RunMap: PLAY BALL! MapSelect --> MainMenu: BACK RunMap --> AtBat: PLAY BALL! RunMap --> MainMenu: SAVE & QUIT AtBat --> Shop: inning cleared AtBat --> RunOver: out of outs / last inning cleared Shop --> RunMap: NEXT INNING AtBat --> MainMenu: pause SAVE & QUIT TO MENU / LEAVE CAGE RunOver --> RunMap: RUN IT BACK RunOver --> MapSelect: PICK A MAP RunOver --> MainMenu: MAIN MENU Lobby --> RunMap: host START RUN (CoopRun.Start) Lobby --> MainMenu: BACK / Esc RunMap --> CoopWatch: co-op, another player bats CoopWatch --> AtBat: co-op, your turn AtBat --> CoopWatch: co-op, turn over RunMap --> Intro: PLAY BALL! on inning 1 (cutscenes on) Intro --> AtBat: walk-up (your turn) Intro --> CoopWatch: co-op, the opener is someone else AtBat --> Outro: boss inning cleared / map beaten / out of outs CoopWatch --> Outro: co-op, same endings Outro --> Shop: after BOSS DOWN Outro --> RunOver: after MAP BEATEN / GAME OVER MainMenu --> Index: INDEX tab Customize --> Index: INDEX tab Index --> MainMenu: PLAY tab / Esc Index --> Customize: CUSTOMIZE tab
With CUTSCENES off in Settings (skipCutscenes), the intro and outro states are skipped: PLAY BALL! goes straight to AtBat, and the inning end goes straight to Shop or RunOver as before. ABANDON RUN and the dev menu’s BEAT MAP / LOSE RUN never play an outro (EndRun(..., null)).
ABANDON RUN (map or pause) ends the run through EndRun(false), so it lands on RunOver. In co-op, LEAVE GAME and a lost session go back to MainMenu (CoopRun.OnSessionEnded shows the reason with MainMenuView.ShowNotice).
Overlays
| Overlay | Owner | Opens with | Notes |
|---|---|---|---|
| Pause (PAUSED) | UIRoot.DrawPause | Esc during AtBat, or the window losing focus | RESUME, the settings, then SAVE & QUIT TO MENU + ABANDON RUN (co-op: LEAVE GAME), or in the cage PITCH / PARK / LEAVE CAGE. Sets Time.timeScale = 0 and AudioListener.pause. |
| Dev menu | DevMenu (own component, GUI.depth = -10) | F1 | Editor and development builds only. Pauses an at-bat while open. See Dev Menu and Shortcuts. |
| NET TEST | NetTestView, drawn by MainMenuView | Ctrl+Shift+N, or the NET button (Editor) | Transport test. See Transports. |
| Fit Mode | FitModeView, drawn by CustomizeView | Ctrl+Shift+F, or the FIT button (Editor) | See Fit Mode. |
| Settings | SettingsView.DrawOptions | Menu icon in the top bar (LobbyNav), and inside pause | See Add a Setting. |
| PERKS, BATTING CAGE park picker | LobbyNav.DrawPopups | Top bar tabs | Shared by MainMenu and Customize. Esc closes them. |
| Screen fade | ScreenFade (GUI.depth = -1000) | Every StateChanged | 0.35 s fade from black. |
| FPS counter | FpsCounter (GUI.depth = -20) | Settings: FPS COUNTER | Over everything, pause included. |
| Walk-up transition | IntroOverlayView.DrawTransition | After the match intro | The second half of the wipe, the NOW BATTING lower-third and the letterbox retracting, drawn over the next screen (AtBat or CoopWatch) while the HUD fades in (MatchIntroDirector.HudAlpha). |
| Outro entry wipe | OutroOverlayView.DrawTransition | The last play of a boss inning or the run | A slash wipe over AtBat / CoopWatch; the state flips to Outro under its midpoint. |
| Hit counter | HitCounterView, drawn by HudView | Every batted ball | Part of the HUD, not its own state (Hit Show). |
Numbers
| What | Value | Where to tune |
|---|---|---|
| Fade-in length | 0.35 s | ScreenFade.Seconds |
| Screens that share the top bar (fade only below it) | MainMenu, Customize, Index | ScreenFade.HasTopBar |
| Pause panel height | 616 (cage: 668) | UIRoot.DrawPause |
| GUI depth: UIRoot / DevMenu / FpsCounter / ScreenFade | 0 / -10 / -20 / -1000 | each component’s OnGUI |
In the code
| File | What it does |
|---|---|
Scripts/Core/GameState.cs | The 12 states: MainMenu, RunMap, AtBat, Shop, RunOver, Customize, Lobby, CoopWatch, MapSelect, Intro, Outro, Index. |
Scripts/UI/UIRoot.cs | One view instance per state; Update handles pause, dev pause and cursor confinement; OnGUI switches on State. |
Scripts/UI/LobbyNav.cs | Top bar for MainMenu, Customize and Index (PLAY, CUSTOMIZE, PERKS, BATTING CAGE, INDEX, points, menu). |
Scripts/Intro/MatchIntroDirector.cs, OutroDirector.cs | Run the cutscenes and set the Intro / Outro states. |
Scripts/UI/IntroOverlayView.cs, OutroOverlayView.cs, IndexView.cs | The views for the three new states. |
Scripts/Modes/BattingCage.cs | Enter and StartSession set AtBat with the cage active. |
Gotchas
MainMenuView,CustomizeViewand the other views are plain classes, not MonoBehaviours. They keep their fields between visits;CustomizeViewresets itself throughOnStateChanged.- The cursor is
Confinedonly while batting and not paused. Unity enforces it in Windows/Linux builds, not the Editor’s Game view. - Alt-tab during an at-bat pauses (
OnApplicationFocus) so you never lose a strike to a focus change. BattingCage.IsActiveis cleared on any state change away fromAtBat.- The cage counts as
AtBat, soHudViewand the pause menu serve it too. ScreenFadeskips its fade fromIntrotoAtBat/CoopWatch(the intro ends on the batting view, one continuous shot) unless the intro was skipped with Esc, and fromAtBat/CoopWatchintoOutro(the entry wipe covers it).- The pause menu only opens in
AtBat; inIntroandOutroEsc skips the cutscene instead. GameAudiotreatsIntroandOutrolikeAtBat: the menu organ fades out (Audio).- The dev previews (dev menu CUTSCENES, the Editor-only I / B / V / G keys on the run map) go
MainMenuorRunMaptoIntro/Outroand back to where they started (Dev Menu and Shortcuts).
Related
- UI System: how the views are drawn
- Boot and GameRoot: the navigation methods
- Add a Screen: adding a state and a view
- Co-op Run Flow: the co-op transitions
- Run Structure: the solo loop
- Cutscenes and Index Screen: the three states added since e7dba51