앱 슬라이싱을 사용하면 애플리케이션이 실행 중인 기기의 사양에 따라 에셋을 동적으로 다운로드할 수 있습니다. 예를 들어 대용량 기기에는 고해상도 에셋을, 저용량 기기에는 저해상도 에셋을 다운로드할 수 있습니다. 앱 슬라이싱은 에셋 번들을 정의하는 방식으로 작동하며, 배리언트 프로비전이 추가되었습니다. 시작 시 어떤 배리언트를 사용할지 결정하고 다운로드 시 자동으로 에셋 파일 이름에 추가할 수 있습니다.
배리언트를 생성하려면 다음 단계를 따르십시오.
BuildiOSAppSlices.cs
라는 새 스크립트를 생성합니다.textures
와 배리언트 hd
및 sd
를 자체 항목으로 교체합니다. 이 코드 예시에서는 HD 텍스처가 포함된 폴더와 SD 텍스처가 포함된 폴더 등 여러 폴더를 참조합니다. 이러한 폴더에는 배리언트 hd 및 sd가 부여됩니다.using UnityEngine;
using UnityEditor;
public class BuildiOSAppSlices : MonoBehaviour
{
[InitializeOnLoadMethod]
static void SetupResourcesBuild( )
{
UnityEditor.iOS.BuildPipeline.collectResources += CollectResources;
}
static UnityEditor.iOS.Resource[] CollectResources( )
{
return new UnityEditor.iOS.Resource[]
{
new UnityEditor.iOS.Resource("textures").BindVariant( "Assets/ODR/textures.hd", "hd" )
.BindVariant( "Assets/ODR/textures.sd", "sd" )
.AddOnDemandResourceTags( "textures" ),
};
}
[MenuItem( "Bundle/Build iOS App Slices" )]
static void BuildAssetBundles( )
{
var options = BuildAssetBundleOptions.None;
bool shouldCheckODR = EditorUserBuildSettings.activeBuildTarget == BuildTarget.iOS;
# if UNITY_TVOS
shouldCheckODR |= EditorUserBuildSettings.activeBuildTarget == BuildTarget.tvOS;
# endif
if( shouldCheckODR )
{
# if ENABLE_IOS_ON_DEMAND_RESOURCES
if( PlayerSettings.iOS.useOnDemandResources )
options |= BuildAssetBundleOptions.UncompressedAssetBundle;
# endif
# if ENABLE_IOS_APP_SLICING
options |= BuildAssetBundleOptions.UncompressedAssetBundle;
# endif
}
BuildPipeline.BuildAssetBundles( "Assets/ODR", options, EditorUserBuildSettings.activeBuildTarget );
}
}
이 코드는 Unity 에디터 메뉴 바에 Bundle이라는 새 메뉴를 생성합니다. 이를 클릭하고 Build iOS App Slices를 선택합니다. 그러면 ODR
폴더에 에셋 번들이 생성됩니다.
에셋을 로드하려면 Assets 폴더에 LoadBundle.cs
라는 스크립트 파일을 생성하고 다음 코드를 복사합니다. textures
를 로드하려는 배리언트의 이름으로 교체합니다.
using UnityEngine;
using UnityEngine.iOS;
using System;
using System.Collections;
public class LoadBundle : MonoBehaviour
{
public AssetBundle TextureBundle;
void Start( )
{
LoadAssetAsync( "textures", "textures" );
}
public IEnumerator LoadAsset( string resourceName, string odrTag )
{
// Create the request
using(OnDemandResourcesRequest request = OnDemandResources.PreloadAsync( new string[] { odrTag } ))
{
// Wait until request is completed
await request;
// Check for errors
if( request.error != null )
throw new Exception( "ODR request failed: " + request.error );
TextureBundle = AssetBundle.LoadFromFile( "res://" + resourceName );
}
}
}
특정 기기나 설정된 메모리 제한을 초과하여 실행되는 기기에서 배리언트를 사용하려는 경우가 있을 수 있습니다. 이렇게 하려면 사용하는 각 배리언트의 설정을 변경하면 됩니다.
배리언트를 수정하려면 Player Settings > Other Settings > Configuration으로 이동하여 Variant map for app slicing을 확장합니다.
참고: Player Settings > Other > Configuration에서 Use on demand resources를 활성화하면 Variant map for app slicing 옵션을 볼 수 있습니다.
설정 | 설명 | |
---|---|---|
Variant name | 로딩 스크립트에서 배리언트 이름을 표시합니다. | |
Device | 이 배리언트가 타게팅할 기기를 선택합니다. | |
Memory | 이 배리언트에 필요한 최소 메모리를 선택합니다. | |
Graphics | 이 배리언트에 사용할 Metal 프레임워크를 선택합니다. | |
Display color space | 이 배리언트에 사용할 색 영역을 선택합니다. | |
Add custom entry | 커스텀 설정 및 값을 추가하려면 Add custom entry를 클릭합니다. | |
Key | 설정의 이름을 입력합니다. | |
값 | 설정의 값을 입력합니다. |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.