14
Introduction to Game Programming Introduction to Game Programming Autumn 2016 Autumn 2016 Autumn 2016 Autumn 2016 3. Game architecture case 3. Game architecture case Unity Unity game engine game engine Juha Vihavainen Juha Vihavainen University of Helsinki University of Helsinki Outline Outline Basic concepts and architecture of Basic concepts and architecture of Unity Unity On origins/developments of On origins/developments of Unity Unity Unity Unity as an integrated development environment (IDE): as an integrated development environment (IDE): Unity Unity as an integrated development environment (IDE): as an integrated development environment (IDE): Unity Unity world/level editor and its major user interfaces world/level editor and its major user interfaces The logical architecture of a The logical architecture of a Unity Unity game game scenes scenes => => game game objects objects => => components => settings, scripts components => settings, scripts Asset handling in Asset handling in Unity Unity; project's reusable ; project's reusable models models and and images images (textures textures) are seen in ) are seen in Project Project pane (located in pane (located in Assets Assets folder) folder) (textures textures) are seen in ) are seen in Project Project pane (located in pane (located in Assets Assets folder) folder) Briefly on implementation and architecture of the Unity engine Briefly on implementation and architecture of the Unity engine Unity Unity scripting in more detail later scripting in more detail later 6.12.2016 6.12.2016 Juha Vihavainen / University of Helsinki Juha Vihavainen / University of Helsinki 2

Introduction to Game Programming Autumn 2016 3. Game ... · Introduction to Game Programming Autumn 2016 3. ... (low level, in C) ... The main parts of the UI of Unity Editor

Embed Size (px)

Citation preview

Introduction to Game ProgrammingIntroduction to Game ProgrammingAutumn 2016 Autumn 2016 Autumn 2016 Autumn 2016

3. Game architecture case 3. Game architecture case UnityUnity game enginegame engine

Juha VihavainenJuha Vihavainen

University of HelsinkiUniversity of Helsinki

OutlineOutline

Basic concepts and architecture of Basic concepts and architecture of UnityUnity

�� On origins/developments of On origins/developments of Unity Unity

�� UnityUnity as an integrated development environment (IDE): as an integrated development environment (IDE): �� UnityUnity as an integrated development environment (IDE): as an integrated development environment (IDE): UnityUnity world/level editor and its major user interfacesworld/level editor and its major user interfaces

�� The logical architecture of a The logical architecture of a UnityUnity gamegame

�� scenesscenes => => gamegame objectsobjects => => components => settings, scriptscomponents => settings, scripts

�� Asset handling in Asset handling in UnityUnity; project's reusable; project's reusablemodels models andandimages images ((texturestextures) are seen in ) are seen in ProjectProject pane (located in pane (located in AssetsAssets folder)folder)((texturestextures) are seen in ) are seen in ProjectProject pane (located in pane (located in AssetsAssets folder)folder)

�� Briefly on implementation and architecture of the Unity engineBriefly on implementation and architecture of the Unity engine

�� UnityUnity scripting in more detail laterscripting in more detail later

6.12.20166.12.2016 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 22

ReferencesReferences

�� Lots and lots of Unity documentation and manuals, both online and Lots and lots of Unity documentation and manuals, both online and printed versionsprinted versions

Michael P. Rogers, Bringing Michael P. Rogers, Bringing UnityUnity to the classroom. In to the classroom. In Journal Journal �� Michael P. Rogers, Bringing Michael P. Rogers, Bringing UnityUnity to the classroom. In to the classroom. In Journal Journal of Computing Sciences in Colleges of Computing Sciences in Colleges 27 (2012), 5 (May), 17127 (2012), 5 (May), 171--177.177.

�� Philip Chu, Philip Chu, Game development with UnityGame development with Unity, Technicat LLC, , Technicat LLC, 2010.2010.(One nice condensed introduction to Unity)(One nice condensed introduction to Unity)

�� Joseph Hocking Joseph Hocking , Unity in Action , Unity in Action -- Multiplatform game Multiplatform game development in C# with Unity 5. Manning, 2015.development in C# with Unity 5. Manning, 2015.

�� . . .. . .

6.12.20166.12.2016 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 33

Choosing a game engineChoosing a game engine�� One option was an One option was an inin--house game engine house game engine that usually only did what the that usually only did what the

game requiredgame required

