Version: 2023.2
The Mipmap Streaming system
Streaming Controller component

The Mipmap Streaming system API

Use this API to override the default settings in the Mipmap Streaming system, or get more fine-grained control.

本页包含以下信息:

For general information about this system, see Mipmap Streaming system.

概述

You can use the API to override behavior for specific situations, while the Mipmap Streaming system automatically manages the default settings.

This is useful if you know that Unity needs to fully load certain textures; for example, if they relate to GameObjects that move large distances quickly, or if you use instantaneous camera cuts.

Controlling the Mipmap Streaming system

To enable and control Mipmap Streaming on a texture, use the following properties:

Mipmap Streaming automatically reduces the mipmap level of textures until they fit into the Mipmap Streaming Memory Budget. The Texture’s Mip Map Priority number is roughly a mipmap offset for the Memory Budget. For example, with a priority of 2, the Mipmap Streaming system tries to use a mipmap level that is two levels higher than other textures with a priority of 0. Negative values are also valid. If it can’t do this, it uses a lower mipmap level to fit the Memory Budget.

以下属性在运行时为只读:

要控制运行时的行为,请使用以下静态属性:

Controlling Cameras

When cutting from one location to another, the Mipmap Streaming system needs time to stream the required Textures into Unity. To trigger preloading at a disabled target Camera location, call StreamingController.SetPreloading on the target Camera’s Streaming Controller component. You can specify a time-out to end the preloading phase. To automatically enable the Camera at the end of the preloading phase, set the activateCameraOnTimeout flag to true in script. To disable a Camera after you cut from it to the new one, pass that Camera as the disableCameraCuttingFrom parameter.

void StreamingController.SetPreloading(float timeoutSeconds=0.0f, bool activateCameraOnTimeout=false, Camera disableCameraCuttingFrom=null)

要取消或查询预加载状态,请使用下列方法:

To determine whether the Mipmap Streaming system is still loading Textures, you can query the following properties:

Note that there is delay between when you enable a Camera and when these properties become a value other than zero. This delay is because the Mipmap Streaming system calculates the required mipmaps using time-sliced processing. For this reason, during a Camera cut you should wait a minimum length of time before the cut. Texture budget and Scene movement can cause continuous Mipmap Streaming, so you also need to set a maximum length of time before the cut.

Loading a specific mipmap level

To override the mipmap level calculation for a specific Texture, use Texture2D.requestedMipmapLevel. This is an exact mipmap level ranging from 0 to the maximum mipmap level of the specific Texture, or the Max Level Reduction value if that is lower. 0 is the highest resolution mipmap.

To check if your requested mipmap level has loaded, use Texture2D.IsRequestedMipmapLevelLoaded.

If you no longer want to override the mipmap level you requested and instead want the system to continue to calculate mipmap levels, use Texture2D.ClearRequestedMipmapLevel to reset the value.

要估算网格上的 UV 密度,请使用以下代码行:

float Mesh.GetUVDistributionMetric(int uvSetIndex)

可以使用 UV 分布指标根据摄像机的位置来计算所需的 Mipmap 级别。请参阅 Mesh.GetUVDistributionMetric 以查看代码示例。

To override the system and force all mipmap levels to load, use Texture.streamingTextureForceLoadAll.

Debugging and profiling

要获取可用于创建调试可视化的材质属性中每个纹理串流信息,请使用 Texture.SetStreamingTextureMaterialDebugProperties

You can use Texture.SetStreamingTextureMaterialDebugProperties to assign streaming status information for each texture to material properties. You can then use these properties in the shader to create debug visualizations.

You can also use these properties to create Mipmap Streaming profiling and debugging tools for your project.

To get information about the number of Textures or renderers the Mipmap Streaming system is interacting with, use the following properties:

要获取有关纹理的 Mipmap 级别的信息,请使用以下属性:

Related Unity API methods

要获取和设置分配给某一材质的纹理,请使用:

要获取某一材质中的所有纹理属性,请使用:

The Mipmap Streaming system
Streaming Controller component