Вы находитесь на странице: 1из 122

Week 1

• Course Overview
• Introduction to Unity (3D centric)
• Game Objects
§ All course information is available on Blackboard
§ Course Outline
§ Assignments
§ Notes
§ Announcements

§ Link
§ http://learn.humber.ca

2
§ College Closed Dates
§ Monday, September 3rd, 2018 (Labour Day)
§ Monday, October 8th, 2018 (Thanksgiving)

§ Last Day to Withdraw without academic penalty


§ Friday, November 16th, 2018

§ Last Day of Classes


§ Friday, December 14th, 2018

3
§ GDD Submission
§ Wednesday, September 26th, 2018 (Week 4)

§ Game Presentation
§ Thursday, December 13th, 2018 (Week 15)

4
§ Introduction to Unity (3D centric)
§ Game Objects

§ Intermediate C# in Unity
§ C# in Unity (Intermediate)
§ Out parameters / ref parameters / operator overloading / vectors

§ Exception Handling
§ Try / catch / finally
§ Custom exceptions
§ Enumerations
§ Destructors
§ The cost of co-routines

5
§ Data Structures
§ Dictionary / Stacks / Queues

§ Callbacks
§ Callbacks / Dynamic callbacks

§ Lambda Expressions
§ Anonymous Expressions

§ Source Control & Debugging


§ Git / SVN
§ Diff / Merge / KDiff
§ Locals / Call Stack / Watch List

6
§ Managing Scenes
§ Working with Scenes
§ Creating Screens
§ Moving between Scenes

§ Terrain Tools
§ Painting Terrain

§ Loading Meshes and Making Prefabs


§ Import / Mecanim / Prefab generation

7
§ Connecting to Input
§ Connecting Input to First / third person controls

§ Collision Detection and Colliders


§ Mesh Collisions
§ Broad Phase / Narrow Phase

§ Pickups / Effects
§ Adding Effects
§ Adding Pickups
§ Control UI
§ Particle Systems

8
§ Unity NavMesh
§ Nav Mesh / Weak Path finding

§ Publishing
§ Build Settings
§ Web
§ Desktop
§ Android
§ iOS
§ Windows Store
§ Windows Phone
§ Consoles

9
§ Level Design Considerations for 3D games
§ Level Progression & Beat Charts
§ Metrics
§ Procedural level generation
§ World Maps

§ Going Beyond
§ Multi-Player / Split Screen

10
§ Game Design Document (Due Week 4)
§ Game plan for the game will completed using the provided
template as a guide for creating the final game
§ Game Idea must be approved week 2 before work is started on the
GDD and the game

§ Project/Labs Development (Weekly)


§ Weekly labs will build towards creating a final build of the game or
assist with the development of the game

§ Game Presentation and Game Playability (Week 15)


§ Final game will be presented and play tested during the final class

11
§ Introduction to Unity (3D centric)
§ Projects
§ Panels
§ Prefabs
§ Game Objects

12
§ Become familiar with the following:
§ Unity Manual
§ Designed to help learn how to use Unity, from basic to advanced
techniques
§ Can be read from start to finish or used as a reference.
§ Unity Scripting Reference
§ Contains details of the scripting API that Unity provides
§ Examples use C# or JavaScript
§ Unity Answers
§ Can ask and answer questions about development with Unity
§ Unity Forums
§ More information such as tutorials, announcements and general support
of Unity

13
14

New Projects
Saving Projects
Archiving Projects
§ Create a new Project
§ Start up Project Wizard

Click to create a
new Project

15
§ Give Project a name
§ Can be changed later if a temporary name is chosen

16
§ Choose Location to save project to
§ Can be copied to a new location later

17
§ Choose Project Type

§ Sets default import settings for the Project

18
§ Click Asset packages… to import built-in

§ Other Asset packages can be added later on

19
§ Click Asset packages… to import built-in

§ Other Asset packages can be added later on

20
§ Click Create Project to Create project without adding any
assets or after select Assets from previous slide

§ Asset packages can be added later on


