Upload
dominique-boutin
View
351
Download
2
Embed Size (px)
Citation preview
1
DEV TIPS FOR STARTING NEW UNITY PROJECTS
DUBLIN UNITYUSER GROUP
MEETUP SEPTEMBER 2015
BY DOMINIQUE BOUTIN
CTO @ DIGIT GAME STUDIOS
2
AGENDA– About Me
– About Digit
– High Level Game Dev Process
– Unity As A Platform
– App Code Organisation
– App Flows
– App Flow Customisation
DEV TIPS FOR STARTING NEW UNITY PROJECTS
3
MEDominique Boutin
CTO @ Digit Game Studios
Professional industry experience:
5 years: F2P game dev
15 years: game technology
Was Director of Dev&Tech @ Bigpoint HQ
Started using Unity with v2.0 in 2007
Was Virtools expert before switching to Unity
4
THE DIGIT TEAM
Founded in 2012
Ireland’s largest game developer, based in the center of Dublin.
World leading team of engineers, artists and game developers.
Combined experience of launching 100+ titles on Mobile, Browser, PC and Console.
Experts in MMO strategy games and high fidelity mobile game development.
Staff of ~ 35
Digit’s first title is on 5 platforms and everybody plays in the same big world !
6
COMING SUMMER 2016
?
Digit’s second title is an iconic AAA-IP based mobile strategy MMO
7
Indie?
Decide: project for learning or project for publishing?
Do active risk managent:
reduce the risk to fail using a good approach
Key:
Move risks to very early stages of any project
(where it’s cheaper to
handle)HOW WE MAKE GAMES
HIGH LEVEL GAME DEV PROCESS
8 HOW WE MAKE GAMES
HIGH LEVEL GAME DEV PROCESS
Preproduction Production Release Post Release
Exploration
Validation
Core definition
Stretch goals
Tech Vertical Slice
First Playable
Tools
Team Rampup
Full Production
Alpha
Content Completed
Beta / Soft Launch
Fine Tuning
Full Release
Hot fixes
New Content
New Gameplay
9
You don’t do FarCry3 for the WiiWork and design for limitations of Unity and target platforms
Unity is closed source butVery extensible and customisableNot only for programmers: include designers, artists etc.
Unity promotes one way of doing butNot always the best
But also allows to be used differently
UNITY AS PLATFORM
10
APP CODE ORGANISATION
RELATIONS INSIDE YOUR CODE
11
– It’s about
• How do elements communicate with each otheror use each other
• Approach for references and dependencies
• Events vs direct usage / calls
• Avoiding processing overhead (GC, lookups etc)
– Also
• Code base easy to understand?
• Code base easy to extend or to refactor?
• Easy to debug?
• Testautomation possible?
APP CODE ORGANISATION
12
– Don’t follow industry recommendations blindly
• Programming cultures are too dogmatic (smells, best practices, patterns, testdriven etc.)
• Some solutions should not be ported 1:1 into Unity
• Avoid heavy frameworks (MVC frameworks, dependency injection frameworks etc)
– coding overhead and coding complication= High friction of change as it leads to = Low coder morale, especially for special cases
– You can achieve the same results much leanerAnd with better performance and maintability
• Avoid over abstraction by having an interface for everythingBe pragmatic!
APP CODE ORGANISATION
13
At Digit
• Composition over inheritance (Has-a vs Is-a)
• Related topics are organised as groups and sub-groups via namespaces and object composition
• Multi-Layered / -tiered APIs (think of Physics, Networking etc.)
– Don’t hide internals
– Instead layer APIs (internals, low level, service level)
• Use self-speaking names (that’s actually not easy)
• Comment smartly to avoid study of code context
• Rely on the programmer to do his job well:Education over enforcement.
APP CODE ORGANISATION
14
At Digit
• One “singleton” called “Hub”
– Doesn’t do anything
– Initialised and populated at startup of the app
– High Level Topic-Groups
» Allows access all systems
» Use interfaces where stubbing/mocking for testing is desired but don’t force it globally through the entire code base
– Only main thread usage
APP CODE ORGANISATION
15
At Digit
• Hub-Groups usually lead to systems related to the topic
– Easy to “dot” to what you are looking for e.g.
Hub.App.LifecycleManager
– Manually use interfaces for systems if you want stubbing/mocking for testing but not recommended to force it as requirement
• Consider keeping a local reference to a system if it makes sense
• Expose C# Events for callbacks / signals related to the topic
APP CODE ORGANISATION
16
At Digit
• If you need decoupling consider using static c# events
– Plus usaging Code Generation to speedup creation of new events
APP CODE ORGANISATION
17
APP FLOWS
WHAT HAPPENS WHEN
18
GAME ENGINE CORE LOOP
Traditionally something like
*Nowadays more parallelised
How do you organise your logic within a frame?
Network Physics Inputs Game Logic Rendering
GAME SCRIPT LOGIC LOOP?
Main Logic
Managers
Cameras
19
Study:
Execution Order of Events
http://docs.unity3d.com/Manual/ExecutionOrder.html
*system could have been designed better
SCRIPT EXECUTION
ORDER
20
SCRIPT EXECUTION ORDER
Use
• LateUpdate e.g. for updating camera movements
• Start to initialise and cache calculations or lookups
• Etc.
Also use Script Execution Order Settings• http://docs.unity3d.com/Manual/class-ScriptExecution.html
• Run somelogic upfront or after everybody body else
• You can also use this to proxy events into your custom framework via c# delegates in combination with non-destructible Gos and layered scene management
21
CUSTOM APP FLOWS, INJECTION
– Permanently root app/hub manager script(s) into the Unity app
• Use a base-scene for app management
– and scenes as layers via Application.LoadLevelAdditiveAsync
• Use DontDestroyOnLoad on the managing GameObjects
• Note to SDK developers:
– Creating the persisting game object should be a service.Assue the game is already doing it and just want to pass gameobject or events along
22
CUSTOM APP FLOWS, INJECTION
– Some unity APIs work with coroutines
• Make a coroutine starter component available that sits on your main app / Hub game object
• And can be passed into your systems e.g. for doing Web-Requests
23
CUSTOM APP FLOWS, INJECTION
– Do you own event pump or
– Forward Unity events into your custom c# framework (if wanted)
• Expose events e.g. via c# delegate to your framework
• Not recommended:Specialise MonoBehaviour through inheritancee.g. to call via reflection
– Usually hybrid approaches are used
24
CUSTOM APP FLOWS
– We recommend NodeCanavas (commerical product)
– Visual tools do help. Go for a healthy mix of code and data driven tools
– We worked with the author to make it work on 5+ platforms
– Behaviour trees are not only good for AI. In general for App flows quite useful (e.g. tutorials)
– Also comes with a visual state machine toolset
25
CUSTOM APP FLOWSConsider using reactive patterns
• Automatic notification when a value changed incl. the new value
– Score data changed: UI is updated automatically
• For a piece of logic: listen to what you are interested in
• A data field can have multiple subscribers
• If you go for c# delegates, use code gen
26
APPENDIX
• Use sub-folders (don’t pollute root)• Use Standard Asset Folder to split into
compilation units to save compilation time
digitgaming.com
WE ARE HIRING !
https://www.digitgaming.com/careers/