�� Then, commercial fullThen, commercial full--featuredfeaturedUnrealUnreal (by (by Epic GamesEpic Games, USA) and , USA) and CryEngineCryEngine (by German game developer (by German game developer CrytekCrytek) were often licensed on ) were often licensed on (by German game developer (by German game developer ) were often licensed on ) were often licensed on a pera per--game basis game basis

�� The The UnityUnity engine and development environment engine and development environment has become a popular has become a popular choice as an engine for small studios and individualschoice as an engine for small studios and individuals

�� offers a lot of highoffers a lot of high--end features (physics, integrated asset mgmt..)end features (physics, integrated asset mgmt..)

�� has a has a freefree version and lowversion and low--cost cost ProPro versions (details changing)versions (details changing)

runs either on a runs either on a MacMac (originally) or on a (originally) or on a WindowsWindows PCPC�� runs either on a runs either on a MacMac (originally) or on a (originally) or on a WindowsWindows PCPC

�� targets several platforms; in 2013, made the iOS and Android targets several platforms; in 2013, made the iOS and Android licenses free for Unity freelicenses free for Unity free--version usersversion users

�� Unity Free has no fee; it is available Unity Free has no fee; it is available for any usefor any useto individuals or to individuals or companies with companies with less than $100,000 of annual gross revenueless than $100,000 of annual gross revenue

6.12.20166.12.2016 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 44

Background: many kinds of libraries/enginesBackground: many kinds of libraries/engines�� Game development is mostly in C/C++ and script languages, e.g.Game development is mostly in C/C++ and script languages, e.g.

�� UnrealUnreal Engine Engine uses uses C++ C++ (for core system code) and optionally a (for core system code) and optionally a custom visual script languagecustom visual script languageBlueprintBlueprint (for (for gameplay)gameplay)

�� UnityUnity is mostly implemented in C++ (and partly in is mostly implemented in C++ (and partly in BooBoo, I think) , I think) �� UnityUnity is mostly implemented in C++ (and partly in is mostly implemented in C++ (and partly in BooBoo, I think) , I think) but can use but can use UnityScriptUnityScript and C# as scripting languagesand C# as scripting languages

�� BlenderBlender is coded in C, C++ and is coded in C, C++ and PythonPython; ; PythonPython is used as an is used as an internal scripting language (including its game engine part)internal scripting language (including its game engine part)

�� OgreOgre graphics engine (over 1,300,000 lines of C++)graphics engine (over 1,300,000 lines of C++)

�� OpenGLOpenGL and and DirectXDirectX graphics libraries (low level, in C)graphics libraries (low level, in C)

�� Use mostly the same fundamental concepts (graphics, update loop)Use mostly the same fundamental concepts (graphics, update loop)�� Use mostly the same fundamental concepts (graphics, update loop)Use mostly the same fundamental concepts (graphics, update loop)

�� We’ll do little or no 3D modeling; it is assumed friendly artists will We’ll do little or no 3D modeling; it is assumed friendly artists will do that for us (or we can search do that for us (or we can search freefree assets from the web)assets from the web)

�� We’ll only be interested in interactive video games, and not in We’ll only be interested in interactive video games, and not in general graphicsgeneral graphics

Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 556.12.20166.12.2016

UnityUnity basicsbasics�� Unity is a Unity is a multimulti--platformplatform development tooldevelopment tool

�� platformsplatforms includeinclude: : desktopsdesktops, mobile , mobile devicesdevices, , webweb pagespages, , consolesconsoles

�� Unity’s visual editor has several sections that work togetherUnity’s visual editor has several sections that work together

�� build/editbuild/edit scenes/levelsscenes/levels, , editingediting of a of a selectedselected gamegame objectobject (in (in inspectorinspector pane)pane)

�� scripts are attached to scripts are attached to objects as special kinds of objects as special kinds of componentscomponents, and , and executed by a hidden game loopexecuted by a hidden game loop

�� a a UnityUnity projectproject is is representedrepresented byby a a folderfolder

�� C# scripts are edited and processed by a separate programming C# scripts are edited and processed by a separate programming �� C# scripts are edited and processed by a separate programming C# scripts are edited and processed by a separate programming environment (environment (MonoDevelopMonoDevelop/Visual Studio); /Visual Studio); UnityScriptUnityScript by a by a suitable text editorsuitable text editor

�� interactions/processinginteractions/processing betweenbetween differentdifferent sections (views) sections (views) is is mostlymostly automatic, e.g., updating settings change visualsautomatic, e.g., updating settings change visuals

6.12.20166.12.2016 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 66

On history/developments (2005 On history/developments (2005 --> > ))

