SlideShare une entreprise Scribd logo
1  sur  53
Télécharger pour lire hors ligne
Architecting Games in
Unity
Common patterns for developing games in Unity
If this was your house, what would you do?
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
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!
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
Good Architecture = Good Standards
• Use C#
• Naming conventions
• Use descriptive names
• Use standardized capitalization
• In Unity don’t be afraid of using spaces in names
• Logical folder structure
• Zero-tolerance for warnings and errors
• Zero-tolerance for runtime memory allocation
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.
Main Controller – Reset State
• Call GC.Collect to try to reclaim some memory.
Main Controller – Preload State
• Start loading the level asynchronously and change state to Load
Main Controller – Load State
• Keep going until loading is done
Main Controller – Unload State
• Resources.UnloadUnusedAssets()
• Keep going until Unloading is done
Main Controller – Postload State
• Do things immediately after loading
• Update currentSceneName
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
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
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.
Scene State Machine Implementation
• Example Implementation
• MenuController
• GameController
• MainController
MenuController
GameController
MainController
Implementing Gameplay
• Controllers manage the objects
• Inter-object communication
• Static public methods
• Temporary public instance methods
• Messages, events
• Most common are:
• Singletons
• “Pool” controllers
Singleton
• Only one of them in the game
• Static public methods
• Examples:
• Score
• Player
• World
• Game
Singleton
• Example Implementation
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
GameObjects are loaded from
storage and placed in a pool and
disabled.
Object Pool
Storage
Pool Based Objects
GameObjects are activated when
needed.
Object Pool
Storage
Pool Based Objects
GameObjects are deactivated
when no longer needed. This
returns them to the pool.
Object Pool
Storage
Pool Based Objects
Pool Based Objects
• Example Implementation
SpawnPointController
AgentController
Download
• Find the Template.zip here:
http://goo.gl/8WZGxn
Best-Practices
• Use C#
• Naming conventions
• Logical folder structure
• Zero-tolerance for warnings and errors
• Zero-tolerance for runtime memory allocation
Thank You!
Rustum Scammell
Email: rus@unity3d.com
Skype: rustumscammell

Contenu connexe

Tendances

Configuração de Drivers
Configuração de DriversConfiguração de Drivers
Configuração de Drivers
AVEVA
 
ELCE 2012 - Dive into Android Networking: Adding Ethernet Connectivity
ELCE 2012 - Dive into Android Networking: Adding Ethernet ConnectivityELCE 2012 - Dive into Android Networking: Adding Ethernet Connectivity
ELCE 2012 - Dive into Android Networking: Adding Ethernet Connectivity
Benjamin Zores
 
Embedded Operating System - Linux
Embedded Operating System - LinuxEmbedded Operating System - Linux
Embedded Operating System - Linux
Emertxe Information Technologies Pvt Ltd
 
Android audio system(audioflinger)
Android audio system(audioflinger)Android audio system(audioflinger)
Android audio system(audioflinger)
fefe7270
 

Tendances (20)

Chapitre 5 classes abstraites et interfaces
Chapitre 5  classes abstraites et interfacesChapitre 5  classes abstraites et interfaces
Chapitre 5 classes abstraites et interfaces
 
Cours JavaScript
Cours JavaScriptCours JavaScript
Cours JavaScript
 
Advanced C - Part 1
Advanced C - Part 1 Advanced C - Part 1
Advanced C - Part 1
 
Configuração de Drivers
Configuração de DriversConfiguração de Drivers
Configuração de Drivers
 
OpenNebula 5.4 Hands-on Tutorial
OpenNebula 5.4 Hands-on TutorialOpenNebula 5.4 Hands-on Tutorial
OpenNebula 5.4 Hands-on Tutorial
 
POO Java Chapitre 6 Exceptions
POO Java  Chapitre 6 ExceptionsPOO Java  Chapitre 6 Exceptions
POO Java Chapitre 6 Exceptions
 