21
§ Create a new Project with Unity3D open
§ Click FileàNew Project
§ Follow previous steps

Click to create
a new Project

22
§ Project is now created

23
§ Project is now created

Project Panel may or may not be empty


24
- Depends on Asset packages selected
§ Everything in the Project Panel is saved as soon as it has been
created or imported into the Project
§ Everything in the Hierarchy must be saved as part of a Scene
§ Anything not saved in a Scene will still exist, it just wont be saved at
the location its in Scene

Not Saved

25
§ Everything in the Project Panel is saved as soon as it has been
created or imported into the Project
§ Everything in the Hierarchy must be saved as part of a Scene
§ Anything not saved in a Scene will still exist, it just wont be saved at
the location its in Scene

Saved

26
§ Save all Scenes before exiting Unity
§ Save Scene
§ Save Scene as…

§ All roads will lead to saving the scene, choose one

27
§ All Scenes will be saved to the Parent Asset Folder of the
Project but within a Scenes Folder

28
§ Save all Scenes to the Asset Folder of the Project

Location

29
§ Save all Scenes to the Asset Folder of the Project

Scene Name

30
§ Check the Project Panel for the Scene as a check to make sure
it was saved
§ If the Scene is there with the Unity Icon, it’s saved

§ Try saving all scenes in a folder called Scenes to make it easier to


find when working with larger Projects

31
§ Click Create to bring up the Drop Down menu
§ Choose Folder

§ Name the new folder Scenes


§ F2 is typically the shortcut to rename a folder
§ Alternatively, click once to select and once to rename

32
§ Click and drag the Scene into Scenes folder

33
§ Opening from Project splash screen at start-up
§ Click on Open other to load a project from a directory or from
Previous project section

Click to open a
project not listed in
previous projects
section 34
§ Opening from Project splash screen at start-up
§ Click on Open other to load a project from a directory or from
Previous project section

Otherwise, click the


Project from previous
projects section 35
§ To open a new Project while an existing one is open, click File
and Open Project

36
§ Open Project will go to Recent Projects screen
§ Select the Project to load by clicking on the name

37
§ Select Open other to choose a different Project not listed in
Recent projects
§ Can happen when a folder name is changed or moved

38
§ Locate Project Folder with Project

39
§ Click Select Folder to load the Project
§ If Assets or Library folders are shown, go up one directory

40
§ If there is nothing in the Scene Panel once the Project is loaded,
look in the Project Panel for the Saved Scene
§ Double click the Scene file to load all assets in the Scene Panel

§ If the Scene cannot be found, it was not saved and everything will
need to be started from scratch

41
§ Works like moving a folder in Windows Explorer
§ With Unity closed, locate the Project Folder
§ Click and move the Project folder to a new location

42
§ If needed, change the Project folder name or copy and Paste
the Project folder to a new location

43
§ Locate Folder to be archived
§ Right-Click Folder and choose Send To à Compressed(zipped)
Folder or use another archiving tool that is installed

44
§ Do not move or archive Folders in the Project directory
§ Always uses the Project Panel to move or change things

§ Moving Folders can break things in the Project

45
§ Unity doesn’t open a Project by default
§ Change by going to EditàPreferences

Check to Load
Previous Project
at start

46
§ Change editor to Visual Studio from MonoDevelop
§ Click the drop down to change it

47
48

Layouts
Panels
§ Main Editor Window

49
§ Click Layout Button

50
§ Select 2 by 3

51
§ Should look like the following

52
§ Change the Asset Panel to Single Column

53
§ Change the Asset Panel to Single Column

54
§ Single Column Project View should look like the following:

55
§ Project View
§ Game assets for the project are stored here
§ Scripts, 3D models, textures, audio files and prefabs
§ Organize contents into folders to make it easier to find

56
§ Avoid moving assets outside of Unity
§ Use Project View to organize assets
§ Each object contains metadata links within assets and can break, which
can potentially corrupt a project

§ Adding Assets:
§ Drag Assets into Project View
§ Import Assets using AssetsàImport New Assets

