|
1 | 1 | # Game programming patterns in Unity
|
2 | 2 |
|
3 |
| -A collection of programming (design) patterns in Unity, mainly from the book [Game Programming Patterns](http://gameprogrammingpatterns.com). These are very useful to better organize your Unity project as it grows because they capture best practices and solutions to commonly occuring problems. 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! |
| 3 | +Here you can find a collection of programming (design) patterns in Unity, mainly from the book [Game Programming Patterns](http://gameprogrammingpatterns.com). These are very useful to better organize your Unity project as it grows because they capture best practices and solutions to commonly occuring problems. You don't have to use them - you should see them as tools in your toolbox. You can also experiment with how they are implemented to fit your specific needs. Some patterns, such as Update, Game Loop, Component, are already been built-in into Unity so you are already using them! |
4 | 4 |
|
5 | 5 | Programming patterns can be divided into the following groups:
|
6 | 6 | 1. **Architectural patterns.** One example is the MVC (Model-View-Controller).
|
@@ -196,6 +196,8 @@ Your game can be in a number of states. For example, the main character can have
|
196 | 196 |
|
197 | 197 | * If you are making a GTA-style game. You have one state for driving, one for when the character is not in a vehicle, another state for flying, etc. Then you can also add state-of-states. For example, in the state class where the character is not in a vehicle, you can have several sub-states, such as holding nothing, holding grenade, holding pistol, etc.
|
198 | 198 |
|
| 199 | +* Enemy AI is often using the State pattern. The creepers in Minecraft have three states: move randomly when you are far away, move towards you if you are closer, blow up when you are very close. |
| 200 | + |
199 | 201 | **Related patterns**
|
200 | 202 |
|
201 | 203 | * [Type Object](#12-type-object). In both cases you have a main object and then you add another object to define something. The difference is that in State you switch the other object, while in Type Object that object remains the same. So if the object in Type Object can be switched you get the State pattern.
|
@@ -507,6 +509,8 @@ You have some class you want to add some behaviors to in a flexible way without
|
507 | 509 |
|
508 | 510 | * If you have an order system where people order several products at the same time but pay at a later time. An example of this can be found in the code section where you order Tesla cars with modifications. Yes you could store each order in a list, but a better way is to store them in objects linked to each other. Instead of iterating through each object to find the price, you can just ask the "last" object to get the price of the entire chain.
|
509 | 511 |
|
| 512 | +* If you ever played Pubg you know you have weapons to which you can attach various attachments you find while playing the game. You can find magazines, sights, silenzers, etc, modifying the weapon's properties. You can use the Decorator pattern to implement this in your game. |
| 513 | + |
510 | 514 | **Related patterns**
|
511 | 515 |
|
512 | 516 | * [Subclass Sandbox](#11-subclass-sandbox). You may end up with many child-classes. To easier handle the code, you can define high-level methods in the parent like in the Subclass Sandbox pattern.
|
|
0 commit comments