City Basics Youtube Youtube.Com/Daggerfallworkshop V1.3.31 [Unity 5.0.1] | 06/08/2015 Twitter Twitter.Com/Gav Clayton Email [email protected]
Total Page:16
File Type:pdf, Size:1020Kb
Devblog dfworkshop.net Forums forums.dfworkshop.net Daggerfall Tools for Unity Tutorial Source github.com/Interkarma/daggerfall-unity City Basics YouTube youtube.com/daggerfallworkshop V1.3.31 [Unity 5.0.1] | 06/08/2015 Twitter twitter.com/gav_clayton Email [email protected] City Basics Introduction This tutorial builds on concepts introduced in Dungeon Basics. It assumes you now have some familiarity with the Unity Editor and Daggerfall Tools for Unity. In this tutorial, we will import the city of Daggerfall, add a sky background, change time and seasons, enter buildings and dungeons, and open and close city gates. Let’s get to it! Getting Started Please create a new project and scene by following the Getting Started tutorial. To summarise: Note: You must be running Unity 5.0.1 or later. Create a New Project and import Custom Package “Daggerfall Tools for Unity.unitypackage”. Empty default scene and add DaggerfallUnity and Player (or PlayerAdvanced) prefabs. Prepare Lighting configuration and set player Rendering Path to Deferred. Set Quality settings to Fantastic. Set Arena2 Path of your local Daggerfall installation. Create Run input binding and optionally invert mouse look. Import Daggerfall City Go to the Daggerfall Unity Importer foldout and enter Daggerfall/Daggerfall into City Name (this field is case sensitive) then click Import. This will take a few seconds to read and convert data from Daggerfall’s files into your Unity scene. When finished, you should have a completed scene like below. Devblog dfworkshop.net Forums forums.dfworkshop.net Daggerfall Tools for Unity Tutorial Source github.com/Interkarma/daggerfall-unity City Basics YouTube youtube.com/daggerfallworkshop V1.3.31 [Unity 5.0.1] | 06/08/2015 Twitter twitter.com/gav_clayton Email [email protected] Above: Daggerfall City consists of 8x8 exterior block elements. Adding Sunlight To add sunlight, drag and drop the Sunlight Rig from Prefabs/World into your Hierarchy. This will add more light using a simple three-point directional light setup. The Sunlight Rig prefab also has some automation we’ll look at in a few minutes. Devblog dfworkshop.net Forums forums.dfworkshop.net Daggerfall Tools for Unity Tutorial Source github.com/Interkarma/daggerfall-unity City Basics YouTube youtube.com/daggerfallworkshop V1.3.31 [Unity 5.0.1] | 06/08/2015 Twitter twitter.com/gav_clayton Email [email protected] Note: Daggerfall Tools for Unity uses the Unity 5 Standard Shader for almost all materials. This means you can use Physically Based Shading, skyboxes, realtime GI, and other advanced lighting methods. However, this tutorial only covers basic lighting for simplicity. Position Player Select the Player object in Hierarchy and set their transform as below. This positions your player in the main thoroughfare facing Daggerfall Castle. Hit Play and have a brief explore. When you’re done, press Play again to exit play mode. Add Sky Background Now we have a city to explore, but the sky is completely dark. Let’s go through the steps of adding a sky to our scene. There is a SkyRig prefab for you in Prefabs/World. But rather than just drop in a prefab, we’ll go through the steps of adding a sky manually to see how it works. Click GameObject > Create Empty and rename it CitySky. With CitySky selected, add the Daggerfall Sky component. This also adds a secondary Camera component for the sky renderer which you can ignore. Sky Index is a number between 0-31 controlling the sky to be displayed. Daggerfall uses a variety of sky images to represent different climates, seasons, and weather. Devblog dfworkshop.net Forums forums.dfworkshop.net Daggerfall Tools for Unity Tutorial Source github.com/Interkarma/daggerfall-unity City Basics YouTube youtube.com/daggerfallworkshop V1.3.31 [Unity 5.0.1] | 06/08/2015 Twitter twitter.com/gav_clayton Email [email protected] Sky Frame is a number between 0-63 controlling the sky animation. There are 32 frames of animation from dawn to midday, where the skies are flipped east-to-west then those animations are played backwards from midday to dusk. DaggerfallSky takes care of all the animation and flipping. Just think of a complete day cycle having 64 frames of animation. For Daggerfall’s 12-hour daylight period, this is equivalent to 1 step every 11.25 minutes. Is Night will exchange the sky for a static night time version. Night skies have only a single frame, so Sky Frame will be ignored until Is Night is cleared. Show Stars will toggle a random star field in night skies. Sky Tint Color will colourize the sky in realtime. This is useful for creating a variety of effects. Default is 128, 128, 128, 255 for R, G, B, A values. Sky Color Scale is the overall brightness of the sky in realtime. This is handy if you need to darken the sky (e.g. a partial blindness debuff) or ramp it up extra-bright (e.g. lightning flashes). Weather Style sets optional overcast textures. Just leave this on Normal for now. Click Play now and your sky will be rendered to the background under other geometry. Above: Sky background added to scene. Changing Time & Seasons You may have noticed a few check boxes in the DaggerfallUnity singleton about automating time and space. These options indicate the tools should automatically swap textures and other settings to handle day/night and seasonal transitions. Devblog dfworkshop.net Forums forums.dfworkshop.net Daggerfall Tools for Unity Tutorial Source github.com/Interkarma/daggerfall-unity City Basics YouTube youtube.com/daggerfallworkshop V1.3.31 [Unity 5.0.1] | 06/08/2015 Twitter twitter.com/gav_clayton Email [email protected] With automation enabled, many of the components in Daggerfall Tools for Unity are able to perform texture swaps and other changes to simulate time of day and passing of the seasons. The key to this automation lies in the World Time component on the DaggerfallUnity singleton. If you can’t see all settings above, expand the World Date Time field. These values represent the exact in-game time down to the second. These fields are all zero-based, which means the 12 months of the year are represented by 0-11, the 24 hours of the day are 0-23, etc. The first thing we’ll do is change the season to one of the winter months. To do this, simply edit the Month field to 12, which corresponds to Evening Star (or December on Earth). Hit Play and your game world is plunged into winter. When you’re done exploring, press Play again and return to editing. The next thing to try changing is the time of day. Set the Hour field to 0 (midnight) and go into Play mode again. We now have a night-time winter scene. Above: A winter scene. Above: Night-time in winter. Devblog dfworkshop.net Forums forums.dfworkshop.net Daggerfall Tools for Unity Tutorial Source github.com/Interkarma/daggerfall-unity City Basics YouTube youtube.com/daggerfallworkshop V1.3.31 [Unity 5.0.1] | 06/08/2015 Twitter twitter.com/gav_clayton Email [email protected] Now set the Month back to 5 and Hour back to 12 (or just reset World Time back to prefab settings). The final thing we can try is changing the Time Scale to watch day-night transitions. Set this to a high value like 2000 and Play the game again. You can now watch shadows creep across the ground, lights turn on and off, and day follow night. If you’d like to see the current time then enable Show Debug String to display the time on-screen. Don’t forget to reset your Time Scale back to 10 or revert World Time to prefab before moving on. Building Interiors Let’s explore inside those buildings! The transition between outside and inside is handled by several different components all working together. DaggerfallStaticDoors. This component was imported along with the city. Every building (or block when using RMB combining) contains a list of doors the player can use to enter/exit buildings and dungeon. PlayerActivate. This script detects when the player clicks on things. In this case, it will handle the player clicking on doors. PlayerEnterExit. This script transitions player in and out of buildings and dungeons. There are a few options here to help you build dynamic, compartmentalized scenes. We will look at these more closely in a moment. DaggerfallInterior. This script handles the layout of a new interiors at runtime. It would be far too memory-intensive to load every interior from the editor. Instead we only load them as needed, just like Daggerfall. GameObjectHelper. This script is filled with static helper objects to construct new scene data dynamically. It is used heavily by the editor when importing scenes, but you can also use this script to import anything at runtime as well. If you ever need to load a Daggerfall game object at runtime, there is probably a helper for it here. PlayerGPS. Provides information about player’s position in world space for texture swaps and dungeon transitions. We’ll touch on more in a few minutes. Before we can enter buildings there are a few scripts required by our player. Select Player in Hierarchy then click Add Component in its Inspector. Add the Scripts > DaggerfallWorkshop.Demo > Player Activate component. We looked at this script in the Dungeon Basics tutorial. It is responsible for detecting clicks on world objects like doors and switches. With Player still selected in Hierarchy add component Scripts > DaggerfallWorkshop.Demo > Player Enter Exit. This script transitions player in and out of buildings. Let’s take a closer look. Devblog dfworkshop.net Forums forums.dfworkshop.net Daggerfall Tools for Unity Tutorial Source github.com/Interkarma/daggerfall-unity City Basics YouTube youtube.com/daggerfallworkshop V1.3.31 [Unity 5.0.1] | 06/08/2015 Twitter twitter.com/gav_clayton Email [email protected] Exterior Parent is a parent GameObject to be disabled/enabled as player enters/exits buildings.