Skip to content

A technical showcase of C# design patterns in Unity, featuring a generic Object Pooling system, Command, State, and Decorator patterns for a decoupled and scalable system

Notifications You must be signed in to change notification settings

volkanerden/Design-Patterns-Prototype

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Architecture & Design Patterns Showcase (Unity/C#)

This project is a technical prototype developed to demonstrate the implementation of scalable, memory-efficient software architectures within a real-time environment. Rather than focusing on visual assets, the project serves as a showcase for decoupled systems, event-driven logic, and optimized memory management.

Key Architectural Implementations

1. Command Pattern (ICommand.cs, CommandInvoker.cs, MoveCommand.cs)

Implemented a robust Command Pattern to handle player movement.

  • Decoupling Action from Execution: Input triggers are encapsulated as command objects and passed to a CommandInvoker.
  • Extensibility: This architecture allows for easy implementation of features like move-queuing (via Queue<ICommand>) or undo/redo functionality, ensuring the player controller remains lightweight and modular.

2. High-Performance Object Pooling (PoolBase.cs, BulletPool.cs, EnemyPool.cs)

To manage high-frequency object spawning without performance degradation, I developed a generic, reusable Object Pooling System.

  • Memory Optimization: Utilizing UnityEngine.Pool, the system recycles projectiles and enemies to maintain a near-zero allocation footprint during runtime, effectively eliminating Garbage Collection (GC) spikes.
  • Generic Abstraction: The PoolBase<T> allows for rapid scaling—adding new pooled entities requires zero modification to the core pooling logic.

3. Decorator Pattern for Dynamic Logic (BulletDecor.cs)

The "Rage Mode" weapon system is built using the Decorator Pattern, allowing for the dynamic extension of object behaviors at runtime.

  • Composition over Inheritance: Instead of complex inheritance trees, weapon upgrades (like the RageBullet) "wrap" the DefaultBullet to modify damage and fire rates on the fly.
  • Polymorphism: The IBullet interface ensures that the Fire.cs system can interact with any bullet type without knowing its specific implementation.

4. State Pattern & FSM (StateMachine.cs, StateControl.cs)

Player behavior is managed through a Finite State Machine (FSM).

  • State Encapsulation: Discrete classes for IdleState, MovingState, and FiringState handle their own logic and transitions.
  • Clean Control Flow: This removes large, complex if-else or switch blocks from the main Update loop, making the player controller highly maintainable and less prone to "state-leaking" bugs.

5. Event-Driven Feedback (RageManager.cs, KillCounter.cs)

The project utilizes C# Actions and Delegates to manage cross-system communication.

  • Observer Pattern: Systems like UI indicators and spawners react to events (e.g., OnExitRage) without direct dependencies, keeping the architecture loosely coupled.

Technical Stack

  • Language: C#
  • Engine: Unity
  • Key Patterns: Command, Decorator, Object Pooling (Generic), State (FSM), Observer.
  • Principles: SOLID, DRY, Composition over Inheritance.

About

A technical showcase of C# design patterns in Unity, featuring a generic Object Pooling system, Command, State, and Decorator patterns for a decoupled and scalable system

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published