包含此页的版本:
不含此页的版本:
使用纹理压缩一种存储数据的方法,可减少所需的存储空间量。请参阅纹理压缩、动画压缩、音频压缩、构建压缩。
请参阅术语表在 Web 平台中创建基于纹理压缩3D图形硬件要求将纹理压缩为专用格式,这些格式针对快速纹理采样进行了优化。更多信息
请参阅术语表它们支持的格式。
桌面和移动设备支持不同的纹理压缩格式。如果希望 Web 应用程序在两种类型的浏览器上使用压缩纹理,则必须首先选择受支持的纹理压缩格式。
要在具有压缩纹理的桌面和移动浏览器上运行游戏,您可能需要创建两个面向:
您可以从 Web 生成设置或 Web 中为 Web 应用程序设置默认纹理压缩格式玩家设置设置,可让您为 Unity 构建的最终游戏设置各种特定于玩家的选项。更多信息
请参阅术语表.在设置纹理压缩格式之前,请务必确定哪些设置优先。在构建设置中设置的纹理压缩格式值优先于在 玩家设置(Player Settings) 中设置的值。默认情况下,Unity 编辑器将构建设置值设置为“使用播放器设置”。
注意:编辑器在构建设置中序列化纹理压缩Library文件夹。这意味着它不受版本控制用于管理文件更改的系统。您可以将 Unity 与最常见的版本控制工具结合使用,包括 Perforce、Git、Mercurial 和 PlasticSCM。更多信息
请参阅术语表.
您还可以自定义单个纹理的纹理压缩格式。您为个人设置的值texture 覆盖特定于平台的设置,允许你为每个目标平台设置分辨率、文件大小以及相关的内存大小要求、像素尺寸和纹理质量。更多信息
请参阅术语表默认纹理压缩格式值。有关如何更改纹理格式一种文件格式,用于在 3D 图形硬件(例如显卡或移动设备)实时渲染期间处理纹理。更多信息
请参阅术语表单个纹理,请参阅纹理导入设置。
您可以使用构建设置或播放器设置为 Web 应用程序设置默认纹理压缩格式。在构建设置中设置的纹理压缩格式值优先于在播放器设置中设置的值。默认情况下,Unity 编辑器将构建设置值设置为“使用播放器设置”。
要使用构建设置选择默认纹理压缩格式,请执行以下作:
要使用播放器设置选择默认纹理压缩格式,请执行以下作:
有关如何同时为桌面浏览器和移动浏览器创建构建版本及其相应的纹理压缩格式的示例,请参阅从脚本为桌面浏览器和移动浏览器创建构建版本。
你可以使用脚本同时为桌面浏览器和移动浏览器运行具有相应纹理压缩格式的构建。例如:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Diagnostics;
using System.IO;
using UnityEditor.Build.Reporting;
public class comboBuild
{
//This creates a menu item to trigger the dual builds https://docs.unity3d.com/ScriptReference/MenuItem.html
[MenuItem("Game Build Menu/Dual Build")]
public static void BuildGame()
{
//This builds the player twice: a build with desktop-specific texture settings (WebGL_Build)
//as well as mobile-specific texture settings (WebGL_Mobile),
//and combines the necessary files into one directory (WebGL_Build)
string dualBuildPath = "WebGLBuilds";
string desktopBuildName = "WebGL_Build";
string mobileBuildName = "WebGL_Mobile";
string desktopPath = Path.Combine(dualBuildPath, desktopBuildName);
string mobilePath = Path.Combine(dualBuildPath, mobileBuildName);
string[] scenes = new string[] {"Assets/scene.unity"};
EditorUserBuildSettings.webGLBuildSubtarget = WebGLTextureSubtarget.DXT;
BuildPipeline.BuildPlayer(scenes, desktopPath, BuildTarget.WebGL, BuildOptions.Development);
EditorUserBuildSettings.webGLBuildSubtarget = WebGLTextureSubtarget.ASTC;
BuildPipeline.BuildPlayer(scenes, mobilePath, BuildTarget.WebGL, BuildOptions.Development);
// Copy the mobile.data file to the desktop build directory to consolidate them both
FileUtil.CopyFileOrDirectory(Path.Combine(mobilePath, "Build", mobileBuildName + ".data"), Path.Combine(desktopPath, "Build", mobileBuildName + ".data"));
}
}
您可以修改 Web 模板的 index.htmlfile 以选择适当的数据文件(如果支持纹理压缩格式扩展):
// choose the data file based on whether there's support for the ASTC texture compression format
var dataFile = "/{{{ DATA_FILENAME }}}";
var c = document.createElement("canvas");
var gl = c.getContext("webgl");
var gl2 = c.getContext("webgl2");
if ((gl && gl.getExtension('WEBGL_compressed_texture_astc')) || (gl2 &&
gl2.getExtension('WEBGL_compressed_texture_astc'))) {
dataFile = "/WebGL_Mobile.data";
}
var buildUrl = "Build";
var loaderUrl = buildUrl + "/{{{ LOADER_FILENAME }}}";
var config = {
dataUrl: buildUrl + dataFile,
frameworkUrl: buildUrl + "/{{{ FRAMEWORK_FILENAME }}}",
#if USE_WASM
codeUrl: buildUrl + "/{{{ CODE_FILENAME }}}",
#endif
#if MEMORY_FILENAME
memoryUrl: buildUrl + "/{{{ MEMORY_FILENAME }}}",
#endif
#if SYMBOLS_FILENAME
symbolsUrl: buildUrl + "/{{{ SYMBOLS_FILENAME }}}",
#endif
streamingAssetsUrl: "StreamingAssets",
companyName: {{{ JSON.stringify(COMPANY_NAME) }}},
productName: {{{ JSON.stringify(PRODUCT_NAME) }}},
productVersion: {{{ JSON.stringify(PRODUCT_VERSION) }}},
showBanner: unityShowBanner,
};