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 mip 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 mip that is two mip 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 mip 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 mip maps 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 mip level

要覆盖特定纹理的 Mip 级别计算,请使用 Texture2D.requestedMipmapLevel。这是一个精确的 Mip 级别,范围从 0 到特定纹理的最高 Mip 级别或者是 Max Level Reduction 值(如果该值更大)。0 表示最高分辨率的 Mip。

要检查您请求的 Mip 级别是否已加载,请使用 Texture2D.IsRequestedMipmapLevelLoaded

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

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

float Mesh.GetUVDistributionMetric(int uvSetIndex)

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

要覆盖系统并强制加载所有 Mip,请使用 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
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961