OGDC 2014: Architecting Games in Unity
-
Author
gamelandvn -
Category
Documents
-
view
1.976 -
download
4
Embed Size (px)
description
Transcript of OGDC 2014: Architecting Games in Unity
- 1. Architecting Games in Unity Common patterns for developing games in Unity
2. If this was your house, what would you do? 3. Broken Windows Fix the windows. In New York City, Albuquerque and The Netherlands, improving the physical appearance of a neighbourhood has been shown to reduce crime and increase quality of life. People are influenced by their environment: Social norms and conformity Routine monitoring 4. Ah, Freedom! Unity gives you a rich set of building blocks that can be used to construct any type of game. Unity is flexible. There are hundreds of ways to build projects. And developers use ALL of them! 5. Architecture for Games But let's look at what you need And let's create a structure that can be reused for efficiency and robustness 6. Good Architecture = Good Standards Use C# Naming conventions Use descriptive names Use standardized capitalization In Unity dont be afraid of using spaces in names Logical folder structure Zero-tolerance for warnings and errors Zero-tolerance for runtime memory allocation 7. Core Application Logic Main Controller Base controller to manage high level application Uses public static methods so everyone can access it Uses Object.DontDestroyOnLoad so it is available throughout the project Scenes Other scenes are loaded on top of this. MainController loads and unloads other scenes and cleans up. 8. Main Controller Reset State Call GC.Collect to try to reclaim some memory. 9. Main Controller Preload State Start loading the level asynchronously and change state to Load 10. Main Controller Load State Keep going until loading is done 11. Main Controller Unload State Resources.UnloadUnusedAssets() Keep going until Unloading is done 12. Main Controller Postload State Do things immediately after loading Update currentSceneName 13. Main Controller Ready State Call GC.Collect to try to reclaim some memory. Avoid this if you have unused assets in the scene that may be used later. Do things just before beginning: e.g.: Get User Input to Start 14. Main Controller Run State We stay here until currentLevelName != nextLevelName This can be changed by calling SwitchScene static public method on the Main Controller from anywhere 15. Scene State Machine Implementation We can use a switch-case Gets difficult to maintain and read We can use delegates Unfortunately, setting a delegate allocates memory So we use an array of delegates. 16. Scene State Machine Implementation Example Implementation MainController, MenuController and GameController Lets look at the Profiler too! 17. Implementing Gameplay Controllers manage the objects Inter-object communication Static public methods Temporary public instance methods Messages, events Most common are: Singletons Pool controllers 18. Singleton Only one of them in the game Static public methods Examples: Score Player World Game 19. Singleton Example Implementation 20. Pool Based Objects Numerous instances in the game Limited number at any one time Preload simultaneously used quantity and disable Static public method to spawn one finds first disabled one and enables it Examples: Explosions Bullets Enemies Scenery 21. GameObjects are loaded from storage and placed in a pool and disabled. Object Pool Storage Pool Based Objects 22. GameObjects are activated when needed. Object Pool Storage Pool Based Objects 23. GameObjects are deactivated when no longer needed. This returns them to the pool. Object Pool Storage Pool Based Objects 24. Pool Based Objects Example Implementation 25. Download Find the Template.zip here: http://goo.gl/8WZGxn 26. Best-Practices Use C# Naming conventions Logical folder structure Zero-tolerance for warnings and errors Zero-tolerance for runtime memory allocation 27. Thank You! Rustum Scammell Email: [email protected] Skype: rustumscammell