�� Started 2005 as a Started 2005 as a MacMac--based tool developing for based tool developing for MacMac and and WindowsWindows

�� WindowsWindows--based version available 2009 based version available 2009 (Unity 2.5) (Unity 2.5)

�� Unity 3.5 (Feb 2012), new Unity 3.5 (Feb 2012), new ShurikenShuriken particle system, HDR, etc.particle system, HDR, etc.

�� Unity 4 (June 2012): Unity 4 (June 2012): Mecanim Mecanim animation system (animation system (boughtbought), ), DirectDirectX11 X11 support, support, UbuntuUbuntu platform, etc.platform, etc.

�� Unity 4.2 (July 2013): Android, iOS, Windows Phone 8, etc. were Unity 4.2 (July 2013): Android, iOS, Windows Phone 8, etc. were included with the included with the freefree license; dyn. shadows w/ onelicense; dyn. shadows w/ one--directional lightdirectional light

�� Unity 4.3 (2013) added complete native 2D tools (instead of 3rdUnity 4.3 (2013) added complete native 2D tools (instead of 3rd--party party 2D tools), blendshape facial animation, among others 2D tools), blendshape facial animation, among others 2D tools), blendshape facial animation, among others 2D tools), blendshape facial animation, among others

�� In July 2013, reached over 2 million registered Unity users In July 2013, reached over 2 million registered Unity users (downloads)(downloads)

�� In March 3, 2015, the release of In March 3, 2015, the release of Unity 5.0Unity 5.0 had improvements in had improvements in shading techniques, lighting, audio, animation, WebGL (soon), etc.shading techniques, lighting, audio, animation, WebGL (soon), etc.

6.12.20166.12.2016 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 77

Some more historySome more history�� On May 21, 2002, Nicholas Francis, a Danish programmer, posted on the On May 21, 2002, Nicholas Francis, a Danish programmer, posted on the

Mac Mac OpenGLOpenGL board asking for assistance with a shader system he was trying board asking for assistance with a shader system he was trying to implement into his game engine; Joachim Ante responded; David to implement into his game engine; Joachim Ante responded; David Helgason heard about the project and thought they were "really onto Helgason heard about the project and thought they were "really onto something", so jumped aboard as the third developersomething", so jumped aboard as the third developersomething", so jumped aboard as the third developersomething", so jumped aboard as the third developer

�� Unity: "Unity: "A toolset used to build games, and .. the technology that executes the A toolset used to build games, and .. the technology that executes the graphics, the audio, the physics, the interactions, and the networkinggraphics, the audio, the physics, the interactions, and the networking""

�� Needed to make a full commercial game using their new Needed to make a full commercial game using their new engine; engine; GooballGooball was published in March 2005was published in March 2005

Nowadays, Unity has hundreds of employees around the world

engine; engine; GooballGooball was published in March 2005was published in March 2005

�� Using the profits from Using the profits from GooballGooball, the company hired more, the company hired moredevelopers to refine Unity before its initial 1.0 release in June 2005developers to refine Unity before its initial 1.0 release in June 2005

�� an opportunity to tear apart the engine to find bugs, remove annoyances, an opportunity to tear apart the engine to find bugs, remove annoyances, and fix the interface before its official release and fix the interface before its official release

6.12.20166.12.2016 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 88

Some distinguishing featuresSome distinguishing features

�� Supports development of a wide range of games on diverse platformsSupports development of a wide range of games on diverse platforms

�� Supports Supports CC# and # and UnityScriptUnityScript (earlier also (earlier also BooBoo) as scripting languages ) as scripting languages

�� A single IDE provides prototyping tools for game developmentA single IDE provides prototyping tools for game development�� A single IDE provides prototyping tools for game developmentA single IDE provides prototyping tools for game development

�� edit world/level => edit components/scripts => run the game => . .edit world/level => edit components/scripts => run the game => . .

�� Applies Applies CompositeComposite, , ComponentComponent, , PrototypePrototype, , Game Loop, Update Game Loop, Update Method Method plus other design patterns in its design and implementationplus other design patterns in its design and implementation

�� Especially, uses a wellEspecially, uses a well--thought design for game objects thought design for game objects

�� uses a version of "uses a version of "propertyproperty--centriccentric" approach to game objects" approach to game objects�� uses a version of "uses a version of "propertyproperty--centriccentric" approach to game objects" approach to game objects

�� dynamic dynamic componentscomponents simulate multiple inheritance/mixins simulate multiple inheritance/mixins (to compose an object from multiple varying parts)(to compose an object from multiple varying parts)

