How fy-/fyworld works
Project Type and Purpose
• FyWorld is a Unity-based, top-down base-building / simulation game. It’s organized as a “mega-tutorial” open-source project: the Unity Editor + C# code drive simulation (entities, AI, world), while assets (textures, shaders, prefabs) supply visuals and UI.
High-Level Components
a. Unity Editor & Project Settings
• Manages build, input, graphics, scene loading (ProjectSettings/*, Packages/*).
b. Assets
• Resources: Textures, Shaders, Materials (for world/tiles/units).
• Prefabs: UI elements, FX, Character panels.
• Third-party libs: TextMesh Pro, Priority Queue.
c. Core Simulation
• World Layer: Map, GroundGrid, TilableGrid, LayerGrids (World/*).
• Entities: Ground, Plant, Mountain, Building, Inventory, Tick (Entities/*).
• Definitions: DefsLoader + Def classes (Definitions/*) load JSON/XML data into in-memory definitions (e.g. BuildingDef, TaskDef).
• Game Loop: GameManager orchestrates fixed ticks, updates world and entities.
d. Character & AI Systems
• BaseCharacter, CharacterStats, CharacterMovement (Characters/*).
• AI: BrainNode, PathFinder, Target, Tasks, per-node logic (Characters/AI/*).
e. Controllers & UI
• Input/UI controllers: MenuController, WindowController, DragController, TileSelectorController, CameraController (Controllers/*).
• UI windows and panels, tied to prefabs under Assets/Fy/Resources/Prefabs/UI.
f. Rendering & Visuals
g. Helpers & Tools
• Utility classes (PerlinNoise, GameObjectPool, Utils, WordUtils*).
• PythonUtils folder: external Python scripts for offline generation or analysis.
Interactions and Data Flow
• On start, DefsLoader components read data files → populate Definitions.
• GameManager invokes WorldUtils to generate Map & Grids → instantiate Entities with their Defs.
• Each tick:
• Entities.Tick triggers update: CharacterBrain selects Task (via AI.BrainNode, Tasks classes) → PathFinder calculates path → CharacterMovement moves character → Entities state updates (Inventory, Stats).
• Controllers listen for user input (mouse/keyboard) → modify game state (e.g., place buildings, change camera, open UI windows).
• Logging and editor settings managed by Unity ProjectSettings; assets hot-reloaded by Editor.
Architectural Patterns and Design Principles
• Data-Driven: Definitions loaded at runtime decouple data from code.
• Entity-Component-System flavor: Entities maintain data, various systems (AI, Movement, Rendering) operate on them each tick.
• MVC-like UI: Controllers feed Models (game state) to Views (UI windows + prefabs).
• Singleton GameManager: coordinates loop.
• Object pooling and resource management via helper classes.