Skip to content

CoderGamester/Core-Game

Repository files navigation

Core Game Template Project

๐ŸŽฎ Overview

Build fast, scalable mobile and WebGL games with a clean architecture, Addressables, and a lightweight service layer.

Unity License: MIT

Target audience: Unity developers building mobile (iOS/Android) and WebGL games who want a solid starting point with best practices.


๐Ÿ“‘ Table of Contents


๐Ÿš€ Features

  • SOLID-first architecture with manual dependency injection.
  • Addressables-first asset pipeline for dynamic loading and small initial APK/WebGL payloads.
  • Message-driven design with a simple message broker.
  • State machineโ€“driven game flow.
  • WebGL-ready with a working demo and production-friendly hooks for pause/quit.
  • Built-in Compliance Screen prefab.

๐Ÿ“ฆ Prerequisites

  • Unity Editor: 6000.0.55f1
  • API Compatibility Level: .NET Standard 2.1 (or .NET 4.x)
  • Git LFS (Large File Storage)

๐Ÿงฐ Quick Start

  1. Clone
git clone https://github.com/CoderGamester/Core-Game.git
cd Core-Game
  1. Open in Unity Hub (Unity 6000.0.55f1 recommended)

  2. Generate Addressables settings

  • Window > Asset Management > Addressables > Groups > Create/Generate Settings
  1. Configure UI (optional)
  • Locate and open UiConfigs.asset (Project search or Tools > Select UiConfigs.asset if available)
  1. Open the "Boot" Scene and Play
  • Open the scene named by Constants.Scenes.BOOT (boots into Main additively)
  1. Run the sample and inspect the flow

๐Ÿงญ Project Architecture

The entrypoint Main (Assets/Src/Main.cs) wires services and starts the game state machine.

Key responsibilities of Main:

  • Bind services via a lightweight Installer
  • Initialize Unity Services and internal versioning
  • Start the GameStateMachine
  • Handle lifecycle events (pause, focus, quit) and persist data

Example (excerpt from Main.cs):

var installer = new Installer();

installer.Bind<IMessageBrokerService>(new MessageBrokerService());
installer.Bind<ITimeService>(new TimeService());
installer.Bind<GameUiService, IGameUiServiceInit, IGameUiService>(new GameUiService(new UiAssetLoader()));
installer.Bind<IPoolService>(new PoolService());
installer.Bind<ITickService>(new TickService());
installer.Bind<ICoroutineService>(new CoroutineService());
installer.Bind<AssetResolverService, IAssetResolverService, IAssetAdderService>(new AssetResolverService());
installer.Bind<ConfigsProvider, IConfigsAdder, IConfigsProvider>(new ConfigsProvider());
installer.Bind<DataService, IDataService, IDataProvider>(new DataService());

var gameServices = new GameServicesLocator(installer);
installer.Bind<IGameServicesLocator>(gameServices);

_stateMachine = new GameStateMachine(installer);

Lifecycle hooks (excerpt):

private void OnApplicationPause(bool isPaused)
{
    if (isPaused)
    {
        _dataService.SaveAllData();
        _services.AnalyticsService.FlushEvents();
    }
    _services.MessageBrokerService.Publish(new ApplicationPausedMessage { IsPaused = isPaused });
}

State and logic boundaries are orchestrated by GameServicesLocator, GameLogicLocator, and GameStateMachine instances.


๐Ÿ—‚ Folder Structure

  • Assets/
    • Addressables/ โ€” runtime-loadable assets (configs, scenes, prefabs, UI)
      • Scenes/ โ€” scenes to be loaded (often additively) at runtime
      • Prefabs/ โ€” UI and gameplay prefabs (e.g., Compliance Screen)
    • Libs/ โ€” third-party libraries
    • Resources/ โ€” avoid for game content; reserved for Unity defaults/plugins
    • Src/ โ€” gameplay code and composition roots (e.g., Main.cs, BootSplashscreen.cs)
      • Cheats/ โ€” developer cheats and test toggles (e.g., SROptions.Cheats.cs)
      • Commands/ โ€” commands to trigger game logic actions (e.g., AcceptComplianceCommand.cs, RestartGameCommand.cs)
      • Configs/ โ€” ScriptableObject config definitions (e.g., DataConfigs.cs, GameConfigs.cs, SceneAssetConfigs.cs)
      • Data/ โ€” persistent data models (e.g., AppData.cs, PlayerData.cs) saved via IDataService
      • Editor/ โ€” editor-only tools (asset/sheet importers, utilities)
      • Ids/ โ€” strongly-typed IDs and auto-generated Addressable IDs (AddressableId.cs, GameId.cs, SceneId.cs)
      • Logic/ โ€” domain game logic and facades (GameLogicLocator.cs, plus Client/ and Server/ folders)
      • Messages/ โ€” message types/events published via IMessageBrokerService (e.g., ApplicationStateMessages.cs)
      • Presenters/ โ€” UI presenters (MVP) for all UI screens managed by the 'GameUiService' (e.g., MainHudPresenter.cs, MainMenuPresenter.cs)
      • Services/ โ€” game-specific services/adapters (GameServicesLocator.cs, analytics helpers, UI service, world refs)
      • StateMachines/ โ€” game flow states and orchestrator (e.g., GameStateMachine.cs, InitialLoadingState.cs)
      • Utils/ โ€” constants and small helpers (Constants.cs)
      • ViewControllers/ โ€” base/entity view controllers handled by the Presenters (ViewControllerBase.cs, EntityViewController.cs)
      • Views/ โ€” view MonoBehaviours (e.g., TimerView.cs)
  • Packages/ โ€” Package Manager manifest and lock
  • ProjectSettings/ โ€” Unity project settings and version
  • WebGL_Build/ โ€” example built WebGL output and template files

