C# 코드를 사용하여 최적화 설정 활성화
Use a C# script to enable some optimization settings.
읽는 시간 1분최근 업데이트: 한 달 전
코드를 사용하여 웹 빌드 최적화에서 권장하는 일부 최적화를 활성화할 수 있습니다. 코드를 사용하여 이러한 설정을 구성하면 각 설정을 개별적으로 수동 설정해야 하는 시간을 절약할 수 있습니다.
참고: 이 스크립트는 빌드가 아닌 Unity 에디터에서 작동합니다.
C# 스크립트를 만들어 웹 빌드 최적화
코드를 사용하여 Unity 프로젝트 설정에서 대부분의 최적화를 한 번에 활성화하려면 다음 단계를 따르십시오.
-
아직폴더가 없다면 폴더를 만듭니다.
Assets/Editor -
폴더에 빈 C# 스크립트를 만듭니다.
Editor -
다음 코드를 스크립트에 붙여 넣습니다.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; }}
-
프로젝트에 맞게 스크립트를 변경합니다.
-
툴바에서 Example > Optimize를 선택하여 스크립트를 실행합니다. 설정이 업데이트됩니다.
에셋 임포트 오버라이드에 대한 설정을 변경하려면 빌드 프로파일 레퍼런스를 참조하십시오.