gitmyhub

Unity-Design-Pattern

C# ★ 4.7k updated 6y ago

:tea: All Gang of Four Design Patterns written in Unity C# with many examples. And some Game Programming Patterns written in Unity C#. | 各种设计模式的Unity3D C#版本实现

A Unity C# project with working implementations of all 23 classic Gang of Four design patterns plus game-specific patterns, each in its own folder with an inspectable Unity scene and a real game example.

C#Unitysetup: moderatecomplexity 3/5

This repository contains working implementations of classic software design patterns written in C# for Unity, the game engine. Design patterns are well-known, named solutions to recurring problems in programming, and this project covers all 23 patterns from the Gang of Four, a foundational book on object-oriented software design from the 1990s that remains widely referenced today.

The 23 patterns are split into three groups. Behavioral patterns deal with how objects communicate and pass responsibility, and include things like the Command pattern (storing actions as objects), the Observer pattern (notifying multiple objects when something changes), and the State pattern (changing an object's behavior based on its current state). Structural patterns deal with how objects and classes are composed, and include patterns like Adapter, Facade, and Proxy. Creational patterns deal with how objects are created, covering Singleton, Factory, Builder, and others.

In addition to the Gang of Four patterns, the repository partially implements patterns from a separate book called Game Programming Patterns, which focuses on problems specific to game development. These include things like the Object Pool pattern (reusing objects instead of repeatedly creating and destroying them), the Game Loop pattern, and the Event Queue pattern.

Each pattern gets its own folder. Inside, one subfolder shows a basic structural implementation of the pattern in Unity with a scene you can open and inspect. Another subfolder contains one or more real-world game examples of the pattern in action, also with a working Unity scene.

The project is written in both English and Chinese. It references several well-known books and online resources as background reading, and credits an earlier Unity design pattern project as a structural influence.

Where it fits