Unity 2018 Cookbook - Third Edition

Book Description

Develop quality game components and solve common gameplay problems with various game design patterns

Key Features

  • Become proficient at traditional 2D and 3D game development
  • Build amazing interactive interfaces with Unity's UI system
  • Develop professional games with realistic animation and graphics, materials and cameras, and AI with Unity 2018

Book Description

With the help of the Unity 2018 Cookbook, you'll discover how to make the most of the UI system and understand how to animate both 2D and 3D characters and game scene objects using Unity's Mecanim animation toolsets.

Once you've got to grips with the basics, you will familiarize yourself with shaders and Shader Graphs, followed by understanding the animation features to enhance your skills in building fantastic games. In addition to this, you will discover AI and navigation techniques for nonplayer character control and later explore Unity 2018's newly added features to improve your 2D and 3D game development skills. This book provides many Unity C# gameplay scripting techniques.

By the end of this book, you'll have gained comprehensive knowledge in game development with Unity 2018.

What you will learn

  • Get creative with Unity's shaders and learn to build your own shaders with the new Shader Graph tool
  • Create a text and image character dialog with the free Fungus Unity plugin
  • Explore new features integrated into Unity 2018, including TextMesh Pro and ProBuilder
  • Master Unity audio, including ducking, reverbing, and matching pitch to animation speeds
  • Work with the new Cinemachine and timeline to intelligently control camera movements
  • Improve ambiance through the use of lights and effects, including reflection and light probes
  • Create stylish user interfaces with the UI system, including power bars and clock displays

Who this book is for

Unity 2018 Cookbook is for you if you want to explore a wide range of Unity scripting and multimedia features and find ready-to-use solutions for many game features. This book also helps programmers explore multimedia features. It is assumed that you already know basics of Unity and have some programming knowledge of C#.

Downloading the example code for this book You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Publisher Resources

