Architecture and Implementation of the System for Serious Games in Unity 3D
Total Page:16
File Type:pdf, Size:1020Kb
Architecture and implementation of the system for serious games in Unity 3D Master Thesis Aleksei Penzentcev Brno, May 2015 Declaration Hereby I declare, that this paper is my original authorial work, which I have worked out by my own. All sources, references and literature used or excerpted during elaboration of this work are properly cited and listed in complete reference to the due source. Aleksei Penzentcev Advisor: RNDr. Barbora Kozliková, Ph.D. ii Acknowledgement I would like to thank my supervisor RNDr. Barbora Kozliková, Ph.D. for the opportunity to participate in the project of Department of Computer Graphics and Design, for her consultation and comments during the work on the thesis. Also I would like to thank Mgr. Jiří Chmelík, Ph.D. for the technical support and leading the mother project for my thesis called Newron1 and to all people participated in this project for inspiring communication and contribution to it. 1 http://www.newron.cz iii Abstract This thesis describes a way of designing architecture for a serious game in Unity 3D environment and implementation of interaction with the game via Kinect device. The architecture is designed using event-based system which makes easier adding new components into the game including support of other devices. The thesis describes main approaches used for creation of such system. The mini-game “Tower of Hanoi” is implemented as an example of usage event-based system. iv Keywords Unity 3D, game architecture, events, C#, game, game engines, Kinect, Tower of Hanoi, gestures recognition, patterns, singleton, observer, SortedList. v Contents 1 Introduction .................................................................................................... 5 2 Overview ........................................................................................................ 7 2.1 Gathering of requirement ........................................................................... 7 2.2 Total list of requirement ............................................................................. 7 2.3 Planned system overview ........................................................................... 8 3 Choosing of a game engine ............................................................................. 9 3.1 Why Unity?................................................................................................ 9 3.2 CryEngine (4d generation) ....................................................................... 10 3.2.1 License ........................................................................................... 10 3.2.2 Features .......................................................................................... 10 3.3 Unreal Engine 4 ....................................................................................... 11 3.3.1 Features .......................................................................................... 12 3.3.2 License ........................................................................................... 12 3.4 Ogre ......................................................................................................... 13 3.4.1 Features .......................................................................................... 13 3.4.2 License ........................................................................................... 14 3.5 Unity 3d ................................................................................................... 14 3.5.1 License ........................................................................................... 15 3.5.2 Features .......................................................................................... 15 3.6 Project Anarchy ....................................................................................... 16 3.6.1 Features .......................................................................................... 17 3.6.2 License ........................................................................................... 17 3.7 Comparison of game engines ................................................................... 18 1 4 Devices ......................................................................................................... 19 4.1 Kinect device ........................................................................................... 19 4.2 Other devices ........................................................................................... 21 4.2.1 Mouse/keyboard ............................................................................. 21 4.2.2 Leap motion .................................................................................... 22 4.2.3 Touchscreen .................................................................................... 23 4.2.4 Oculus Rift ..................................................................................... 24 5 General Unity ............................................................................................... 26 5.1 Common elements ................................................................................... 26 5.1.1 MonoBehaviour .............................................................................. 26 5.1.2 GameObject .................................................................................... 26 5.1.3 Scripts ............................................................................................. 26 5.1.4 Prefabs ............................................................................................ 27 5.1.5 Unity Resources .............................................................................. 27 5.1.6 Unity Scenes ................................................................................... 27 5.1.7 Unity Packages ............................................................................... 28 5.2 Unity Lifecycle ........................................................................................ 28 5.2.1 First scene load ............................................................................... 28 5.2.2 Before first frame update ................................................................ 29 5.2.3 Update order ................................................................................... 29 5.2.4 When quitting ................................................................................. 29 5.2.5 When object is destroyed ................................................................ 29 5.3 Patterns implemented in Unity ................................................................. 30 5.4 Unity as a component-based engine ......................................................... 31 6 Game architecture......................................................................................... 32 2 6.1 Architecture layers ................................................................................... 32 6.1.1 The device driver level .................................................................... 32 6.1.2 The wrappers level .......................................................................... 32 6.1.3 The common interface level ............................................................ 33 6.1.4 The game core ................................................................................ 33 6.1.5 The mini-game level ....................................................................... 33 6.2 Design patterns ........................................................................................ 34 6.2.1 Wrapper .......................................................................................... 35 6.2.2 Singleton ......................................................................................... 35 6.2.3 Observer ......................................................................................... 35 6.3 Event-based system .................................................................................. 37 6.4 Event-based system implementation ........................................................ 39 6.4.1 CommandMonoBehaviour .............................................................. 40 6.4.2 PendingCommand........................................................................... 41 6.4.3 GameEvent ..................................................................................... 42 6.4.4 GameEventArgs .............................................................................. 44 6.5 Basic classes ............................................................................................ 44 6.5.1 MonoBehaviourBase ...................................................................... 44 6.5.2 Singleton ......................................................................................... 45 6.5.3 MouseControl ................................................................................. 45 7 Kinect Interaction ......................................................................................... 46 7.1 Assets used .............................................................................................. 46 7.1.1 Kinect with MS-SDK ...................................................................... 46 7.1.2 KinectExtras with MsSDK .............................................................. 46 7.2 Kinect Manager ....................................................................................... 48 3 7.3 Interaction Manager ................................................................................. 49 7.4 Gesture Listener ......................................................................................