Rationale: prioritize Addressables over Resources/ to reduce initial payloads and enable content updates.


๐Ÿ“š Packages and Dependencies

Declared in Packages/manifest.json (selected):

  • com.gamelovers.services โ€” service locator and installer utilities
  • com.gamelovers.statechart โ€” state machine
  • com.gamelovers.uiservice โ€” UI service scaffolding
  • com.gamelovers.assetsimporter โ€” Addressables import helpers
  • com.gamelovers.configsprovider โ€” static config provider
  • com.gamelovers.dataextensions โ€” extensions and data containers
  • com.gamelovers.googlesheetimporter โ€” Google Sheets data import
  • com.cysharp.unitask โ€” async/await for Unity without allocations
  • com.acegikmo.mathfs โ€” math helpers
  • Unity packages: Addressables (2.6.0), Input System, UGUI, Cinemachine, Newtonsoft JSON, Analytics, Cloud Diagnostics, etc.

See also:


๐Ÿ—ƒ Addressables Setup and Workflow

  1. Open Addressables window
    • Window > Asset Management > Addressables > Groups
  2. Create/Generate Settings (first time only)
  3. Organize groups (Configs, UI, Scenes, etc.) and assign labels as needed
  4. Build Addressables
    • Build > New Build > Default Build Script
  5. Use generated IDs from AddressableId helpers

Example usage:

// Example from docs
AddressableId.Addressables_Configs_DataConfigs.GetConfig().Address;

Notes

  • Prefer Addressables over Resources/ for gameplay content
  • When changing serialized data, rebuild Addressables (and perform content update if using Remote)

๐ŸŽฌ Scenes and Game Flow

  • Boot scene contains BootSplashScreen and is the initial scene
  • Main scene hosts Main (composition root) and gameplay entry
  • Boot loads Main additively, then merges scenes and destroys bootstrapper

๐Ÿ“ฆ Build and Deployment

WebGL

  1. Build Settings
  • Platform: WebGL
  • Add Boot and Main scenes to Build Settings
  • Build to: WebGL_Build/
  1. Addressables
  • Build Addressables before building player
  1. Hosting

Tips

  • Enable compression and data caching in Player Settings as needed
  • On WebGL, OnApplicationQuit is not called; this project publishes quit on pause for WebGL

Mobile (Android/iOS)

  1. Build Settings
  • Add Boot and Main scenes
  • Android: IL2CPP, ARM64, Internet Access: Required if using remote Addressables
  • iOS: IL2CPP, set bundle identifiers, enable required capabilities
  1. Addressables
  • Choose Local or Remote profiles; rebuild Addressables for release
  1. Analytics/Diagnostics
  • Configure Unity Services as needed (Analytics, Cloud Diagnostics)

โšก Performance & Optimization

  • Prefer Addressables over Resources/
  • Pool frequently spawned objects (IPoolService)
  • Keep WebGL memory size appropriate for your content
  • Use IL2CPP and code stripping on mobile release builds
  • Defer heavy initialization with async (UniTask) during splash/boot

๐Ÿงช Troubleshooting

  • Addressables not loading
    • Ensure settings were created and groups built
  • WebGL shows blank page
    • Serve via HTTP(S); ensure compression/decompression settings are consistent
  • Missing packages after opening project
    • Open Package Manager to resolve; run Reimport All if needed
  • iOS tracking compile symbols
    • iOS ATT calls are behind UNITY_IOS; ensure related package/capabilities only for iOS builds

๐Ÿค Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m "Add some AmazingFeature")
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“„ License

MIT License


๐Ÿ“ž Contact


Unity Project Keybind Shortcuts

  • ALT+R (Windows) / โŒ˜+R (Mac) โ€” force compile project code
  • ALT+1 (Windows) / โŒฅ+1 (Mac) โ€” open the "Boot" scene
  • ALT+2 (Windows) / โŒฅ+2 (Mac) โ€” open the "Main" scene

Demo URL

https://codergamester.github.io/Core-Game/WebGL_Build/

About

This project is a the core architecture of a new mobile game project

Resources

Stars

Watchers

Forks

Packages

No packages published