57
§ Scenes are stored in the Project View
§ Scenes are the levels of the game

§ Creating new scenes


§ Shortcut: Ctrl-N

§ Assets that can be created


within Unity are shown
on the right

58
§ Contains GameObjects in Current Scene
§ 3D Models
§ Next slide shows the breakdown of what can be used to create and the
models
§ Prefabs
§ Custom objects that will make up much of the game

59
§ Parenting
§ Make objects Children of other GameObjects
§ To make a GameObject a Child of another, drag one GameObject onto
another GameObject in the Hierarchy
§ Child inherits movement and rotation of its Parent
§ Helps when an 3D Model was not properly exported
§ Can now expand and contract parent to see the children through the
Hierarchy

60
§ Click GameObjectàCreate Empty
§ An empty container object
§ Simply a point in the world that can only be selected using the
Hierarchy Panel
§ Any object can be made from this Empty GameObject
§ Audio
§ Player
§ Trigger

61
§ Let’s create some GameObjects yo demonstrate tools, views
and other awesome Unity things an object will be created
§ Click GameObjectàOther ObjectàCube
§ Adds Cube to Scene

§ Check Inspector
§ Set Cube (x,y,z) position to (0,0,0)

62
§ Align with View
§ Typically used with the camera
§ Moves the camera or GameObject to the current view in the scene

63
§ Displays information about
a selected GameObject
§ Includes all attached
Components and properties
§ Functionality of GameObjects
can be modified

64
§ Duplicate (Ctrl-D)
§ Frame (F)
§ Brings an object into frame focus

§ Find (Ctrl-F)
§ Finds objects inside of a scene

65
§ Save Selection ( Ctrl+Alt+(1-9) )
§ Allows developer to group selections together
§ Similar to a unit group in an RTS game

§ Load Selection ( Ctrl+Shift+(1-9) )


§ Selects previously grouped objects

§ Snapping
§ Can be assigned to snap objects to
§ Hold ctrl and move the object around

66
§ Consists of five basic controls
§ Transform Tools
§ Used with Scene View

§ Transform Gizmo Tools


§ Affect Scene View display

§ Play/Pause/Step Button
§ Used with the Game View

67
§ Consists of five basic controls
§ Layers Drop-down
§ Controls which objects are displayed in Scene View

§ Layout Drop-down
§ Controls arrangement of all Views

68
§ Blank canvas to start creating the game
§ Used to select and position
§ Environments
§ Player
§ Camera
§ Enemies
§ Other GameObjects

69
§ Scene View Navigation
§ Click Right Mouse button to enter Flythrough mode
§ WASD keys move the View
§ Mouse handles turning
§ ‘Q’ and ‘E’ is for up and down in first person view
§ Spacebar flips views from windowed to full screen

§ Click Scene View


§ Cursor keys can now be used to move around the environment on one
plane

70
§ Scene View Navigation
§ Alt + Left click
§ Drag to orbit camera around current pivot point
§ Alt + Middle click
§ Drag to drag Scene View
§ Alt + Right click
§ Drag to zoom Scene View
§ Same as scrolling with mouse wheel

71
§ Screen Gizmo
§ Click the arms to snap Scene Camera
to that direction and change to
Isometric Mode
§ While in Isometric Mode, right-click drag to orbit and Alt-click drag to
pan
§ To exit mode, click middle of Scene Gizmo
§ Shift-clicking the middle of the Scene Gizmo to toggle Isometric Mode

72
§ Positioning Game Objects
§ Focusing
§ Focus Scene View Camera on an object before manipulating
§ Select a GameObject and press ‘F’
§ Centers Scene View and pivot point on selection
§ Also known as Frame Selection

73
§ Positioning Game Objects
§ Translate, Rotate and Scale
§ Use the Transform Tools in the Toolbar to Translate, Rotate, and Scale
individual GameObjects
§ Each has a corresponding Gizmo that appears around the selected
GameObject in the Scene View.
§ Can use the mouse and manipulate any Gizmo axis to alter the Transform
Component of the GameObject, or you can type values directly into the
number fields of the Transform Component in the Inspector