Databases in Android Application
Databases in Android ApplicationDatabases in Android Application
Databases in Android Application
 
C Programming - Refresher - Part II
C Programming - Refresher - Part II C Programming - Refresher - Part II
C Programming - Refresher - Part II
 
Formation Script MS-DOS.ppt
Formation Script MS-DOS.pptFormation Script MS-DOS.ppt
Formation Script MS-DOS.ppt
 
Introduction to shell scripting
Introduction to shell scriptingIntroduction to shell scripting
Introduction to shell scripting
 
ELCE 2012 - Dive into Android Networking: Adding Ethernet Connectivity
ELCE 2012 - Dive into Android Networking: Adding Ethernet ConnectivityELCE 2012 - Dive into Android Networking: Adding Ethernet Connectivity
ELCE 2012 - Dive into Android Networking: Adding Ethernet Connectivity
 
Android Things : Building Embedded Devices
Android Things : Building Embedded DevicesAndroid Things : Building Embedded Devices
Android Things : Building Embedded Devices
 
Android-Tp5 : web services
Android-Tp5 : web servicesAndroid-Tp5 : web services
Android-Tp5 : web services
 
La gestion des exceptions avec Java
La gestion des exceptions avec JavaLa gestion des exceptions avec Java
La gestion des exceptions avec Java
 
Cours javascript
Cours javascriptCours javascript
Cours javascript
 
Embedded Operating System - Linux
Embedded Operating System - LinuxEmbedded Operating System - Linux
Embedded Operating System - Linux
 
Chapitre8: Collections et Enumerations En Java
Chapitre8: Collections et Enumerations En JavaChapitre8: Collections et Enumerations En Java
Chapitre8: Collections et Enumerations En Java
 
Android audio system(audioflinger)
Android audio system(audioflinger)Android audio system(audioflinger)
Android audio system(audioflinger)
 
Create Development and Production Environments with Vagrant
Create Development and Production Environments with VagrantCreate Development and Production Environments with Vagrant
Create Development and Production Environments with Vagrant
 
Cours de C++ / Tronc commun deuxième année ISIMA
Cours de C++ / Tronc commun deuxième année ISIMACours de C++ / Tronc commun deuxième année ISIMA
Cours de C++ / Tronc commun deuxième année ISIMA
 

Similaire à OGDC 2014_Architecting Games in Unity_Mr. Rustum Scammell

OGDC 2014: Architecting Games in Unity
OGDC 2014: Architecting Games in UnityOGDC 2014: Architecting Games in Unity
OGDC 2014: Architecting Games in Unity
GameLandVN
 

Similaire à OGDC 2014_Architecting Games in Unity_Mr. Rustum Scammell (20)

OGDC 2014: Architecting Games in Unity
OGDC 2014: Architecting Games in UnityOGDC 2014: Architecting Games in Unity
OGDC 2014: Architecting Games in Unity
 
Scalable game-servers-tgc
Scalable game-servers-tgcScalable game-servers-tgc
Scalable game-servers-tgc
 
Lecture 8 - What is Game AI? Final Thoughts
Lecture 8 - What is Game AI? Final ThoughtsLecture 8 - What is Game AI? Final Thoughts
Lecture 8 - What is Game AI? Final Thoughts
 
Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...
Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...
Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...
 
2D Endless Runner in Unity for Mobile - GDG DevFest Istanbul 2014
2D Endless Runner in Unity for Mobile - GDG DevFest Istanbul 20142D Endless Runner in Unity for Mobile - GDG DevFest Istanbul 2014
2D Endless Runner in Unity for Mobile - GDG DevFest Istanbul 2014
 
Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...
Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...
Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...
 
stackconf 2022: Infrastructure Automation (anti) patterns
stackconf 2022: Infrastructure Automation (anti) patternsstackconf 2022: Infrastructure Automation (anti) patterns
stackconf 2022: Infrastructure Automation (anti) patterns
 
Infrastructure as Code Patterns
Infrastructure as Code PatternsInfrastructure as Code Patterns
Infrastructure as Code Patterns
 