�� Utilizes C# builtUtilizes C# built--in iterators to implement a in iterators to implement a coroutinecoroutine facility => one facility => one script (code block with state) may span multiple frames script (code block with state) may span multiple frames

6.12.20166.12.2016 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 99

Inheritance vs. componentsInheritance vs. componentsUnity in Action - Multiplatform game development in C# by Joseph Hocking.

6.12.20166.12.2016 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 1010

Unity game engine: basic conceptsUnity game engine: basic concepts

�� An An assetasset is anything that is imported into your project (is anything that is imported into your project (project viewproject view), and ), and then to be instantiated & placed into the game world (then to be instantiated & placed into the game world (scene viewscene view))

�� ScenesScenes are used to create different levels (a term used by Unity docs)are used to create different levels (a term used by Unity docs)

�� separately loaded / managed (game object space and assets)separately loaded / managed (game object space and assets)�� separately loaded / managed (game object space and assets)separately loaded / managed (game object space and assets)

�� to make a "to make a "persistentpersistent" object: call " object: call DontDestroyOnLoad (object) DontDestroyOnLoad (object)

�� A A game object game object is a essentially a container for componentsis a essentially a container for components

�� A A componentcomponent is something to be attached to a game entity, describing is something to be attached to a game entity, describing some property, capability, behaviour, or relationship some property, capability, behaviour, or relationship

�� created independently but always attached to some game objectcreated independently but always attached to some game object�� created independently but always attached to some game objectcreated independently but always attached to some game object

�� can be separately removed and destroyedcan be separately removed and destroyed

�� A A scriptscript is a special kind of component that defines the is a special kind of component that defines the behaviourbehaviour of a of a game object; the same script class can be "attached" to game object; the same script class can be "attached" to multiplemultiplegameobjects, and gameobjects, and multiplemultiple scripts can be attached to the same objectscripts can be attached to the same object

6.12.20166.12.2016 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 1111

How to start a game development with How to start a game development with UnityUnity

1.1. Create a Unity Create a Unity projectproject for the game (creates a folder, actually)for the game (creates a folder, actually)

2.2. Import Import assets assets viavia menumenu, or (directly) to the, or (directly) to theAssetsAssets folderfolder

3.3. Create a Create a scenescene for each for each level level (or a game screen/page)(or a game screen/page)3.3. Create a Create a scenescene for each for each level level (or a game screen/page)(or a game screen/page)

4.4. In each scene, select and place initial assets into the game worldIn each scene, select and place initial assets into the game world

5.5. Adjust/place the main (default) Adjust/place the main (default) cameracamera; add cameras as desired; add cameras as desired

6.6. Add light objects, adjust ambient light..Add light objects, adjust ambient light..

7.7. Add and adjust materials in objects' renderer componentsAdd and adjust materials in objects' renderer components

8.8. Attach Attach rigidbodiesrigidbodies, , physicsphysics materialsmaterials, , colliderscolliders to objectsto objects

9.9. Write and attach Write and attach scriptsscripts to objects.to objects.

10.10. Test the game in the Editor's "Test the game in the Editor's "Game WindowGame Window" (pane, view)" (pane, view)

11.11. Publish to the desired platform, building selected scenesPublish to the desired platform, building selected scenes

6.12.20166.12.2016 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 1212

The main parts of the UI of Unity EditorThe main parts of the UI of Unity Editor1.1. Project view Project view shows all of the project's assets, possibly in their shows all of the project's assets, possibly in their

own subfolders (can select own subfolders (can select oneone-- or or twotwo--columncolumn formats)formats)

2.2. Scene view Scene view where we arrange and manipulate game objects; where we arrange and manipulate game objects; describes the initial configuration (state) of the level (scene)describes the initial configuration (state) of the level (scene)describes the initial configuration (state) of the level (scene)describes the initial configuration (state) of the level (scene)

3.3. Hierarchy view Hierarchy view lists the objects of the current scene in a tree form lists the objects of the current scene in a tree form (an alternative view on all the game objects, in alphabetical order)(an alternative view on all the game objects, in alphabetical order)

4.4. Game window Game window shows the running game (as seen by the player)shows the running game (as seen by the player)

5.5. InspectorInspector where we can access asset parameters, game objects'where we can access asset parameters, game objects'settings, components, script fields, and scene or project settingssettings, components, script fields, and scene or project settingssettings, components, script fields, and scene or project settingssettings, components, script fields, and scene or project settings