Download Example Code

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Unity 2018 Cookbook Third Edition
  3. Dedication
  4. Packt Upsell
    1. Why subscribe?
    2. Packt.com
  5. Foreword
  6. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  7. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  8. Displaying Data with Core UI Elements
    1. Introduction
      1. The big picture
    2. Displaying a "Hello World" UI text message
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Styling substrings with Rich Text
    3. Displaying a digital clock
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. The Unity tutorial for animating an analog clock
    4. Displaying a digital countdown timer
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Creating a message that fades away
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Displaying a perspective 3D Text Mesh
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. We have to make this text crawl like it does in the movie
        2. Where to learn more
    7. Creating sophisticated text with TextMeshPro
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Rich Text substrings for colors, effects, and sprites
    8. Displaying an image
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Working with 2D Sprites and UI Image components
      5. See also
    9. Creating UIs with the Fungus open source dialog system
      1. How to do it...
      2. How it works...
    10. Creating a Fungus character dialog with images
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Data-driven conversations
  9. Responding to User Events for Interactive UIs
    1. Introduction
      1. The big picture
    2. Creating UI Buttons to move between scenes
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Color tint when mouse pointer is over the button
    3. Animating button properties on mouse-over
      1. How to do it...
      2. How it works...
    4. Organizing image panels and changing panel depths via buttons
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Moving up or down by just one position, using scripted methods
    5. Displaying the value of an interactive UI Slider
      1. How to do it...
      2. How it works...
    6. Displaying a countdown timer graphically with a UI Slider
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Setting custom mouse cursors for 2D and 3D GameObjects
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Setting custom mouse cursors for UI controls
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Interactive text entry with an Input Field
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Limiting the type of content that can be typed
    10. Toggles and radio buttons via Toggle Groups
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Adding more Toggles and a Toggle Group to implement mutually-exclusive radio buttons
    11. Creating text and image icon UI Dropdown menus
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Adding images to a Dropdown control
    12. Displaying a radar to indicate the relative locations of objects
      1. Getting ready
      2. How to do it...
      3. How it works...
        1. The Start() method
        2. The Update() method
        3. The FindAndDisplayBlipsForTag(...) method
        4. The CalculateBlipPositionAndDrawBlip (...) method
        5. The NormalisedPosition(...) method
        6. The CalculateBlipPosition(...) method
        7. The DrawBlip() method
      4. There's more...
        1. Adapt for object heights and opaque obstacles
  10. Inventory UIs
    1. Introduction
      1. The big picture
    2. Creating a simple 2D mini-game – SpaceGirl
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Displaying single object pickups with carrying and not-carrying text
      1. Getting ready
      2. How to do it...
      3. How it works...
        1. The PlayerInventory script class
        2. The PlayerInventoryDisplay script class
      4. There's more...
        1. Collecting multiple items and display total number carried
        2. Alternative – combining all the responsibilities into a single script
    4. Displaying single object pickups with carrying and not-carrying icons
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Displaying multiple pickups of the same object with multiple status icons
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Revealing icons for multiple object pickups by changing the size of a tiled image
    6. Using panels to visually outline the inventory UI area and individual items
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Creating a C# inventory slot UI display scripted component
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Modifying the game for a second inventory panel for keys
    8. Using UI Grid Layout Groups to automatically populate a panel
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Automatically infer number of inventory slots based on number of GameObjects tagged Star
        2. Add a horizontal scrollbar to the inventory slot display
        3. Automatically changing the grid cell size based on the number of slots in the inventory
    9. Displaying multiple pickups of different objects as a list of text via a dynamic List<> of scripted PickUp objects
      1. Getting ready
      2. How to do it...
      3. How it works...k
      4. There's more...
        1. Order items in the inventory list alphabetically
    10. Displaying multiple pickups of different objects as text totals via a dynamic Dictionary<> of PickUp objects and enum pickup types
      1. Getting ready
      2. How to do it...
      3. How it works...
  11. Playing and Manipulating Sounds
    1. Introduction
      1. The big picture
        1. Future audio features
    2. Playing different one-off sound effects with a single AudioSource component
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Play a sound at a static point in 3D world space
    3. Playing and controlling different sounds each with their own AudioSource component
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Creating just-in-time AudioSource components at runtime through C# scripting
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Adding the CreateAudioSource(...) method as an extension to the MonoBehavior class
    5. Delaying before playing a sound
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Preventing an Audio Clip from restarting if it is already playing
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    7. Waiting for the audio to finish playing before auto-destructing an object
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    8. Creating a metronome through the precise scheduling of sounds with dspTime
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Creating just-in-time AudioSource GameObjects for the basic and accented beats
        2. Creating beat sounds through data rather than AudioClips
    9. Matching the audio pitch to the animation speed
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Changing the Animation/Sound Ratio
        2. Accessing the function from other scripts
        3. Allowing reverse animation (negative speeds!)
    10. Simulating acoustic environments with Reverb Zones
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Attaching the Audio Reverb Zone component to Audio Sources
        2. Making your own Reverb settings
    11. Adding volume control with Audio Mixers
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Playing with Audio Production
      5. See also
    12. Making a dynamic soundtrack with Snapshots
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Reducing the need for multiple audio clips
        2. Dealing with audio file formats and compression rates
        3. Applying Snapshots to background noise
        4. Getting creative with effects
      5. See also
    13. Balancing in-game audio with Ducking
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    14. Audio visualization from sample spectral data
      1. Getting ready
      2. How to do it...
      3. How it works...
        1. The void Awake() method
        2. The void CreateCubes() method
        3. The void Update() method
        4. The void UpdateCubeHeights() method
        5. The float HeightFromSample(float) method
      4. There's more...
        1. Adding visualizations to a second AudioSource
        2. Try out different FFT (Fast Fourier Transform) window types
    15. Synchronizing simultaneous and sequential music to create a simple 140 bpm music-loop manager
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Adding visualizations to the four playing loops
  12. Creating Textures, Maps, and Materials
    1. Introduction
      1. Creating and saving texture maps
      2. The big picture
        1. Standard Shader (Specular workflow)
        2. Standard Shader (Metallic workflow)
        3. Other material properties
        4. Resources
          1. Unity samples and documentation
          2. References
          3. Tools
        5. Additional reading
    2. Creating a basic material with Standard Shader (Specular setup)
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Setting the texture type for an image file
        2. Combining the map with color
    3. Adapting a basic material from Specular setup to Metallic
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Applying Normal maps to a Material
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Adding Transparency and Emission maps to a material
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Using texture maps with the Transparent Mode
        2. Avoiding issues with the semi-transparent objects
        3. Emitting light over other objects
    6. Highlighting materials at mouse-over
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Collider needed for custom meshes
        2. Mouse Down/Up events – for clicking color
    7. Adding Detail maps to a material
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Fading the transparency of a material
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Start with keypress and fade in from invisible
        2. Destroy object when fading complete
        3. Using GameObect's alpha as our starting alpha value
        4. Using a coroutine for our fading loop
  13. Shader Graphs and Video Players
    1. Introduction
      1. The big picture
        1. The new Shader Graph tool
        2. Playing videos with the new Video Player
        3. Online references materials
          1. Shader Graph online resources
          2. Video Player online resources
    2. Playing videos by manually adding a VideoPlayer component to a GameObject
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Semi-transparent video and Camera Near Plane
        2. Audio issues and AudioSource solution
    3. Using scripting to control video playback on scene textures
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Ensuring that a movie's prepared before playing it with the prepareCompleted event
        2. Outputting video playback to a Render Texture asset
        3. Ensuring that the movie is prepared before playing with coroutines
        4. Downloading an online video (rather than a clip)
    4. Using scripting to play a sequence of videos back-to-back
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Creating and using a simple Shader Graph
      1. How to do it...
      2. How it works...
    6. Creating a glow effect with Shader Graph
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Toggling a Shader Graph color glow effect through C# code
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Using Sine Time to create a pulsating glow effect
        2. Using the Compile and Show Code button as another way to find exposed property IDs
  14. Using Cameras
    1. Introduction
      1. The big picture
        1. Cinemachine
    2. Creating the basic scene for this chapter
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Creating a picture-in-picture effect
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Changing the size and location of the picture-in-picture viewport on the screen
        2. Adding further contols for depth-of-field and aspect-ratio
        3. Manually changing Camera viewport properties in the Inspector
      5. See also
    4. Switching between multiple cameras
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Using a single-enabled camera
      5. See also
    5. Making textures from screen content
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Applying your texture to a material
        2. Using your texture as a screenshot
      5. See also
    6. Zooming a telescopic camera
      1. Getting ready...
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Adding a vignette effect when you zoom
        2. Going further with version 2 of the Unity Post Processing Stack
    7. Displaying a minimap
      1. Getting ready...
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Using a UI Mask to make the minimap circular in shape
        2. Hiding player character image at center of minimap and showing triangle marker
        3. Rotating a compass-style image
        4. Making the range of the map larger or smaller
        5. Adapting your minimap to other styles
    8. Creating an in-game surveillance Camera
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Using Post-Processing to add a grainy, grayscale effect to the CCTV
    9. Working with Unity's multi-purpose camera rig
      1. How to do it...
      2. How it works...
    10. Using Cinemachine ClearShot to switch cameras to keep the player in shot
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Unity Cinemachine tutorials
        2. Will Goldstone's ClearShot turtorial
        3. Adam Myhill's Cinemachine blog posts
        4. Read the installed Cinemachine documentation
    11. Letting the player switch to a Cinemachine FreeLook camera
      1. Getting ready
      2. How to do it...
      3. How it works...
  15. Lights and Effects
    1. Introduction
      1. The big picture
        1. Lights
          1. Environment lighting
          2. Emissive materials
          3. Projector
          4. Lightmaps
          5. Light probes
          6. The Lighting settings window
        2. The Light Explorer panel
        3. Cucoloris cookies
        4. Color space (Gamma and Linear)
        5. Further resources
    2. Directional Light with cookie Texture to simulate a cloudy day
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Creating and applying a cookie texture to a spotlight
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Adding a custom Reflection map to a scene
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Mapping coordinates
        2. Sharp reflections
        3. Maximum size
    5. Creating a laser aim with a projector
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Limiting the range of the laser with Raycast hit to limit the far clip plane
        2. Further reading
    6. Enhancing the laser aim with a Line Renderer
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Changing the beam color when the Fire key is held down
    7. Setting up an environment with Procedural Skybox and Directional Light
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Setting and rising the sun through scripted rotation of Directional Light
        2. Adding a sun flare
    8. Reflecting surrounding objects with Reflection Probes
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    9. Using Material Emission to bake light from a glowing lamp onto scene objects
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Lighting a simple scene with Lightmaps and Light Probes
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  16. 2D Animation
    1. Introduction
      1. The Big picture
        1. Grids, Tilemaps, and Tile Palettes
        2. The 2D GameKit – bringing 2D tools together
        3. Resources
    2. Flipping a sprite horizontally – the DIY approach
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Flipping a sprite horizontally – using Animator State Chart and Transitions
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Instantaneous swapping
    4. Animating body parts for character movement events
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Creating a three-frame animation clip to make a platform continually animate
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Copy animation relative to a new parent GameObject
    6. Making a platform start falling once stepped on using a Trigger to move animation from one state to another
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Creating animation clips from sprite sheet sequences
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Creating a platform game with Tiles and Tilemaps
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Tile Palettes for objects and walls
        2. Rule Tiles for intelligent Tile selection
        3. Learning more
    9. Creating a game with the 2D Gamekit
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  17. 3D Animation
    1. Introduction
      1. The big picture
    2. Configuring a character's Avatar and idle animation
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Use Controller with another 3D character Avatar
      5. See also
    3. Moving your character with root motion and Blend Trees
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Mixing animations with Layers and Masks
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Override versus Additive blending
    5. Organizing States into Sub-state Machines
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Transforming the Character Controller via scripts
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Adding rigid props to animated characters
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Removing props with a script
        2. Setting Active if there's only one type of Prop
    8. Using Animation Events to throw an object
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Applying Ragdoll physics to a character
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Using a new player GameObject rather than deactivating and moving to a respawn point
    10. Rotating the character's torso to aim a weapon
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Generic solution for Cameras other than the Main Camera
    11. Creating geometry with Probuilder
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. Creating a game with the 3D Gamekit
      1. Getting ready
      2. How to do it...
      3. How it works...
    13. Importing third-party 3D models and animations from Mixamo
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Looping the animation
        2. Scripting events to control when Animation Clips are played
        3. Information sources about importing models and animations into Unity
  18. Webserver Communication and Online Version-Control
    1. Introduction
      1. The Big Picture
    2. Setting up a leaderboard using PHP and a database
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. SQLite, PHP, and database servers
        2. PHPLiteAdmin
    3. Unity game communication with web-server leaderboard
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Extracting the full leaderboard data for display within Unity
        2. Using the secret game codes to secure your leaderboard scripts
    4. Creating and cloning a GitHub repository
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Learn more about DVCS
        2. Learn more about Git at the command line
        3. Using Bitbucket and SourceTree visual applications
        4. Learning about Mercurial rather than Git
    5. Adding a Unity project to a local Git repository, and pushing files up to GitHub
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Unity project version-control using GitHub for Unity
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Further reading about GitHub for Unity
        2. Pulling down updates from other developers
        3. Unity Collaborate from Unity Technologies
    7. Preventing your game from running on unknown servers
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Enabling WebGL in Google Chrome
        2. Improving security by using full URLs in your domain list
  19. Controlling and Choosing Positions
    1. Introduction
      1. The big picture
    2. Player control of a 2D GameObject (and limiting the movement within a rectangle)
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Drawing a gizmo yellow rectangle to visually show bounding a rectangle
      5. See also
    3. Player control of a 3D GameObject (and limiting the movement within a rectangle)
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Drawing a gizmo yellow rectangle to visually show bounding a rectangle
    4. Choosing destinations – finding a random spawn point
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Choosing destinations – finding the nearest spawn point
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Avoiding errors due to an empty array
      5. See also
    6. Choosing destinations – respawning to the most recently passed checkpoint
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Moving objects by clicking on them
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Firing projectiles in the direction of movement
      1. Getting ready
      2. How to do it...
      3. How it works...
  20. Navigation Meshes and Agents
    1. Introduction
      1. The big picture
        1. Run-Time Nav Mesh Obstacles
        2. Source of further information about Unity and AI navigation
    2. NPC to travel to destination while avoiding obstacles
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. NPC to seek or flee from a moving object
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more
        1. Using a Debug Ray to show a source-to-destination line
        2. Constantly updating NavMeshAgent destination to flee from Player's current location
        3. Maintain constant distance from target ("lurking" mode!)
    4. Point-and-click move to object
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more
        1. Creating a mouse-over yellow highlight
    5. Point-and-click move to tile
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more
        1. Yellow debug-ray to show destination of AI-agent
    6. Point-and-click Raycast with user-defined higher-cost Navigation Areas
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more
        1. More intelligent pathfinding by setting different costs for custom-defined navigation areas such as Mud and Water
        2. Improving UX by updating a "gaze" cursor each frame
    7. NPC NavMeshAgent to follow waypoints in a sequence
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Working with arrays of waypoints
        2. Increased flexibility with a WayPoint class
    8. Controlling object group movement through flocking
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Creating a movable NavMesh Obstacle
      1. Getting ready
      2. How to do it...
      3. How it works...
  21. Design Patterns
    1. Introduction
      1. The big picture
    2. State-driven behavior DIY states
      1. How to do it...
      2. How it works...
      3. See also
    3. State-driven behavior using the State Design Pattern
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Adding the Timer event to lose the game after five seconds
      5. See also
    4. State-driven behavior with Unity Scriptable Objects
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Extending the game to model Player health
      4. See also
    5. Publisher-Subscriber pattern C# delegates and events
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Model-View-Controller (MVC) pattern
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  22. Editor Extensions and Immediate Mode GUI (IMGUI)
    1. Introduction
      1. The Big picture
        1. Unity Immediate Mode GUI (IMGUI)
        2. Identifying and saving changes
        3. Memory - EditorPrefs persistent storage
        4. Conclusions and further resources
    2. Menu items to log messages and clear the console
      1. How to do it...
      2. How it works...
      3. There's more
        1. Keyboard shortcuts
        2. Sub-menus
    3. Displaying a panel with text data
      1. How to do it...
      2. How it works...
      3. There's more
        1. Vertical centering
        2. Vertical and horizontal centering (middle of an area)
    4. An interactive panel with persistent storage
      1. How to do it...
      2. How it works...
      3. There's more
        1. Persistent storage with EditorPrefs
        2. GUILayout versus EditorGUILayout
    5. Creating GameObjects, parenting, and registering Undo actions
      1. How to do it...
      2. How it works...
      3. There's more
        1. Registering object changes to allow Undo'ing of actions
        2. Creating primitive 3D GameObjects with random colors
    6. Working with selected objects and deactivating menu items
      1. How to do it...
      2. How it works...
    7. Menu item to create 100 randomly positioned prefab clones
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Childing each new GameObject to a single parent, to avoid filling up the Hierarchy with 100s of new objects
    8. A progress bar to display proportion completed of Editor extension processing
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. An editor extension to allow pickup type (and parameters) to be changed at design time via a custom Inspector UI
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Offer the custom editing of pickup parameters via Inspector
        2. Offer a drop-down list of tags for key-pickup to fit via Inspector
        3. Logic to open doors with keys based on fitsLockTag
        4. The need to add [SerializeField] for private properties
    10. An editor extension to have an object-creator GameObject, with buttons to instantiate different pickups at cross-hair object location in scene
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. Extensible class-based code architecture to manage complex IMGUIs
      1. How to do it...
      2. How it works...
        1. Script-class MyEditorWindow
        2. Script-class IMyGUI
        3. Script-class MyGUIFlexibleSpace
        4. Script-class MyGUITextField
        5. Script-class MyGUILabel
        6. Script-class MyGUIButton
  23. Working with External Resource Files and Devices
    1. Introduction
      1. The big picture
    2. Loading external resource files – using Unity Default Resources
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Loading text files with this method
        2. Loading and playing audio files with this method
      5. See also
    3. Loading external resource files by downloading files from the internet
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Converting from Texture to Sprite
        2. Downloading a text file from the web
        3. The WWW class and the resource content
        4. An example using UnityWebRequest
      5. See also
    4. Loading external resource files by manually storing files in the Unity 