Procedural Processes - Lessons Learnt from Automated Content Generation in "E...
Procedural Processes - Lessons Learnt from Automated Content Generation in "E...Procedural Processes - Lessons Learnt from Automated Content Generation in "E...
Procedural Processes - Lessons Learnt from Automated Content Generation in "E...
 
Optimization in Unity: simple tips for developing with "no surprises" / Anton...
Optimization in Unity: simple tips for developing with "no surprises" / Anton...Optimization in Unity: simple tips for developing with "no surprises" / Anton...
Optimization in Unity: simple tips for developing with "no surprises" / Anton...
 
0507 057 01 98 * Adana Cukurova Klima Servisleri
0507 057 01 98 * Adana Cukurova Klima Servisleri0507 057 01 98 * Adana Cukurova Klima Servisleri
0507 057 01 98 * Adana Cukurova Klima Servisleri
 
Optimizing mobile applications - Ian Dundore, Mark Harkness
Optimizing mobile applications - Ian Dundore, Mark HarknessOptimizing mobile applications - Ian Dundore, Mark Harkness
Optimizing mobile applications - Ian Dundore, Mark Harkness
 
"Using Automation Tools To Deploy And Operate Applications In Real World Scen...
"Using Automation Tools To Deploy And Operate Applications In Real World Scen..."Using Automation Tools To Deploy And Operate Applications In Real World Scen...
"Using Automation Tools To Deploy And Operate Applications In Real World Scen...
 
"Using Automation Tools To Deploy And Operate Applications In Real World Scen...
"Using Automation Tools To Deploy And Operate Applications In Real World Scen..."Using Automation Tools To Deploy And Operate Applications In Real World Scen...
"Using Automation Tools To Deploy And Operate Applications In Real World Scen...
 
Software Engineer- A unity 3d Game
Software Engineer- A unity 3d GameSoftware Engineer- A unity 3d Game
Software Engineer- A unity 3d Game
 
The Professional Programmer
The Professional ProgrammerThe Professional Programmer
The Professional Programmer
 
Orleans gdc2019
Orleans gdc2019Orleans gdc2019
Orleans gdc2019
 
Antifragility and testing for distributed systems failure
Antifragility and testing for distributed systems failureAntifragility and testing for distributed systems failure
Antifragility and testing for distributed systems failure
 
Practical Windows Kernel Exploitation
Practical Windows Kernel ExploitationPractical Windows Kernel Exploitation
Practical Windows Kernel Exploitation
 
Improving Game Performance in the Browser
Improving Game Performance in the BrowserImproving Game Performance in the Browser
Improving Game Performance in the Browser
 

Plus de ogdc

OGDC 2014_Entity system in mobile game development_Mr. Cody nguyen
OGDC 2014_Entity system in mobile game development_Mr. Cody nguyenOGDC 2014_Entity system in mobile game development_Mr. Cody nguyen
OGDC 2014_Entity system in mobile game development_Mr. Cody nguyen
ogdc
 
OGDC 2014_Sky Garden Mobile conceptualization: From PC to Mobile_Mr. Luc Hoan...
OGDC 2014_Sky Garden Mobile conceptualization: From PC to Mobile_Mr. Luc Hoan...OGDC 2014_Sky Garden Mobile conceptualization: From PC to Mobile_Mr. Luc Hoan...
OGDC 2014_Sky Garden Mobile conceptualization: From PC to Mobile_Mr. Luc Hoan...
ogdc
 
OGDC 2014_Creativity in Game Design - Case Study: Famous Vietnamese mobile ga...
OGDC 2014_Creativity in Game Design - Case Study: Famous Vietnamese mobile ga...OGDC 2014_Creativity in Game Design - Case Study: Famous Vietnamese mobile ga...
OGDC 2014_Creativity in Game Design - Case Study: Famous Vietnamese mobile ga...
ogdc
 
