Unity - Software Design Patterns

39
Software Design Patterns How I use them in Unity!

Transcript of Unity - Software Design Patterns

Page 1: Unity - Software Design Patterns

Software Design PatternsHow I use them in Unity!

Page 2: Unity - Software Design Patterns

Me!

Page 3: Unity - Software Design Patterns

David Baron- Professional Game Developer- I’ve worked for Ubisoft, Eidos, Gameloft …- Currently specialization is VR / AR

Page 4: Unity - Software Design Patterns

Goals

Page 5: Unity - Software Design Patterns

What I’m covering?

- My observations of the rise of Unity within the indie game industry.

- How developers started integrated design patterns into the scripting engine.

- Only the simplest patterns that I find useful for indie game development.

Page 6: Unity - Software Design Patterns

What I’m NOT covering?

- The exact GoF definitions.

- Source-code or how to implement them.

- There’s people that know this stuff way better than me!

Page 7: Unity - Software Design Patterns

What are design patterns?

Page 8: Unity - Software Design Patterns

History

Page 9: Unity - Software Design Patterns

GoFGang of Four

Page 10: Unity - Software Design Patterns

AAA

Page 11: Unity - Software Design Patterns

C++

C#

LUA

Visual Scripting

Engine Programmer

Gameplay Programmer

Technical Director

Level Designer / Scripter

Core Implementations

Game System Implementations

Exposition & Wrapping

Sequencing & Integration

Page 13: Unity - Software Design Patterns

What do I code in Unity?

Page 14: Unity - Software Design Patterns

BehavioursAnimations, cycles, UI, NPCs ...

Page 15: Unity - Software Design Patterns

SystemsMechanics, services ...

Page 16: Unity - Software Design Patterns

ScenariosScene events, flow, paths,

narration ...

Page 17: Unity - Software Design Patterns

ToolsIntegration, debugging,

optimization ...

Page 18: Unity - Software Design Patterns

My rule of thumb

Page 19: Unity - Software Design Patterns

If I don’t recognize it after coding it then it’s not a pattern!

Page 20: Unity - Software Design Patterns

The Anti-Pattern

Page 21: Unity - Software Design Patterns

Spaghetti

Page 22: Unity - Software Design Patterns

Spaghetti- Public GameObject ….

- Reference hell!

- Abusing the inspector.

Page 23: Unity - Software Design Patterns

The Patterns

Page 24: Unity - Software Design Patterns

Singleton

Page 25: Unity - Software Design Patterns
Page 26: Unity - Software Design Patterns

Singleton- Anyways all GameObjects in the scene are

initialized.

- Easy access to an instance.

- But not everything needs to be accessible.

- Too many singles in one room!

Page 27: Unity - Software Design Patterns

Facade

Page 28: Unity - Software Design Patterns

Hide the nuts and bolts!

Page 29: Unity - Software Design Patterns

Facade- I see it being used in a professional contexts.

- Very good solution for exposing complex gameplay systems to scripters.

Page 30: Unity - Software Design Patterns

Managers & Facades- They usually synonyms but not always.

- Having too many managers is like having “too many cooks in the kitchen”.

Page 31: Unity - Software Design Patterns

Adapter

Page 32: Unity - Software Design Patterns

Adapter- I use when I’m in an advanced prototyping

stage but I want to avoid refactoring interfaces to related implementations.

- Adapter makes things work after they're designed.

Page 33: Unity - Software Design Patterns

Exploring

Page 34: Unity - Software Design Patterns

Mediator

Page 35: Unity - Software Design Patterns

Mediator- My biggest challenge is to find elegant ways for

game systems to communicate with each other while staying decoupled.

- The Mediator design pattern is used to handle communication between related objects (Colleagues).

- I NEVER used in production, at least not in an explicit way.

Page 36: Unity - Software Design Patterns

Decorator

Page 37: Unity - Software Design Patterns

Object Pool

Page 38: Unity - Software Design Patterns
Page 39: Unity - Software Design Patterns

References

- Derek Banashttps://www.youtube.com/playlist?list=PLF206E906175C7E07

- Decorator Design Patternhttps://sourcemaking.com/design_patterns/decorator

- Efficient WebVR Development Using the Adapter Pattern in Three.jshttp://hecodes.com/2016/08/efficient-webvr-development-using-the-adapter-pattern-in-three-js/