Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Тарас Леськів “Game Programming Patterns and Unity”

Тарас Леськів “Game Programming Patterns and Unity”

http://gamedev.lviv.ua
https://www.facebook.com/startuplviv
https://twitter.com/gdlviv

  • Login to see the comments

  • Be the first to like this

Тарас Леськів “Game Programming Patterns and Unity”

  1. 1. Game Programming Patterns & Unity Taras Leskiv Unity3D Developer, Nravo
  2. 2. Agenda 1. GOF revisited - Singleton - Prototype - Flyweight - State 2. Behavioral - Subclass Sandbox - Type Object 3. Optimization - Object Pool
  3. 3. The Classics
  4. 4. The Controversial Guy
  5. 5. Singleton Oh c’mon, not again • It’s global • Coupling, coupling, coupling • Concurrency (not in Unity though)
  6. 6. Singleton Perfect usage example: • Avoided singleton Alternatives: • Just remove it (if possible) • Subclass Sandbox • Service Locator
  7. 7. Some Stuff To Handle • Scene transitions – ensure there is only one GO that was created first • Ensure there is no chance of multiple instances in scene
  8. 8. Perfect Unity Singleton • State that “travels” through all scenes and needs to be a gameObject • Generic MonoSingleton concept
  9. 9. 2. Prototype • Built-in Instantiate method. Creates identical copy of the provided gameObject • Prototype Implementation example
  10. 10. 3. Flyweight • All about efficiency (Similar to TypeObject) • Flyweight objects can represent states in state patterns.
  11. 11. 4. State • FSM Concept In Unity: • Mecanim Animator is an FSM
  12. 12. Playmaker FSM Finite state machines are useful when: • You have an entity whose behavior changes based on some internal state. • That state can be rigidly divided into one of a relatively small number of distinct options. • The entity responds to a series of inputs or events over time. http://gameprogrammingpatterns.com/state.html
  13. 13. 5. Subclass Sandbox Define behavior in a subclass using a set of operations provided by its base class.
  14. 14. 6. Type Object Define a type object class and a typed object class. Each type object instance represents a different logical type. Each typed object stores a reference to the type object that describes its type.
  15. 15. When to use? • You don’t know what types you will need up front. • Need to modify and add types without recompiling.
  16. 16. In Unity • Asset files and custom editors – perfect for game designers
  17. 17. 7. Object Pool Just a collection of reusable objects
  18. 18. Questions

×