OGDC 2014_Vietnam Mobile Internet 2014: A focus in smartphone game and compar...
OGDC 2014_Vietnam Mobile Internet 2014: A focus in smartphone game and compar...OGDC 2014_Vietnam Mobile Internet 2014: A focus in smartphone game and compar...
OGDC 2014_Vietnam Mobile Internet 2014: A focus in smartphone game and compar...
ogdc
 
OGDC 2014_Vietnam Smartphone game market 2013 overview. From vision to action...
OGDC 2014_Vietnam Smartphone game market 2013 overview. From vision to action...OGDC 2014_Vietnam Smartphone game market 2013 overview. From vision to action...
OGDC 2014_Vietnam Smartphone game market 2013 overview. From vision to action...
ogdc
 
OGDC 2014_User segmentation and Monetization_Mr. Phat hoang
OGDC 2014_User segmentation and Monetization_Mr. Phat hoangOGDC 2014_User segmentation and Monetization_Mr. Phat hoang
OGDC 2014_User segmentation and Monetization_Mr. Phat hoang
ogdc
 
OGDC 2014_Animation workflow with Spine in Tiny Busters_Mr. Huynh Dong Hai
OGDC 2014_Animation workflow with Spine in Tiny Busters_Mr. Huynh Dong HaiOGDC 2014_Animation workflow with Spine in Tiny Busters_Mr. Huynh Dong Hai
OGDC 2014_Animation workflow with Spine in Tiny Busters_Mr. Huynh Dong Hai
ogdc
 
OGDC 2014_Speed Up and make quality 3D game models_Mr. Pham Duc Duy
OGDC 2014_Speed Up and make quality 3D game models_Mr. Pham Duc DuyOGDC 2014_Speed Up and make quality 3D game models_Mr. Pham Duc Duy
OGDC 2014_Speed Up and make quality 3D game models_Mr. Pham Duc Duy
ogdc
 
OGDC 2014_One-Man Studio: How to make a game prototype_Mr. Le Vo Tien Giang
OGDC 2014_One-Man Studio: How to make a game prototype_Mr. Le Vo Tien GiangOGDC 2014_One-Man Studio: How to make a game prototype_Mr. Le Vo Tien Giang
OGDC 2014_One-Man Studio: How to make a game prototype_Mr. Le Vo Tien Giang
ogdc
 
OGDC 2014_Hands on experience with Cocos2dx in cross-platform with Farmery_Mr...
OGDC 2014_Hands on experience with Cocos2dx in cross-platform with Farmery_Mr...OGDC 2014_Hands on experience with Cocos2dx in cross-platform with Farmery_Mr...
OGDC 2014_Hands on experience with Cocos2dx in cross-platform with Farmery_Mr...
ogdc
 
OGDC 2014_Optimize or Die: Key disciplines to optimize your mobile game_Mr. P...
OGDC 2014_Optimize or Die: Key disciplines to optimize your mobile game_Mr. P...OGDC 2014_Optimize or Die: Key disciplines to optimize your mobile game_Mr. P...
OGDC 2014_Optimize or Die: Key disciplines to optimize your mobile game_Mr. P...
ogdc
 
OGDC 2014_Why choosing 2D animation for Mobile Game?_Mr. Joe Tran
OGDC 2014_Why choosing 2D animation for Mobile Game?_Mr. Joe TranOGDC 2014_Why choosing 2D animation for Mobile Game?_Mr. Joe Tran
OGDC 2014_Why choosing 2D animation for Mobile Game?_Mr. Joe Tran
ogdc
 
OGDC 2014_ An artist's story_Mr. Vu Cam Cong Danh
OGDC 2014_ An artist's story_Mr. Vu Cam Cong DanhOGDC 2014_ An artist's story_Mr. Vu Cam Cong Danh
OGDC 2014_ An artist's story_Mr. Vu Cam Cong Danh
ogdc
 
