Unity doc reading notes (2) Asset Workflow

An asset is any item that you use in your Unity project to create a game or app. An asset can represent visual or audio elements in the project, such as 3D models, textures, sprites, sound effects, or music. Assets can also represent more abstract items, such as gradual changes in colors, animated masks, or arbitrary text or digital data. Assets may come from files created outside of Unity, such as 3D models, audio files, or images. You can also create some types of assets in the Unity editor, such as ProBuilder Mesh, Animator Controller, Audio Mixer, or Render texture

Typical workflow when using resources in Unity. Each column represents a separate step, as described below:

  • Import assets into the Unity editor

  • Use the Unity editor to ** create ** content from these resources.

  • ** Build ** your app or game files, and optional accompanying content packs

  • ** Distribute ** built files so that your users can access them through the publisher or app store

  • Load further updates at runtime as needed, based on your users behavior and how you group and bundle your content.

https://docs.unity3d.com/cn/current/Manual/AssetWorkflow.html

Import

To import assets created outside of Unity into a Unity project, you can export the file directly to the Assets folder under the project, or copy it to that folder. For many common formats, you can save the source file directly to the Assets folder of the project, and Unity can read it. Unity will detect the updated file and re-import it.

Resource import settings

Each type of resource supported by Unity has a set of import settings that affect how the resource appears or behaves. To view the import settings for a resource, select the resource in the Project view . The import settings for the resource appear in the Inspector. The options displayed vary depending on the type of resource selected.

For example, in the import settings for Unity images, you can choose to import them as textures, 2D sprites, or normal maps. In the import settings for FBX files, you can adjust the scale, generate normal or lightmap coordinates, and split and trim animation clips defined in the file.

Resources processing

Unity reads and processes any file you add to the’Assets’ folder, converting the file contents into internal data that can be used directly in the game. The resource file itself remains unchanged, and the internal data is stored in the’Library 'folder of the project. This data is from the Unity editor资源数据库The components.

By using the internal format of the resource, Unity can prepare a version of the resource that can be used directly in the game for use at runtime in the Editor, while keeping the unmodified source files in the’Assets’ folder. Keeping the internal format separate from the resource files means you can quickly edit them and let the Editor automatically pick up the changes. For example, the Photoshop file format is convenient and you can save the ‘.psd’ file directly into the’Assets’ folder, but hardware such as mobile devices and PC graphics cards cannot directly handle the format to render as textures.

Unity stores internal representations of resources in the’Library ‘folder, which is similar to a cache folder. As a user, do not manually change the’Library’ folder, attempting to do so may negatively affect the project in Unity Editor. However, as long as the project is not open in Unity, it is safe to delete the’Library ‘folder, as Unity can regenerate all its data through the’Assets’ and’ProjectSettings’ folders. This also means that the’Library 'folder should not be placed under version control.

Other complex resources, such as models with textures or animations, or audio and video imports, can be found in the doc.

https://docs.unity3d.com/cn/current/Manual/ImportingAssets.html

Supported resource types

https://docs.unity3d.com/cn/current/Manual/AssetTypes.html

https://docs.unity3d.com/2020.3/Documentation/Manual/BuiltInImporters.html

Or through the Script-Importer custom resource definition importer

https://docs.unity3d.com/2020.3/Documentation/Manual/ScriptedImporters.html

Metadata of resources

https://docs.unity3d.com/2020.3/Documentation/Manual/AssetMetadata.html

Resource database

For most types of resources, Unity needs to convert the data in the source files of the resource into a format that can be used in games or real-time applications. These converted files and their associated data are stored in the Asset Database.

Since most file formats are optimized to save storage space, the conversion process needs to be performed, while in games or real-time applications, resource data needs to be in a format available for hardware (such as CPU, graphics card, or audio hardware) to be used immediately. For example, when Unity imports a .png image file as a texture, the original .png format data will not be used at runtime. While importing a texture, Unity will create a new representation of the image in another format and store it in the project’s * Library * folder. The Texture class in the Unity engine uses this imported version, which Unity then uploads to the GPU for real-time display.

If you subsequently modify the source file that the resource has imported (or change any of its dependencies), Unity will reimport the file and update the data of the imported version.

Resource Cache

The resource cache is where Unity stores imported versions of resources. Since Unity can always recreate these imported versions from source resource files and their dependencies, these imported versions are considered a cache of pre-computed data. This cache saves time when using Unity. Therefore, files in the resource cache should be excluded from the version control system.

By default, Unity uses local caching, which means that the resources of the imported version will be cached in the Library folder of the project folder on the local computer. This folder should be excluded from version control using ignore file.

However, if you are a team member and use a version control system, it is best to also use Unity AcceleratorIt can share resource caches across LANs.

Since cached resources are not suitable for storage in a version control system, when your team works together on a project and uses local caching, if resources or dependencies change, each team member’s copy of Unity will perform the import process, which can be time-consuming.

Unity’s solution for this is called Unity AcceleratorOne of the features of Accelerator is a software agent that stores cached versions of resources and makes them available to everyone working together on the same project on the same local networkThis means that only one team member needs to import any given resourceSubsequently, the imported version of the resource will be stored in Accelerator, and other team members can download the cached version without having to wait locally for the import process.

https://docs.unity3d.com/cn/current/Manual/AssetDatabaseRefreshing.html

https://docs.unity3d.com/cn/current/Manual/AssetDatabaseBatching.html

Special folder name

https://docs.unity3d.com/cn/current/Manual/SpecialFolders.html

Preset

You can save the settings of some Components in the component and then apply them to the required Components later.

https://docs.unity3d.com/cn/current/Manual/Presets.html

Asset

An AssetBundle is an archive file that contains platform-specific non-code resources (such as models, textures, prefabs, audio clips, and even entire scenes) that can be loaded by Unity at runtime. AssetBundles can represent dependencies between each other; for example, materials in one AssetBundle can reference textures in another AssetBundle. To improve the efficiency of transmission over the network, AssetBundles can be compressed by selecting the algorithm built-in selection according to the requirements of the use case (LZMA and LZ4).

AssetBundles can be used for downloadable content (DLC), reducing the initial Installation size, loading resources optimized for end-user platforms, and reducing runtime memory pressure.

** Note: ** An AssetBundle can contain serialized data for instances of code objects, such as a ScriptableObject. However, the class definition itself is compiled as one of the project assemblies. When you load a serialized object in an AssetBundle, Unity finds the matching class definition, creates an instance of it, and sets the fields of that instance with the serialized values. This means that you can introduce new items into the game in an AssetBundle, as long as those items do not require any changes to your class definition.

https://docs.unity3d.com/cn/current/Manual/AssetBundles-Workflow.html

Scripts and Resources

https://docs.unity3d.com/cn/current/Manual/LoadingResourcesatRuntime.html

Streaming Media Resources

Unity integrates most of the resources into the project when building it. However, it is sometimes useful to put the file into a normal file system on the target computer so that it is accessible by pathname. An example of this is deploying a movie file on a iOS device; the original movie file must be somewhere in the file system for playback by the’PlayMovie 'function.

Unity copies verbatim all files placed in a folder named ** StreamingAssets__ (case sensitive) in your Unity project to a specific folder on your target computer. To get this folder, use ** Application.streamingAssetsPath** attribute. In any case, it is best to use Application.streamingAssetsPath to get the location of the StreamingAssets__ folder, as it always points to the correct location on the platform on which the application is running.