74
§ Positioning Game Objects
§ Translate, Rotate and Scale

75
§ Positioning Game Objects
§ Gizmo Display Toggles
§ Defines location of any Transform Gizmo

§ Position:
§ Center positions Gizmo at center of object's rendered bounds
§ Pivot positions Gizmo at pivot point of a Mesh
§ Rotation:
§ Local keeps Gizmo's rotation relative to object's
§ Global clamps Gizmo to world space orientation

76
§ Positioning GameObjects
§ Unit Snapping
§ While dragging any GameObject using the Translate Tool, hold Control to
snap in increments defined in Snap Settings
§ To change unit distance used for unit snapping go to EditàSnap Settings

77
§ Objects placed in Scene view are added to a Default Layer
§ Layers can be added to a Project to make it easier to work with
similar objects, similar to Photoshop
§ Layers can be turned off and on

78
§ To Edit Layers, Click on the Layers Option above the inspector
§ Select Edit Layers and add what is needed

79
§ Some are locked and
cannot be changed
Locked

80
§ Some are locked and
cannot be changed
Not Locked

81
§ Some are locked and
cannot be changed

Select Grey area next


to User Layer #

82
§ Positioning Game Objects
§ Surface Snapping
§ While dragging the center using the Translate Tool, hold Shift and Control
to snap object to intersection of any Collider
§ Makes precise positioning of objects faster
§ Look-At Rotation
§ While using Rotate Tool, hold Shift and Control to rotate the object
towards a point on the surface of any Collider

83
§ Rendered from Camera(s) in game
§ Represents final, published game
§ Camera numbers are dependant on the game to control what the
player actually sees when playing

84
§ Play Mode

§ Preview mode for game being created


§ Any changes made are temporary and will be reset when exiting
Play Mode
§ Editor UI darkens to remind you of this

85
§ Game View Control Bar

§ Free Aspect
§ Can force aspect ration to different values for use on different monitors
§ Maximize on Play
§ Maximizes Game View to a full-screen preview of the game

86
§ Game View Control Bar

§ Gizmos
§ Gizmos appearing in Scene View also appear in Game View
§ Stats
§ Shows rendering statistics

87
§ Time per Frame and FPS
§ Only includes frame update and rendering of game view and does
not include time taken in editor to draw the scene view, inspector
and other editor-only processing
§ Draw Calls
§ How many objects are drawn in total.
§ Accumulates objects drawn multiple times as well, for example
some object that is affected by pixel lights will add several draw
calls.

88
§ Batched (Draw Calls)
§ Number of draw calls batched together.
§ Engine combines rendering of multiple objects into one draw-call which
leads to lower CPU overhead
§ Ensure good batching by sharing as many materials between different
objects as possible

§ Tris and Verts

§ Used Textures
§ Count and memory size of textures used when drawing this frame

89
§ Render Textures
§ Count and memory size of Render Textures that are created. Also
displays how many times active Render Texture was switched
during this frame.
§ Screen
§ Size, anti-aliasing level and memory taken by the screen itself

§ VRAM
§ Approximate bounds of current video memory usage

90
§ VBO Total
§ Number of unique meshes (vertex buffers) uploaded to graphics
card
§ Each different model causes new VBOs to be created
§ Scaled objects may cause additional VBOs to be created
§ In case of a static batching however number of objects can share same
VBO

91
§ Visible Skinned Meshes
§ How many skinned meshes are rendered.

§ Animations
§ Number of animations playing

92
93

What are they?


How are they used?
§ What is a GameObject?

94
§ What is a GameObject?
§ Every object in scene is considered a GameObject
§ Base class for all entities in Unity scenes
§ Can be a considered a container to hold things such as things that
make up a character, a car, a level, a light, an island…etc
§ Making them into things requires the use and understanding of
Components and the different combinations to use them

95
§ Every GameObject will contain Components
§ Number of Components depend on what the GameObject can do in
a Scene
§ Most important and automatically added Component is the
Transform Component