OGDC 2014_Tips and Tricks for seasonal events and community building in Drago...
OGDC 2014_Tips and Tricks for seasonal events and community building in Drago...OGDC 2014_Tips and Tricks for seasonal events and community building in Drago...
OGDC 2014_Tips and Tricks for seasonal events and community building in Drago...
ogdc
 
OGDC 2014_Cross platform mobile game application development_Mr. Makku J.Kero
OGDC 2014_Cross platform mobile game application development_Mr. Makku J.KeroOGDC 2014_Cross platform mobile game application development_Mr. Makku J.Kero
OGDC 2014_Cross platform mobile game application development_Mr. Makku J.Kero
ogdc
 
OGDC 2014_Tips and Tricks for seasonal events and community building in Drago...
OGDC 2014_Tips and Tricks for seasonal events and community building in Drago...OGDC 2014_Tips and Tricks for seasonal events and community building in Drago...
OGDC 2014_Tips and Tricks for seasonal events and community building in Drago...
ogdc
 
OGDC 2014_Business design is game design: 10 bits of business/design wisdom_M...
OGDC 2014_Business design is game design: 10 bits of business/design wisdom_M...OGDC 2014_Business design is game design: 10 bits of business/design wisdom_M...
OGDC 2014_Business design is game design: 10 bits of business/design wisdom_M...
ogdc
 
OGDC 2014_Build your own Particle System_Mr. Nguyen Dang Quang
OGDC 2014_Build your own Particle System_Mr. Nguyen Dang QuangOGDC 2014_Build your own Particle System_Mr. Nguyen Dang Quang
OGDC 2014_Build your own Particle System_Mr. Nguyen Dang Quang
ogdc
 
OGDC 2014_ Game Design: 5 years of painful lessons_Mr. Do Van Thanh
OGDC 2014_ Game Design: 5 years of painful lessons_Mr. Do Van ThanhOGDC 2014_ Game Design: 5 years of painful lessons_Mr. Do Van Thanh
OGDC 2014_ Game Design: 5 years of painful lessons_Mr. Do Van Thanh
ogdc
 
OGDC 2014_3D Graphic on mobile_Mr. Hoang Minh Truong
OGDC 2014_3D Graphic on mobile_Mr. Hoang Minh TruongOGDC 2014_3D Graphic on mobile_Mr. Hoang Minh Truong
OGDC 2014_3D Graphic on mobile_Mr. Hoang Minh Truong
ogdc
 

Plus de ogdc (20)

OGDC 2014_Entity system in mobile game development_Mr. Cody nguyen
OGDC 2014_Entity system in mobile game development_Mr. Cody nguyenOGDC 2014_Entity system in mobile game development_Mr. Cody nguyen
OGDC 2014_Entity system in mobile game development_Mr. Cody nguyen
 
OGDC 2014_Sky Garden Mobile conceptualization: From PC to Mobile_Mr. Luc Hoan...
OGDC 2014_Sky Garden Mobile conceptualization: From PC to Mobile_Mr. Luc Hoan...OGDC 2014_Sky Garden Mobile conceptualization: From PC to Mobile_Mr. Luc Hoan...
OGDC 2014_Sky Garden Mobile conceptualization: From PC to Mobile_Mr. Luc Hoan...
 
OGDC 2014_Creativity in Game Design - Case Study: Famous Vietnamese mobile ga...
OGDC 2014_Creativity in Game Design - Case Study: Famous Vietnamese mobile ga...OGDC 2014_Creativity in Game Design - Case Study: Famous Vietnamese mobile ga...
OGDC 2014_Creativity in Game Design - Case Study: Famous Vietnamese mobile ga...
 
OGDC 2014_Vietnam Mobile Internet 2014: A focus in smartphone game and compar...
OGDC 2014_Vietnam Mobile Internet 2014: A focus in smartphone game and compar...OGDC 2014_Vietnam Mobile Internet 2014: A focus in smartphone game and compar...
OGDC 2014_Vietnam Mobile Internet 2014: A focus in smartphone game and compar...
 
