# C# 코드를 사용하여 최적화 설정 활성화

> Use a C# script to enable some optimization settings.

코드를 사용하여 [웹 빌드 최적화](/engine/6000.0/manual/platform-specific/webgl/building-distribution/web-optimization.md)에서 권장하는 일부 최적화를 활성화할 수 있습니다. 코드를 사용하여 이러한 설정을 구성하면 각 설정을 개별적으로 수동 설정해야 하는 시간을 절약할 수 있습니다.

**참고**: 이 스크립트는 빌드가 아닌 Unity 에디터에서 작동합니다.

## C# 스크립트를 만들어 웹 빌드 최적화##create-a-c-script-to-optimize-your-web-build

코드를 사용하여 Unity 프로젝트 설정에서 대부분의 최적화를 한 번에 활성화하려면 다음 단계를 따르십시오.

1. 아직 `Assets/Editor` 폴더가 없다면 폴더를 만듭니다.

2. `Editor` 폴더에 빈 C# 스크립트를 만듭니다.

3. 다음 코드를 스크립트에 붙여 넣습니다.

   ```lang-cs
   using UnityEditor;
   using UnityEditor.Build;
   using UnityEngine;

   public class WebOptimizer
   {
       [MenuItem("Example/Optimize")]
       public static void Optimize()
       {
           var namedBuildTarget = NamedBuildTarget.WebGL;
           var buildOptions = BuildOptions.CompressWithLz4HC;

           // Set IL2CPP code generation to Optimize Size 
           PlayerSettings.SetIl2CppCodeGeneration(namedBuildTarget,         
                                           Il2CppCodeGeneration.OptimizeSize);

           // Set the Managed Stripping Level to High
           PlayerSettings.SetManagedStrippingLevel(namedBuildTarget,     
                                               ManagedStrippingLevel.High);  

           // Strip unused mesh components           
           PlayerSettings.stripUnusedMeshComponents = true;

           // Enable data caching
           PlayerSettings.WebGL.dataCaching = true;

           // Set the compression format to Brotli
           PlayerSettings.WebGL.compressionFormat = WebGLCompressionFormat.Brotli;

           // Deactivate exceptions
           PlayerSettings.WebGL.exceptionSupport = WebGLExceptionSupport.None;

           // Deactivate debug symbols
           PlayerSettings.WebGL.debugSymbolMode = WebGLDebugSymbolMode.Off;

           //Enable WebAssembly 2023 features
           PlayerSettings.WebGL.wasm2023 = true;           

           // Set Platform Settings to optimize for disk size (LTO)
           UnityEditor.WebGL.UserBuildSettings.codeOptimization = UnityEditor.WebGL.WasmCodeOptimization.DiskSizeLTO;
       }
   }
   ```

4. 프로젝트에 맞게 스크립트를 변경합니다.

5. 툴바에서 **Example** > **Optimize**를 선택하여 스크립트를 실행합니다. 설정이 업데이트됩니다.

에셋 임포트 오버라이드에 대한 설정을 변경하려면 [빌드 프로파일 레퍼런스](/engine/6000.0/manual/unity-editor/editor-features/build-settings/build-profiles-reference.md#AssetImportOverride)를 참조하십시오.

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

* [웹 빌드 최적화](/engine/6000.0/manual/platform-specific/webgl/building-distribution/web-optimization.md)

* [웹 빌드를 최적화하기 위한 권장 Graphics 설정](/engine/6000.0/manual/platform-specific/webgl/building-distribution/web-optimization/graphics.md)

* [웹 빌드를 최적화하기 위한 권장 Player 설정](/engine/6000.0/manual/platform-specific/webgl/building-distribution/web-optimization/player.md)

* [웹 빌드를 최적화하기 위한 권장 Quality 설정](/engine/6000.0/manual/platform-specific/webgl/building-distribution/web-optimization/quality.md)

* [웹 빌드에서 미사용 리소스 제거](/engine/6000.0/manual/platform-specific/webgl/building-distribution/web-optimization/remove-resources.md)

* [모바일용 웹 플랫폼 최적화](/engine/6000.0/manual/platform-specific/webgl/building-distribution/web-optimization-mobile.md)