Resources or StreamingAssets folders
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Avoiding cross-platform problems with Path.Combine() rather than / or \
        2. SteamingAssets folder
      5. See also
    5. Saving Project files into Unity Asset Bundles
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Loading resources from Unity Asset Bundles
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Loading AssetBundles via AssetBundle.LoadFromFile()
        2. Loading AssetBundles hosted via a web server
  24. Working with Plain Text, XML, and JSON Text Files
    1. Introduction
      1. The Big picture
        1. XML – the eXtensible markup language
        2. JSON – the JavaScript object notation
    2. Loading external text files using the TextAsset public variable
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Loading external text files using C# file streams
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Saving external text files with C# file streams
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Choosing the Data or the Resources folder
    5. Loading and parsing external XML
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Retrieving XML data files from the web
    6. Creating XML text data manually using XMLWriter
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Adding new lines to make XML strings more human readable.
        2. Making data class responsible for creating XML from list
    7. Saving and loading XML text data automatically through serialization
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Defining the XML node names
        2. Loading data objects from XML text
    8. Creating XML text files – saving XML directly to text files with XMLDocument.Save()
      1. How to do it...
      2. How it works...
    9. Creating JSON strings from individual objects and lists of objects
      1. How to do it...
      2. How it works...
    10. Creating individual objects and Lists of objects from JSON strings
      1. How to do it...
      2. How it works...
  25. Virtual Reality and Extra Features
    1. Introduction
      1. The Big picture
        1. Virtual reality
        2. Gizmos
        3. Saving/Loading data at runtime
    2. Saving screenshots from the game
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Saving and loading player data – using static properties
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Hiding the score before the first attempt is completed
      5. See also
    4. Saving and loading player data – using PlayerPrefs
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Loading game data from a text file map
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. UI Slider to change game quality settings
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Seeing/editing the list of quality settings
    7. Pausing the game
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Learning more about quality settings
        2. Offering the user further game settings
    8. Implementing slow motion
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Customizing the slider
        2. Adding Motion Blur
        3. Creating sonic ambience
    9. Using Gizmo to show the currently selected object in a scene panel
      1. How to do it...
      2. How it works...
    10. Editor snap-to grid drawn by Gizmo
      1. How to do it...
      2. How it works...
    11. Creating a VR project
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Exploring free VR/XR samples/tutorials
        2. Setup with Oculus Rift
        3. Using a Single Pass if working with the Lightweight Rendering Pipeline
    12. Adding 360-degree videos to a VR project
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Playing 360-degree videos on the surface of a 3D object
    13. Working with VR content inside a VR environment – the XR Editor
      1. Getting ready
      2. How to do it ...
      3. How it works...
  26. Automated Testing
    1. Introduction
      1. The big picture
        1. Unit tests
        2. Integration tests (PlayMode tests in Unity)
    2. Generating a default test script class
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Create a default test script from the Project panel's Create menu
        2. Edit mode minimum skeleton unit test script
    3. A simple unit test
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Shorter tests with values in the assertion
        2. Expected value followed by the actual value
    4. Parameterizing tests with a data provider method
      1. How to do it...
      2. How it works...
    5. Unit testing a simple health script class
      1. How to do it...
      2. How it works...
        1. Script-class Health.cs
        2. Script-class TestHealth.cs
    6. Creating and executing a unit test in Play mode
      1. How to do it...
      2. How it works...
    7. PlayMode testing a door animation
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. PlayMode and Unit Testing a player health bar with events, logging, and exceptions
      1. Getting ready
      2. How to do it...
      3. How it works...
        1. PlayMode testing
        2. Unit tests
      4. See also
  27. Bonus Chapters
    1. Working with External Resource Files and Devices
    2. Working with Plain Text, XML, and JSON Text Files
    3. Virtual Reality and Extra Features
    4. Automated Testing
  28. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product Information

  • Title: Unity 2018 Cookbook - Third Edition
  • Author(s): Matt Smith
  • Release date: August 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781788471909