OGDC 2014_Vietnam Smartphone game market 2013 overview. From vision to action...
OGDC 2014_Vietnam Smartphone game market 2013 overview. From vision to action...OGDC 2014_Vietnam Smartphone game market 2013 overview. From vision to action...
OGDC 2014_Vietnam Smartphone game market 2013 overview. From vision to action...
 
OGDC 2014_User segmentation and Monetization_Mr. Phat hoang
OGDC 2014_User segmentation and Monetization_Mr. Phat hoangOGDC 2014_User segmentation and Monetization_Mr. Phat hoang
OGDC 2014_User segmentation and Monetization_Mr. Phat hoang
 
OGDC 2014_Animation workflow with Spine in Tiny Busters_Mr. Huynh Dong Hai
OGDC 2014_Animation workflow with Spine in Tiny Busters_Mr. Huynh Dong HaiOGDC 2014_Animation workflow with Spine in Tiny Busters_Mr. Huynh Dong Hai
OGDC 2014_Animation workflow with Spine in Tiny Busters_Mr. Huynh Dong Hai
 
OGDC 2014_Speed Up and make quality 3D game models_Mr. Pham Duc Duy
OGDC 2014_Speed Up and make quality 3D game models_Mr. Pham Duc DuyOGDC 2014_Speed Up and make quality 3D game models_Mr. Pham Duc Duy
OGDC 2014_Speed Up and make quality 3D game models_Mr. Pham Duc Duy
 
OGDC 2014_One-Man Studio: How to make a game prototype_Mr. Le Vo Tien Giang
OGDC 2014_One-Man Studio: How to make a game prototype_Mr. Le Vo Tien GiangOGDC 2014_One-Man Studio: How to make a game prototype_Mr. Le Vo Tien Giang
OGDC 2014_One-Man Studio: How to make a game prototype_Mr. Le Vo Tien Giang
 
OGDC 2014_Hands on experience with Cocos2dx in cross-platform with Farmery_Mr...
OGDC 2014_Hands on experience with Cocos2dx in cross-platform with Farmery_Mr...OGDC 2014_Hands on experience with Cocos2dx in cross-platform with Farmery_Mr...
OGDC 2014_Hands on experience with Cocos2dx in cross-platform with Farmery_Mr...
 
OGDC 2014_Optimize or Die: Key disciplines to optimize your mobile game_Mr. P...
OGDC 2014_Optimize or Die: Key disciplines to optimize your mobile game_Mr. P...OGDC 2014_Optimize or Die: Key disciplines to optimize your mobile game_Mr. P...
OGDC 2014_Optimize or Die: Key disciplines to optimize your mobile game_Mr. P...
 
OGDC 2014_Why choosing 2D animation for Mobile Game?_Mr. Joe Tran
OGDC 2014_Why choosing 2D animation for Mobile Game?_Mr. Joe TranOGDC 2014_Why choosing 2D animation for Mobile Game?_Mr. Joe Tran
OGDC 2014_Why choosing 2D animation for Mobile Game?_Mr. Joe Tran
 
OGDC 2014_ An artist's story_Mr. Vu Cam Cong Danh
OGDC 2014_ An artist's story_Mr. Vu Cam Cong DanhOGDC 2014_ An artist's story_Mr. Vu Cam Cong Danh
OGDC 2014_ An artist's story_Mr. Vu Cam Cong Danh
 
OGDC 2014_Tips and Tricks for seasonal events and community building in Drago...
OGDC 2014_Tips and Tricks for seasonal events and community building in Drago...OGDC 2014_Tips and Tricks for seasonal events and community building in Drago...
OGDC 2014_Tips and Tricks for seasonal events and community building in Drago...
 
OGDC 2014_Cross platform mobile game application development_Mr. Makku J.Kero
OGDC 2014_Cross platform mobile game application development_Mr. Makku J.KeroOGDC 2014_Cross platform mobile game application development_Mr. Makku J.Kero
OGDC 2014_Cross platform mobile game application development_Mr. Makku J.Kero
 