6.6. ConsoleConsole can display system errors and warnings, user log/trace can display system errors and warnings, user log/trace output with output with Debug.Log ("Hello");Debug.Log ("Hello");, etc., etc.

NoteNote. Never rearrange or rename the contents of the project’s assets . Never rearrange or rename the contents of the project’s assets folder outside the folder outside the UnityUnity editor (but just adding/updating is OK).editor (but just adding/updating is OK).

6.12.20166.12.2016 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 1313

Parts of the interface in UnityParts of the interface in Unity

6.12.20166.12.2016 1414

Editor screenshot: Editor screenshot: ToolbarToolbar, , SceneScene, and , and GameGame

6.12.20166.12.2016 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 1515

6.12.20166.12.2016 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 1616

Game world/level

Hierarchy ProjectInspector

6.12.20166.12.2016 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 1717

Running game

Sample of Unity Editor toolbar controls Sample of Unity Editor toolbar controls

Alt Alt + RHB

Game "player" (~ video player)

pan orbit zoommove rotate scaleManipulate the Manipulate the selected game objectselected game object

6.12.20166.12.2016 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 1818

(~ video player)

To To selectively control which control which objects are rendered by which objects are rendered by which cameras or lit by which lightscameras or lit by which lights(also collisions and raycasting)(also collisions and raycasting)

Select from Select from default ordefault orpredefined world predefined world EditorEditor layoutslayouts

Unity game architectureUnity game architecture

The game objects (included in a scene) form a treeThe game objects (included in a scene) form a tree--like hierarchy like hierarchy determined by parentdetermined by parent--child relationships ( ~ child relationships ( ~ scene graphscene graph))

�� children are affected by changing the parent's transform children are affected by changing the parent's transform �� children are affected by changing the parent's transform children are affected by changing the parent's transform properties: properties: positionposition, , rotationrotation, and , and scalescale

�� a child can also be changed and updated independently, but the a child can also be changed and updated independently, but the transform properties are interpreted transform properties are interpreted in relation to in relation to the parentthe parent

Hierarchy view: Hierarchy view: the initial the initial

6.12.20166.12.2016 1919

the initial the initial contents of the contents of the scenescene

The main entities in Unityby [Petri Veijonen]

Unity's own root class

C# root class

object

AddComponent (type)GetComponent (type) : Component

- combines aggregation with inheritance

Can be enabled/disabled

Transform is not optional

childCountparentGetChild (index):Transform;

GetComponent (type) : ComponentObject.Destroy (obj)

AudioListener

Light

Game object scripts

6.12.20166.12.2016 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 2020

materials (shaders)AudioSource

AudioListener

Attach responsibilities to an object dynamically. Provides an

Get common Components via public variables.

Note the duplication of interfaces in GameObjectand Component.

. . .

BroadcastMessage calls the method on MonoBehavioursin this game object or any of its children (a tree).

object dynamically. Provides an alternative to subclassing. . . .

// these are obsolete. .// these four has been

deprecated in 5.0.; use GetComponent

+name is inherited

2121GameObject is sealed, Component is not.

Note. Not identical.

Common game object Common game object componentscomponents�� TransformTransform specifies position, rotation, and scalespecifies position, rotation, and scale

�� MonoBehaviourMonoBehaviour adds custom functionality (as scripts)adds custom functionality (as scripts)

�� MeshFilterMeshFilter represents a 3D mesh from therepresents a 3D mesh from theAssets Assets folderfolder

�� MeshRendererMeshRenderer draws the game object (with settings/materials..)draws the game object (with settings/materials..)�� MeshRendererMeshRenderer draws the game object (with settings/materials..)draws the game object (with settings/materials..)

�� ColliderCollider makes rigid bodies react when colliding/touchingmakes rigid bodies react when colliding/touching

�� RigidbodyRigidbody makes a game object obey physics (gravity, drag..)makes a game object obey physics (gravity, drag..)

�� but but kinematickinematic rigidbodiesrigidbodies if if movedmoved only by its only by its TransformTransform

�� but they still affect but they still affect otherother physicsphysics--controlled objects controlled objects

�� CameraCamera to view the world from the game object's perspectiveto view the world from the game object's perspectiveCameraCamera to view the world from the game object's perspectiveto view the world from the game object's perspective

�� LightLight can act as a lighting source (lamp, other emissive object)can act as a lighting source (lamp, other emissive object)

