Hands-On Unity 2020 Game Development
上QQ阅读APP看书,第一时间看更新

Importing assets

We have different sources of assets we can use in our project. We can simply get a file from our artist, download them from different free and paid assets sites, or we can use the Asset Store, Unity's official virtual asset store, where we can get free and paid assets ready to use with Unity. We will use a mix of downloading an asset from the internet and from the Asset Store, just to get all possible resources.

In this section, we will cover the following concepts related to importing assets:

  • Importing assets from the internet
  • Importing assets from the Asset Store
  • Downloading and importing assets into our project from the internet

Importing assets from the internet

In terms of getting art assets for our project, let's start with our terrain textures. Remember that we have our terrain painted with a grid pattern, so the idea is to replace that with grass, mud, rock, and other kinds of textures. To do that, we must get images. In this case, these kinds of images are usually top-down views of different terrain patterns, and they have the requirement of being "tileable." You can see an example of this in the following screenshot:

Figure 5.1 – Left: grass patch; right: the same grass patch separated to highlight the texture tiling

The grass on the left seems to be one single big image, but if you pay attention, you should be able to see some patterns repeating themselves. In this case, this grass is just a single image repeated four times in a grid, like the one on the right. This way, you can cover large areas by repeating a single small image, saving lots on RAM on your computer.

The idea is to get these kinds of images to paint our terrain. You can get them from several places, but the easiest way is to use Google Images or any Image Search Engine. To do this, follow these steps:

  1. Open your browser (Chrome, Safari, Edge, and so on).
  2. Go to your preferred search engine. In this case, I will use Google.
  3. Use the keywords PATTERN tileable texture, replacing PATTERN with the kind of terrain you are looking for, such as grass tileable texture or mud tileable texture. In this case, I am going to type grass tileable texture and then press Enter to search.
  4. Switch to image search mode:

    Figure 5.2 – Google Search for images

  5. Find any texture you find suitable for the kind of grass you need and click it. Remember that the texture must be a top-down view of the grass and must repeat.

    Important Note

    Try to check the image's resolution before picking it. Try to select squared images that have a resolution less than 1024 x 1024 for now.

  6. Right-click the opened image and select Save image as…:

    Figure 5.3 – Save image as… option

  7. Save the image in any folder you will remember.

Now that you have downloaded the image, you can add it to your project in several ways. The simplest one would be doing the following:

  1. Locate your image using File Explorer (Finder in Mac).
  2. Locate or create the Textures folder in the Project window in Unity.
  3. Put both File Explorer and Unity Project Window next to each other.
  4. Drag the file from File Explorer to the Textures folder in the Unity Project Window:

Figure 5.4 – Texture being dragged from File Explorer to Unity´s Project View

For simple textures like these ones, any search engine can be helpful, but if you want to replace the Player´s Base geometry with detailed walls and doors or place enemies in your scene, you need to get 3D models. If you search for those in any search engine using keywords such as "free zombie 3D model," you will find endless free and paid 3D models sites such as TurboSquid and Mixamo, but those sites can be problematic because those meshes are usually not prepared for being used in Unity, or even in games. You will find models with very high polygon counts, incorrect sizes or orientations, unoptimized textures, and so on. To prevent those problems, we'll want to use a better source, and in this case, we will use Unity´s Asset Store, so let's explore it.

Importing assets from the Asset Store

The Asset Store is Unity's official asset marketplace where you can find lots of models, textures, sounds, and even entire Unity plugins to extend the capabilities of the engine. In this case, we will limit ourselves to downloading 3D models to replace the Player´s Base prototype. You will want to get 3D models with a modular design, meaning that you will get several pieces such as walls, floors, corners, and so on. You can connect them to create any kind of scenario.

In order to do that, you must follow these steps:

  1. Click on Window | Asset Store in Unity, which will open a new window saying the Asset Store has moved. In previous versions of Unity, you could see the Asset Store directly inside the editor, but now it is recommended to open it in a regular web browser, so just click the Search online button:

    Figure 5.5 – Asset Store moved message

  2. Your browser will open showing a site similar to the one in the following screenshot:

    Figure 5.6 – Asset Store home page

  3. In the right panel, open the 3D category by clicking the arrow to its right. Then, open Environments and check the Sci-Fi mark. As you can see, there are several categories for finding different types of assets, and you can pick another one if you want to. In Environments, you will find 3D models that can be used to generate the scenery for your game.
  4. If you need to, you can pay for an asset, but let's hide the paid ones for now. You can do that by searching through the Pricing section on the sidebar, opening it using the plus (+) symbol on its right, and then checking the Free Assets checkbox:

    Figure 5.7 – Free Assets option

  5. In the search area, find any asset that seems to have the aesthetic you are looking for and click it. Remember to look out for outdoors assets, because most environment packs are usually interiors only. In my case, I have picked one called Sci-Fi Styled Modular Pack that serves for both interiors and exteriors. Take into account that that package might not exist by the time you are reading this, so you might need to choose another one. If you don't find a suitable package, you can download the asset files we used in the GitHub repository. Please refer to the preface instructions of how to access the it.

    Figure 5.8 – Preview of Asset Store searched packages

    Important Note

    At the time of writing this book, Unity is releasing the "Snaps" packages, which are a set of official Unity 3D models that can be used for the modular design of different kinds of environments. Some of them are paid, while others are free – I recommend that you try them out.

  6. Now, you will see the package details in the Asset Store window. Here, you can find information regarding the package's description, videos/images, the package's contents, and the most important part, the reviews, where you can check whether the package is worth buying if it's a paid one:

    Figure 5.9 – Asset Store package details

  7. If you are OK with this package, click the Add To My Assets button, log in to Unity if requested and then click Open In Unity button. You might be prompted to accept a switch of apps to Unity – just accept:

    Figure 5.10 – Switching apps

  8. This will open the Package Manger again, but this time in My Assets mode, showing a list of all the assets you have ever downloaded from the Asset Store, and the one you just selected highlighted in the list. You might need to log again in Unity clicking the Sign In button if you are not logged in Unity Hub.

    Figure 5.11 – Package Manager showing assets

  9. Click on Download at the bottom-right part of the window and wait for it to end. Then hit Import. Double check that you have the proper asset package selected from the list.
  10. After a while, the Package Contents Window will show up, allowing you to select exactly which assets of the package you want in your project. For now, leave it as-is and click Import:

    Figure 5.12 – Assets to import

  11. After some importing time, you will see all the package files in your Project Window.

Take into account that importing lots of full packages will increase your project's size considerably, and that, later, you will probably want to remove the assets that you didn't use. Also, if you import assets that generate errors that prevent you from playing the scene, just delete all the .cs files that come with the package. They are usually in folders called Scripts. Those are code files that might not be compatible with your Unity version. In Part 3, we will learn how to make our own so that those are not necessary:

Figure 5.13 – Code error warning when hitting play

Important Note

The Asset Store is prone to changes, even if you are using the same Unity version I am using, so the previous steps may be changed by Unity without notice. Also, its contents change often, and you may not find the same packages used in this book. In such case, you can find another similar package, or take the files i used from the GitHub repo (links and instructions in the Preface).

Before you continue with this chapter, try to download an enemy character using the Asset Store, following the previous steps. In order to solve this exercise, you must complete the same steps as before but look in the 3D | Characters | Humanoid category of the Asset Store.

Now that we have imported lots of art assets, let's learn how to use them in our scene.