OGDC 2014_Tips and Tricks for seasonal events and community building in Drago...
OGDC 2014_Tips and Tricks for seasonal events and community building in Drago...OGDC 2014_Tips and Tricks for seasonal events and community building in Drago...
OGDC 2014_Tips and Tricks for seasonal events and community building in Drago...
 
OGDC 2014_Business design is game design: 10 bits of business/design wisdom_M...
OGDC 2014_Business design is game design: 10 bits of business/design wisdom_M...OGDC 2014_Business design is game design: 10 bits of business/design wisdom_M...
OGDC 2014_Business design is game design: 10 bits of business/design wisdom_M...
 
OGDC 2014_Build your own Particle System_Mr. Nguyen Dang Quang
OGDC 2014_Build your own Particle System_Mr. Nguyen Dang QuangOGDC 2014_Build your own Particle System_Mr. Nguyen Dang Quang
OGDC 2014_Build your own Particle System_Mr. Nguyen Dang Quang
 
OGDC 2014_ Game Design: 5 years of painful lessons_Mr. Do Van Thanh
OGDC 2014_ Game Design: 5 years of painful lessons_Mr. Do Van ThanhOGDC 2014_ Game Design: 5 years of painful lessons_Mr. Do Van Thanh
OGDC 2014_ Game Design: 5 years of painful lessons_Mr. Do Van Thanh
 
OGDC 2014_3D Graphic on mobile_Mr. Hoang Minh Truong
OGDC 2014_3D Graphic on mobile_Mr. Hoang Minh TruongOGDC 2014_3D Graphic on mobile_Mr. Hoang Minh Truong
OGDC 2014_3D Graphic on mobile_Mr. Hoang Minh Truong
 

OGDC 2014_Architecting Games in Unity_Mr. Rustum Scammell

  • 1.
  • 2. Architecting Games in Unity Common patterns for developing games in Unity
  • 3. If this was your house, what would you do?
  • 4. 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
  • 5. 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!
  • 6.
  • 7. 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
  • 8. Good Architecture = Good Standards • Use C# • Naming conventions • Use descriptive names • Use standardized capitalization • In Unity don’t be afraid of using spaces in names • Logical folder structure • Zero-tolerance for warnings and errors • Zero-tolerance for runtime memory allocation
  • 9.
  • 10. 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.
  • 11. Main Controller – Reset State • Call GC.Collect to try to reclaim some memory.
  • 12. Main Controller – Preload State • Start loading the level asynchronously and change state to Load
  • 13. Main Controller – Load State • Keep going until loading is done
  • 14. Main Controller – Unload State • Resources.UnloadUnusedAssets() • Keep going until Unloading is done
  • 15. Main Controller – Postload State • Do things immediately after loading • Update currentSceneName
  • 16. 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
  • 17. 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
  • 18. 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.
  • 19. Scene State Machine Implementation • Example Implementation • MenuController • GameController • MainController
  • 21.
  • 23.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35. Implementing Gameplay • Controllers manage the objects • Inter-object communication • Static public methods • Temporary public instance methods • Messages, events • Most common are: • Singletons • “Pool” controllers
  • 36. Singleton • Only one of them in the game • Static public methods • Examples: • Score • Player • World • Game
  • 38. 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
  • 39. GameObjects are loaded from storage and placed in a pool and disabled. Object Pool Storage Pool Based Objects
  • 40. GameObjects are activated when needed. Object Pool Storage Pool Based Objects
  • 41. GameObjects are deactivated when no longer needed. This returns them to the pool. Object Pool Storage Pool Based Objects
  • 42. Pool Based Objects • Example Implementation
  • 44.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51. Download • Find the Template.zip here: http://goo.gl/8WZGxn
  • 52. Best-Practices • Use C# • Naming conventions • Logical folder structure • Zero-tolerance for warnings and errors • Zero-tolerance for runtime memory allocation
  • 53. Thank You! Rustum Scammell Email: rus@unity3d.com Skype: rustumscammell