�� CharacterControllerCharacterController moves moves an object by a script, instead an object by a script, instead of of a a RigidbodyRigidbody (still affected by collisions)(still affected by collisions)

�� GUITextGUIText to be associated with a particular game objectto be associated with a particular game object

6.12.20166.12.2016 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 2222

A script's publicvariables are viewed and edited within the IDE: booleans appear as checkboxes;strings as textfields;

6.12.20166.12.2016 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 2323

Initialization in the Inspector overrides initialization in the script code

strings as textfields; etc.

The class The class MonoBehaviourMonoBehaviour

�� The base class for The base class for scriptsscripts

�� AwakeAwake (), (), StartStart (), (), UpdateUpdate (), (), FixedUpdateFixedUpdate (), (), LateUpdateLateUpdate (), (), and and

can be enabled/disabled

FixedUpdateFixedUpdate (), (), LateUpdateLateUpdate (), (), and and OnGUIOnGUI () () are kindare kind of of callbacks callbacks (executed by the engine)(executed by the engine)

�� The variableThe variablegameObjectgameObject refers to the refers to the owner game object;owner game object; alsoalso::transform, transform, name, tag name, tag

�� Convenient notation Convenient notation to access other to access other Delayed calls Delayed calls

2424

�� Convenient notation Convenient notation to access other to access other components (components (nullnull if not attachedif not attached): ):

c = GetComponent <Collider> (); . . .c = GetComponent <Collider> (); . . .c = script.GetComponent <Camera> ();c = script.GetComponent <Camera> ();

Sample of services;some events require colliders

Coroutines named Coroutines named by string value by string value

Callbacks called Callbacks called if presentif present

CollidersColliders in Unityin Unity

�� CollidersColliders give game objects a "give game objects a "physical presencephysical presence" so that they " so that they "" interactinteract" (touch, push, collide) with each other" (touch, push, collide) with each other

�� A A mesh collider mesh collider follows the surface of a geometry (model): expensivefollows the surface of a geometry (model): expensive

�� Each primitive (builtEach primitive (built--in) game object has in) game object has aadefault collider; they aredefault collider; they are�� Each primitive (builtEach primitive (built--in) game object has in) game object has aadefault collider; they aredefault collider; they aremore efficientmore efficient

Set physics Set physics materialsmaterials to to define define frictionfriction and and bounciness; bounciness; provided as provided as standard assets.standard assets.

6.12.20166.12.2016 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 2525

NoteNote. Put . Put rigidbodiesrigidbodies on on game objects that both game objects that both movemove and collide and collide -- that that react to collisions and react to collisions and other forces (e.g., gravity).other forces (e.g., gravity).

On the implementation of UnityOn the implementation of Unity

�� Unity is closedUnity is closed--source, so we cannot but guess at its actual internal source, so we cannot but guess at its actual internal implementation (and anyway, it keeps changing)implementation (and anyway, it keeps changing)

�� Unity engine is itself written in C/C++ butUnity engine is itself written in C/C++ but

�� game logic is expressed via scripts (C#, game logic is expressed via scripts (C#, UnityScriptUnityScript))

�� Generally, a componentGenerally, a component--based engine supports well user interfaces that based engine supports well user interfaces that use draguse drag--andand--dropdrop--style game creationstyle game creation

�� any component can be handled both in the editor and by script codeany component can be handled both in the editor and by script code

�� All scripts are compiled to a .NET .All scripts are compiled to a .NET .dlldll file (i.e., an assembly) file (i.e., an assembly) -- and and �� All scripts are compiled to a .NET .All scripts are compiled to a .NET .dlldll file (i.e., an assembly) file (i.e., an assembly) -- and and finally to native code finally to native code -- so script languages tend to behave rather alike, so script languages tend to behave rather alike, except perhaps differences in compileexcept perhaps differences in compile--time vs. runtime vs. run--time typing/bindingtime typing/binding

�� UnityScriptUnityScript and C# are compiled into different and C# are compiled into different assembliesassemblies so you so you can't just refer to one from the other (messy compilation orders..)can't just refer to one from the other (messy compilation orders..)

6.12.20166.12.2016 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 2626

Unity system architecture (hypothetical sketch only)Unity system architecture (hypothetical sketch only)

[by Petri Veijonen]

�� Unity physics is based on a version of the Unity physics is based on a version of the PhysXPhysX physics simulation physics simulation engine; implementing/installing your own would be a major undertaking!engine; implementing/installing your own would be a major undertaking!

6.12.20166.12.2016 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 2727