96
§ All GameObjects properties are enabled by its use of this
Component
§ Defines its position, rotation and scale in the World (Scene)

§ Transform also enables the concept called Parenting, which is


utilized through the Unity Editor

97
§ Main Camera
§ Contains the following
Components
§ Camera Component
§ GUILayer (Legacy)
§ Flare Layer
§ Audio Listener
§ All provide additional
functionality to a
GameObject

98
§ These functional pieces of every GameObject allow for the
rendering of graphics, physics, collisions, audio…etc
§ Transform is added by default to any GameObject that is
created in a Scene, which includes Empty GameObjects

99
§ Select GameObject in the Scene
§ Choose ComponentàPhysicsàRigidbody from menu

100
§ Can also use Component Browser, which can be activated with
the Add Component button in the object’s inspector.

101
§ Can navigate components by category or use the search box to
locate components by name
§ Any number or combination of Components can be added to a
single GameObject and some Components work best in
combination with others
§ Example
§ Rigidbody works with any Collider
§ Rigidbody controls Transform through PhysX physics engine and the
Collider allows the Rigidbody to collide and interact with other
Colliders

§ Click ’?’ in Component’s header from the Inspector to learn


more about a Component
§ Can also visit Unity Manual or Unity Scripting Reference

102
§ One of the great aspects of Components is flexibility
§ Attaching a Component to a GameObject gives access to
values or Properties in the Component that can be adjusted in
the editor while building a game, or by scripts
§ Two main types of Properties: Values and References

103
§ The “gear” icon in the component’s panel in the inspector is
used to edit a Component

104
§ Reset
§ Restores component values before most recent editing session

§ Remove
§ Removes component that is no longer needed
§ Warning message may appear if removing a dependent component

§ Move Up/Down
§ Image Effects components each apply a specific visual effect to the
rendered view and order effects applied is important
§ Copy/Paste
§ Stores type and current property settings of a component
§ Can be pasted into another component of the same type with Paste
Component Values or create a new component with the copied values on
an object by using Paste Component As New

105
§ Properties can be changed on any GameObject’s Inspector
while in Play Mode
§ Values changed in Play Mode are temporary and will revert back
once Play Mode stops
§ Example:
§ Experimenting with different heights of jumping
§ Can create a Jump Height property in a script, you can enter Play
Mode, change the value, and press the jump button to see what
happens.
§ Change while still in Play Mode to see the new results
§ Exiting Play Mode, will revert properties to pre-Play Mode values

106
§ Mark GameObjects as inactive to temporarily remove from the
scene
§ Can be done using its SetActive() from a script or using the
activation checkbox through the inspector

107
§ When a parent object is deactivated, the deactivation also
overrides the activeSelf setting on all its child objects, so
the whole hierarchy from the parent down is made inactive
§ Note:
§ Does not change value of activeSelf property on child objects, so they
return to original state once parent is reactivated
§ Can’t determine whether or not a child object is currently active in the
scene by reading its activeSelf property
§ Instead, use activeInHierarchy, which takes the overriding effect of
the parent into account

§ Use the following code to change children’s activeSelf:

108
void DeactivateChildren(GameObject g, bool a)
{
g.activeSelf = a;

foreach (Transform child in g.transform)


{
DeactivateChildren(child.gameObject, a);
}
}

109
§ A Tag is a word which links to one or more GameObjects
§ Example:
§ Defining a “Player” and “Enemy” Tag for player-controlled
characters and non-player characters respectively
§ A “Collectable” Tag could be defined for items player can collect

§ Can be used to write script code to find a GameObject by


looking for any object that contains the desired Tag
§ Achieved using GameObject.FindWithTag()

§ Saves from having to manually add GameObjects to a script’s


exposed properties using drag and drop
§ Another example is a TriggerCollider control script which needs to
work out whether the player is interacting with an enemy, as
opposed to, say, a random prop or collectable item

110
§ Inspector will show the Tag and LayeràLayers drop-down
menus just below any GameObject’s name
§ Apply a Tag to a GameObject by opening the Tags drop-down and
choosing a Tag

