• Название:

    Creating E Learning Games with Unity David Hor


  • Размер: 13.15 Мб
  • Формат: PDF
  • или
  • Сообщить о нарушении / Abuse

Установите безопасный браузер



    Предпросмотр документа

    Creating E-Learning Games
    with Unity

    Develop your own 3D e-learning game using
    gamification, systems design, and gameplay
    programming techniques

    David Horachek

    BIRMINGHAM - MUMBAI

    Creating E-Learning Games with Unity
    Copyright © 2014 Packt Publishing

    All rights reserved. No part of this book may be reproduced, stored in a retrieval
    system, or transmitted in any form or by any means, without the prior written
    permission of the publisher, except in the case of brief quotations embedded in
    critical articles or reviews.
    Every effort has been made in the preparation of this book to ensure the accuracy
    of the information presented. However, the information contained in this book is
    sold without warranty, either express or implied. Neither the author, nor Packt
    Publishing, and its dealers and distributors will be held liable for any damages
    caused or alleged to be caused directly or indirectly by this book.
    Packt Publishing has endeavored to provide trademark information about all of the
    companies and products mentioned in this book by the appropriate use of capitals.
    However, Packt Publishing cannot guarantee the accuracy of this information.

    First published: March 2014

    Production Reference: 1180314

    Published by Packt Publishing Ltd.
    Livery Place
    35 Livery Street
    Birmingham B3 2PB, UK.
    ISBN 978-1-84969-342-4
    www.packtpub.com

    Cover Image by Parag Kadam (paragvkadam@gmail.com)

    Credits
    Author
    David Horachek
    Reviewers
    Neeraj Jadhav

    Project Coordinator
    Binny K. Babu
    Proofreader
    Simran Bhogal

    Alankar Pradhan
    K. Aava Rani
    Ranpariya Ankur J. [PAHeartBeat]
    Acquisition Editor
    Joanne Fitzpatrick
    Content Development Editor

    Indexer
    Hemangini Bari
    Graphics
    Ronak Dhruv
    Yuvraj Mannari
    Abhinash Sahu

    Chalini Snega Victor
    Production Coordinator
    Technical Editors

    Shantanu Zagade

    Arwa Manasawala
    Manal Pednekar
    Anand Singh
    Ankita Thakur
    Copy Editors
    Sarang Chari
    Brandt D'Mello
    Mradula Hegde

    Cover Work
    Shantanu Zagade

    About the Author
    David Horachek is a video game software developer with over 13 years of

    experience in programming arcade, home console, and portable games. He has
    programmed game projects published by Midway Games, EA, Ubisoft, SEGA,
    and others. He develops games under the Arbelos Interactive label.
    I would like to thank my wife Allison and my family for their
    encouragement and support, the team at Packt Publishing for their
    patience and advice, and aspiring e-learning game programmers for
    their work to come.

    About the Reviewers
    Neeraj Jadhav did his Bachelors in Computer Engineering from Mumbai University

    and Masters in Computer Science from University of Houston-Clear Lake. He has been
    working as a software developer for three years. His interests primarily lie in software
    development with Java and C# as well as web development with HTML 5, CSS 3,
    jQuery, and JavaScript. During his graduate years, he worked on developing games
    using Unity's 3D game engine with JavaScript and C#.

    Alankar Pradhan is from Mumbai, Maharashtra, and went to Indian Education

    Society's CPV High School. He is an ambitious person who loves interacting with new
    people, travelling, spending leisure time with friends, or playing games on both his
    PC and mobile. Games have been always a passion in his life. More than just playing
    the game, his main curiosity is how things work. Hence, he decided to pursue his
    career in the same field. He graduated with BSc Honors in Software Development
    from Sheffield Hallam University, UK. He is currently pursuing an advanced course
    in game programming (BAC+5 Equivalent) from DSK Supinfogame, where he is
    undertaking industry-oriented projects to enhance his skill set and giving his best in
    doing so. He worked as a game programming intern at The Walt Disney Company
    India Pvt Ltd. During his internship, he worked on a live project, called Hitout Heroes,
    where he was responsible for integration of small gameplay modules and then social
    integration of Facebook into the game, but later on, the whole UI implementation,
    working, flow, and mechanism was managed solely by him. At the end, he was
    responsible for bug solving and memory management. His name was added in
    the credits due to his accomplishments.
    He has worked in many small projects in team as well as individually, thus
    sharpening his own skills in various languages, such as C#, C++, Java, Unreal
    Script, Python, Lua, Groovy/Grails, and HTML5/CSS. He is familiar with engines
    such as Unity3D, Unreal Development Kit, and Visual Studio and also SDKs such as
    NetBeans, Eclipse, and Wintermute. Recently, in 2013, his dissertation on Comparison
    between Python and Lua in Gaming Industry got published as a book.

    More to this, he even likes to read, listen to music, and write poems and rap songs
    at times. He has his own website at http://alan.poetrycraze.com where he posts
    his poems and has also published a book called The Art Of Lost Words, which is
    available on Amazon.com.
    We are so often caught up with our goals that we forget to appreciate
    the journey, especially the people we meet on the way. Appreciation
    is a wonderful feeling; it's way better if we don't overlook it. I hereby
    take this opportunity to acknowledge the people who directed me
    and inspired me in this initiative. I would like to express hearty
    thanks to my parents, who instilled and believed in me always.
    I am also thankful to my friends for their constant support and
    encouraging words that helped me to reach this level. Last but
    not least, I would like to thank all the people who are directly or
    indirectly involved in this and helped me in one or the other way.

    K. Aava Rani is a co-founder of CulpzLab Pvt Ltd., a software company having

    10 years of experience in game technologies. A successful blogger and technologist,
    she switched her focus to game development in 2004. Since then, she has produced
    a number of game titles and has provided art and programming solutions to Unity
    developers across the globe. She is based in New Delhi, India. She has been a
    recipient of several prestigious awards including Adobe for game technology expert
    2012 and SmartFoxServer for her articles. She has experience in various technologies.
    Aava is the co-founder of CulpzLab, a software development company of highly
    skilled professionals in web, game development, and interactive media. Founded
    in 2010, CulpzLab has proven itself to be a reliable technology partner for its clients.
    Currently, CulpzLab employs over 50 people and is based in New Delhi, India.
    CulpzLab is a leading, custom (bespoke) process-driven software solutions provider
    that has helped and partnered with many reputable brands, start-up ventures, and
    offshore IT companies, helping them realize their digital solutions and delivering
    effectively, efficiently, and on time.

    CulpzLab has worked with a plethora of clients globally. With a diverse technology
    background, industry expertise, and a client footprint that extends to more than 14
    countries, CulpzLab is well positioned to help organizations derive maximum value
    from their IT investments and fully support their business aims.
    CulpzLab's core business purpose is to invent, engineer, and deliver technology
    solutions that drive business value, create social value, and improve the lives
    of customers.
    I would like to acknowledge the creators of Unity3D program, the
    amazing tool that allows the ultimate digital experience in creative
    expression. I'd also like to thank my clients for being part of the fun!
    Many of you have become good friends over my creative successes.
    And finally, I'd like to thank R.K.Rajanjan, who taught me how to
    love and appreciate technologies.

    Ranpariya Ankur J. [PAHeartBeat] represents himself in the gaming world

    as PAHeartBeat. He has vast experience in the computer programming field from
    FoxPro to Microsoft .NET technologies. In game programming, he works with one
    of India's successful game studios, GameAnax Inc., by IndiaNIC InfoTech Ltd.,
    as a Unity3D game programmer, and also works on racing titles for mobile
    device-based games and studio's internal reusable code "GameAnax Engine",
    which works in Unity3D for the iOS and Android platforms. He has worked on the
    two most successful in-house games, Crazy Monster Truck – Escape and Go Karts, and
    has also worked on client projects.
    Before this, he hasn't worked for any other books either as a reviewer or as a
    co-author; it's his first experience in book reviewing.
    I would to like to thank my family and my roommates who give me
    space to work for games at night and adjust their routines and time
    according to my schedule, thus providing their help.

    www.PacktPub.com
    Support files, eBooks, discount offers and more

    You might want to visit www.PacktPub.com for support files and downloads related
    to your book.
    Did you know that Packt offers eBook versions of every book published, with PDF
    and ePub files available? You can upgrade to the eBook version at www.PacktPub.
    com and as a print book customer, you are entitled to a discount on the eBook copy.
    Get in touch with us at service@packtpub.com for more details.
    At www.PacktPub.com, you can also read a collection of free technical articles, sign
    up for a range of free newsletters and receive exclusive discounts and offers on Packt
    books and eBooks.
    TM

    http://PacktLib.PacktPub.com

    Do you need instant solutions to your IT questions? PacktLib is Packt's online digital
    book library. Here, you can access, read and search across Packt's entire library
    of books.

    Why Subscribe?

    • Fully searchable across every book published by Packt
    • Copy and paste, print and bookmark content
    • On demand and accessible via web browser

    Free Access for Packt account holders

    If you have an account with Packt at www.PacktPub.com, you can use this to access
    PacktLib today and view nine entirely free books. Simply use your login credentials
    for immediate access.

    Table of Contents
    Preface 1
    Chapter 1: Introduction to E-Learning and the
    Three Cs of 3D Games
    7
    Understanding e-learning
    Introducing our game – Geography Quest
    Comprehending the three Cs
    Creating our first scene
    Developing the character system
    Building character representation
    Developing the camera code
    Implementing GameCam.cs
    Developing the player controls code
    Implementing PlayerControls.cs
    Try it out!
    Summary

    Chapter 2: Interactive Objects and MissionMgr
    Understanding the base scripts
    Building an interactive object
    Implementing the CustomGameObj script
    Implementing the InteractiveObj script
    Implementing the ObjectInteraction script
    Implementing the InventoryItem script
    Implementing the InventoryMgr script
    Implementing the DisplayInventory method

    Implementing the MissionMgr script
    Implementing the Mission script
    Implementing the MissionToken script
    Implementing the SimpleLifespanScript

    8
    10
    11
    12
    13
    14
    15
    16
    21
    21
    26
    26

    27
    28
    29
    30
    31
    33
    34
    36

    40

    44
    46
    48
    48

    Table of Contents

    Putting it all together
    Testing the mission system
    Try it out!
    Summary

    Chapter 3: Mission One – Find the Facts

    Finding the facts
    Designing games to maximize fun
    The teaching loop in game design
    Implementing the core classes for mission one
    Creating a terrain
    Creating the FlagLocators GameObject
    Creating the FlagMonument GameObject
    Creating the MonumentMgr Script

    49
    52
    54
    54

    55
    55
    57
    58
    58
    58
    61
    61

    61

    Creating the InventoryPlaceOnMonument class
    63
    Creating the MissionMgrHelper script
    63
    Creating the TriviaCardScript script
    64
    Creating the SetupMissionOne script
    65
    Creating the flag Prefabs
    67
    Creating the pop-up card Prefabs
    70
    Creating the mission pop-up Prefab
    71
    Creating the mission reward Prefabs
    72
    Creating the FoundAllTheFlags Prefab
    72
    Creating the ReturnedTheFlagsResult Prefab
    73
    Configuring the mission manager
    74
    Playing the level!
    75
    Summary 75

    Chapter 4: Mission One – Future Proofing the Code
    Reorganizing our GameObjects in the Scene view
    Creating a global scene
    Creating a first level scene
    Adding new scenes to the project
    Creating the PopupMainMenu GameObject
    An introduction to Finite State Machines
    Implementing an FSM in a game
    The switch case FSM
    Classes implementation of FSM
    Implementing the GameMgr script
    Reflecting on our code changes
    Analyzing code functionality
    Updating some systems
    [ ii ]

    77
    78
    79
    80
    81
    82
    84
    85
    85
    86
    86
    89
    90
    91

    Table of Contents

    Making the ScorePlate active
    Updating the player motion algorithm
    Playing the level!
    Summary

    Chapter 5: User Interfaces in Unity

    Getting familiar with Unity UI classes
    Developing the pop-up system
    Exploring the GUIText component
    Interpreting the members on GUIText
    Exploring the GUITexture component
    Exploring the TextMesh component
    Ideal use of TextMesh
    Creating clickable text elements
    Detecting mouse clicks
    Detecting mouse over
    Detecting leaving mouse over
    Exploring UnityScript and the GUIButton object
    Using UnityGUI
    Creating a clickable button
    Detecting a mouse click
    Building the main menu pop up
    Testing our work
    Future extensions
    Summary

    Chapter 6: NPCs and Associated Technology

    92
    94
    95
    95

    97

    98
    98
    99
    99
    100
    101
    102
    102
    102
    102
    102
    103
    103
    103
    104
    104
    113
    114
    114

    115

    Creating the NPC GameObject
    116
    Implementing the npcScript class
    116
    Implementing the SplineMgr class
    119
    Connecting SplineMgr to NPCScript
    124
    Implementing the NPC decision system
    127
    Implementing the npcCondition script
    128
    Implementing the npcResponse script
    129
    Implementing the npcInteraction script
    129
    Implementing the npcDecisionMgr script
    131
    Building a collection of NPC conditions and responses
    132
    Implementing the condition_closerThanThresh script
    132
    Implementing the condition_fartherThanThresh script
    133
    Implementing the response_changeState script
    134
    Putting it all together
    135
    Summary 137
    [ iii ]

    Table of Contents

    Chapter 7: Mission Two – Testing a Player's Learning

    139

    Chapter 8: Adding Animations

    161

    Chapter 9: Synthesis of Knowledge

    181

    Exploring the structure of mission two
    Defining the framework for mission two
    Adding a mission to the missionMgr script
    Extending the GameCam script
    Modifying the terrain
    Adding NpcRacers to the mission
    Creating the start and finish line flags
    Creating the LevelStart and LevelFinished pop ups
    Creating the setupLevel2 Prefab
    Creating the raceStartup Prefab
    Implementing the LevelLogicObj GameObject
    Summary
    Exploring 3D hierarchies
    Skinned meshes in Unity3D
    Acquiring and importing models
    Exploring the Mechanim animation system
    Choosing appropriate animations
    Building a simple character animation FSM
    Exploring in-place versus root motion animation
    Adding the character script
    Building a zombie racer animation FSM
    Building a quiz racer animation FSM
    Exploring the Unity animation editor
    Summary
    Understanding the mission three GameObjects
    Applying learning theory to mission three
    Creating the structure for mission three
    Modifying the terrain
    Adding visitors to the park
    Modifying the pop-up system
    Creating the NpcLocators Prefab
    Creating the CorrectResponse Prefabs
    Modifying the quiz cards
    Adding another data condition
    Using the setupLevel3 Prefab
    Creating the AddScore condition
    Creating the ShowLevel3Results response
    [ iv ]

    140
    140
    142
    142
    143
    143
    145
    147
    149
    150
    152
    159

    161
    162
    162
    165
    166
    166
    170
    171
    172
    174
    177
    179
    182
    183
    184
    184
    185
    185
    186
    187
    187
    189
    189
    191
    192

    Table of Contents

    Creating the Time object
    Modifying the LevelLogicObj object
    Rewarding the player
    Summary

    Chapter 10: An Extensible Game Framework Pattern in Unity
    Load additively
    Using delete/load patterns
    Refactoring our work
    The pop-up system
    Updating level 3 pop ups
    Updating level 2 pop ups
    Updating level 1 pop ups

    Refactoring level 2
    Implementing a system to connect object references
    Updating the SetupMission2 script
    Refactoring level 3
    Playing and distributing your game
    Reflecting on e-learning and game design
    Summary

    Index

    [v]

    193
    196
    197
    199

    201

    202
    203
    204
    204

    205
    207
    208

    210
    211
    214
    216
    219
    220
    221

    223

    Preface
    E-learning can be described as the use of computers and digital technology to
    facilitate teaching and learning. One popular method of accomplishing this, and
    which is also the approach we will take in this book, is