# 웹에서 텍스처 압축

> Information about using texture compression in Web.

웹 플랫폼에서 텍스처 압축을 사용하여 지원되는 텍스처 압축 포맷에 따라 플랫폼을 타게팅하는 빌드를 생성합니다.

## 텍스처 압축 포맷##texture-compression-formats

데스크톱 및 모바일 기기는 다양한 텍스처 압축 포맷을 지원합니다. 웹 애플리케이션이 두 가지 유형의 브라우저에서 압축 텍스처를 사용하도록 하려면, 먼저 지원되는 텍스처 압축 포맷을 선택해야 합니다.

압축 텍스처를 사용하여 데스크톱 및 모바일 브라우저 모두에서 게임을 실행하기 위해 타게팅하는 빌드를 2개 생성할 수 있습니다.

* DXT가 텍스처 압축 포맷으로 설정된 데스크톱 브라우저
* ASTC(적응형 확장 가능 텍스처 압축)가 텍스처 압축 포맷으로 설정된 모바일 브라우저

## 압축 포맷 설정의 우선 순위##precedence-for-compression-format-settings

웹 애플리케이션의 기본 텍스처 압축 포맷은 [웹 Build Settings](/engine/6000.0/manual/platform-specific/webgl/building-distribution/web-build-settings.md) 창 또는 웹 [Player 설정](/engine/6000.0/manual/platform-specific/webgl/develop/class-player-settings-web-gl.md) 창에서 설정할 수 있습니다. 텍스처 압축 포맷을 설정하기 전에 이러한 설정의 우선순위를 결정하는 것이 중요합니다. Build Settings에서 설정한 값이 Player 설정에서 설정한 값보다 우선합니다. 기본적으로 Unity 에디터는 Build Settings 값을 **Use Player Settings**로 설정합니다.

**참고:** 에디터는 `Library` 폴더의 Build Settings에서 텍스처 압축을 직렬화합니다. 즉, 버전 관리를 통해 관리되지 않습니다.

개별 텍스처에 텍스처 압축 포맷도 커스터마이즈할 수 있습니다. 개별 텍스처에 설정한 값은 기본 텍스처 압축 포맷 값을 오버라이드합니다. 개별 텍스처의 텍스처 포맷을 변경하는 방법에 대한 자세한 내용은 [텍스처 임포트 설정](/engine/6000.0/manual/materials-and-shaders/textures/textures-reference/class-texture-importer.md)을 참조하십시오.

## 기본 압축 포맷 설정##set-the-default-compression-format

Build Settings 또는 Player 설정을 통해 웹 애플리케이션의 기본 텍스처 압축 포맷을 설정할 수 있습니다. Build Settings에서 설정한 값이 Player 설정에서 설정한 값보다 우선합니다. 기본적으로 Unity 에디터는 Build Settings 값을 **Use Player Settings**로 설정합니다.

Build Settings를 통해 기본 텍스처 압축 포맷을 선택하려면 다음 단계를 따르십시오.

1. **File** > **Build Settings**를 선택합니다.
2. **Platform** 창의 플랫폼 리스트에서 **Web**을 선택합니다.
3. **Texture Compression** 드롭다운 메뉴에서 압축 포맷을 선택합니다.

Player 설정을 통해 기본 텍스처 압축 포맷을 선택하려면 다음 단계를 따르십시오.

1. **File** > **Build Settings**를 선택합니다.
2. **Platform** 창의 플랫폼 리스트에서 **Web**을 선택합니다.
3. **Player 설정** > **Other Settings**를 선택합니다.
4. **Texture compression format** 드롭다운 메뉴에서 압축 포맷을 선택합니다.

해당 텍스처 압축 포맷으로 데스크톱 및 모바일 브라우저용 빌드를 동시에 생성하는 방법에 대한 예시는 [스크립트에서 데스크톱 및 모바일 브라우저용 빌드 생성](#desktop+mobile)을 참조하십시오.

## 스크립트에서 데스크톱 및 모바일 브라우저용 빌드 생성##create-builds-for-desktop-and-mobile-browsers-from-a-scriptscrollpoint-id=desktop+mobile-/

스크립트를 사용하여 해당 텍스처 압축 포맷으로 동시에 데스크톱 브라우저 및 모바일 브라우저용 빌드를 실행할 수 있습니다. 예시:

```
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"));
    }  
}
```

텍스처 압축 포맷 확장자를 지원하는 경우 [웹 템플릿](/engine/6000.0/manual/platform-specific/webgl/building-distribution/templates.md)의 `index.html` 파일을 수정하여 적절한 데이터 파일을 선택할 수 있습니다.

```
// 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,                                            
     };  
```

## 추가 리소스##additional-resources

* [웹 애플리케이션 빌드](/engine/6000.0/manual/platform-specific/webgl/building-distribution/building.md)
* [Player 설정](/engine/6000.0/manual/platform-specific/webgl/develop/class-player-settings-web-gl.md)
