Skip to content

Commit d750114

Browse files
committed
Updated readme
1 parent 5b6b6b4 commit d750114

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

README.md

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
# Game programming patterns in Unity
22

3-
*If you came here from Unity Tutorials, I've not finished the process to move all code to GitHub, so have patience*
4-
53
A collection of programming patterns in Unity, mainly from the book [Game Programming Patterns](http://gameprogrammingpatterns.com). These are very useful to better organize your Unity project as the game grows. You don't have to use them - you should see them as tools in your toolbox. Some patterns, such as Update, Game Loop, Component, are already been built-in into Unity so you are already using them!
64

75
Programming patterns can be divided into the following groups:
86
1. **Architectural patterns.** One example is the MVC (Model-View-Controller).
97
2. **Design patterns.** Are more specific than architectural patterns, such as the Singleton.
10-
3. **Anti-patterns.** Are a collection of patterns that many programmers are using to solve problems even though they shouldn't use them because they are ineffective solutions to a problem. Once example is a God object, most likely called GameController where you collect everything you might need.
8+
3. **Anti-patterns.** Are a collection of patterns that many programmers are using to solve problems even though they shouldn't use them because they are ineffective solutions to a problem. One example is a "God object," most likely called GameController where you collect everything you might need to make the game work. The problem with such as class is that it will grow in size, which will make it more difficult to maintain, and it will also be difficult to debug because the code doesn't belong together.
119

1210
Patterns from the book Game Programming Patterns:
1311

@@ -49,7 +47,7 @@ In you game you have many commands, such as play sound, throw cake, etc. It can
4947

5048
* To make it easier to rebind keys. Example of this is available in the code section.
5149

52-
* To make it easier to make a replay system. When you play the game, you store in some data strcuture which button you pressed each update. When you want to replay what has happened, you just iterate through each command while running the game. Example of this is available in the code section.
50+
* To make it easier to make a replay system. When you play the game, you store in some data structure which button you pressed each update. When you want to replay what has happened, you just iterate through each command while running the game. Example of this is available in the code section.
5351

5452
* To make it easier to make an undo and redo system. Is similar to the replay system, but in each command you also have a method called Undo() where you do the opposite of what the command is doing. Example of this is available in the code section.
5553

@@ -290,17 +288,17 @@ When making a big game you should start thinking in components. A component is s
290288

291289
## 14. Event Queue
292290

293-
This pattern is exactly the same as the Observer pattern. The only difference is that you wait until a later time to process each event. This may be useful if you have many events that may be activated at the same time which will freeze the game - this pattern will spread them out.
291+
This pattern is almost the same as the [Observer](#3-observer) pattern. The only difference is that you wait until a later time to process each event. This may be useful if you have many events that may be activated at the same time which will freeze the game - this pattern will spread them out.
294292

295293
**How to implement?**
296294

297-
Combine the Command pattern with a C#'s built-in queue. In the Update method you pick the first Command in the queue and run it while measuring time. If you have time to spare, you run the next Command, and so on until you are out of time. How much time you can spend on the Event Queue each update depends on the game, so you have to experiment.
295+
Combine the [Command](#1-command) pattern with a C#'s built-in queue. In the Update method you pick the first Command in the queue and run it while measuring time. If you have time to spare, you run the next Command, and so on until you are out of time. How much time you can spend on the Event Queue each update depends on the game, so you have to experiment.
298296

299297
**When is it useful?**
300298

301-
* When you after an event will load some asset. This may take time, so if you want to play a sound when clicking a button, the game may freeze because it has to load the sound.
299+
* When you after an event will load an asset. This may take time, so if you want to play a sound when clicking a button, the game may freeze because it has to load the sound. A better way is to play the sound some frames after the click.
302300

303-
* When you after an event will play some sound. What if 100 enemies die at the same time and each time an enemy dies you play a death-sound. Now 100 sounds will play at the same time. If you put the events in a queue, you can check if a sound is already playing and then ignore the event.
301+
* When you after an event will play a sound effect. What if 100 enemies die at the same time and each time an enemy dies you play a death-sound. Now 100 sounds will play at the same time. If you put the events in a queue, you can check if a sound is already playing and then ignore the event. You can also merge the events that are the same, so you have only one of each event type in the queue.
304302

305303

306304

0 commit comments

Comments
 (0)