111
§ Click “Add Tag…” to create a new Tag option at the end of the
drop-down menu, which opens Tag Manager in Inspector

§ Layers appear similar to Tags, but are used to define how Unity
should render GameObjects in the Scene
§ A GameObject can only have one Tag assigned to it

112
§ Many optimizations need to know if an object can move during
gameplay
§ Information about a Static (ie, non-moving) object can often be
precomputed in the editor in the knowledge that it will not be
invalidated by a change in the object’s position
§ Example: Rendering can be optimized by combining several static
objects into a single, large object known as a batch
§ The inspector for a GameObject has a Static checkbox and
menu in extreme top-right, which is used to inform various
different systems in Unity that the object will not move
§ Object can be marked as static for each of these systems
individually, so you can choose not to calculate static optimisations
for an object when it isn’t advantageous.

113
§ The Everything and Nothing enable or disable static status
simultaneously for all systems that make use of it
§ These systems are:
§ Lightmapping: advanced lighting for a scene
§ Occluder and Occludee: rendering optimization based on visibility
of objects from specific camera positions
§ Batching: rendering optimization that combines several objects into
one larger object
§ Navigation: the system that enables characters to negotiate
obstacles in the scene
§ Off-mesh Links: connections made by Navigation system between
discontinuous areas of the scene
§ Reflection Probe: captures a spherical view of its surroundings in all
directions

114
115

Creating Prefabs
Using Prefabs
Updating Prefabs
§ Acts as a template from where new object instances can be
created in the scene
§ Edits made to a prefab asset are reflected in all instances
§ Components and settings can also be overridden for each instance
or instances
§ Convenient to build GameObjects in scene by adding
components and setting properties to appropriate values
§ Simply copying the object will certainly produce duplicates but
will all be independently editable
§ This can create problems, however, when you have an object like an
NPC, prop or piece of scenery that is reused in the scene several
times

116
§ In order to create a Prefab, simply drag a GameObject that has
been created in the scene into the Project View
§ GameObject name will turn blue to show that it is a Prefab but
can be renamed if needed
§ After you have performed these steps, the GameObject and all
its children have been copied into the Prefab data
§ Prefab can now be re-used in multiple instances
§ The original GameObject in the Hierarchy has now become an
instance of the Prefab

117
§ To create a Prefab instance in scene, drag Prefab from Project
View into Scene or Hierarchy View
§ The linked instance to the Prefab is displayed by the blue text used
for the name in the Hierarchy View

- Three of these GameObjects are linked to Prefabs.


- One of them is not.

118
§ Means whenever source Prefab changes, those changes are
applied to all linked GameObjects
§ Example:
§ If you add a new script to a Prefab, all of the linked GameObjects will
instantly contain the script as well

§ Still possible to change properties of a single instance while


keeping link intact
§ Simply change any property of a prefab instance, and watch as the
variable name becomes bold
§ All overridden properties will not be affected by changes in the
source Prefab
§ Allows you to modify Prefab instances to make them unique from
source Prefabs without breaking the Prefab link

119
§ A linked GameObject with § Linked GameObject with
no overrides enabled (bold) overrides enabled

120
§ The inspector for a prefab instance has three buttons not
present for a normal object:
§ Select
§ Selects prefab asset from which instance was generated
§ Allows you to edit main prefab and thereby change all instances
§ Revert
§ Experiment with overriding properties and use Revert button to realign
instance with its prefab
§ Apply
§ Save overridden values from an instance back to originating prefab
using Apply button
§ Effectively lets you edit all instances via any single instance and is a very
quick and convenient way to make global changes

121
§ Come up with a Game Idea that will be used to create an FPS
game through out the course
§ The Idea should answer the following:
§ What is the general idea of the game?
§ What types of features will be part of the game?
§ What type of game world will be used?
§ What are the game characters?
§ What types of weapons will be used?
§ What type of audio will the game be using
§ What single and multiplayer game elements will be used?

§ Use provided GDD template as guideline to help pitch idea

122

Вам также может понравиться