유니티 자원 관리 종류
유니티에 파일로 된 자원을 관리하는 방법으로 3가지가 있다
1. Resources
2. AssetBundle
3. Addressable
그 중 Addressable은 AssetBundle의 기능을 계승하고 자원을 좀더 편의성있게 사용하기 위해 만들어졌다
AssetBundle과 Addressable은 모바일에서
Resources 단점
1. 리소스가 많으면 많을수록 빌드시 사이즈가 커진다
2. 앱 시작 시간이 길어진다 (비동기 방식이 아닌 동기 방식)
3. 리소스 수정하면 다시 전체 빌드를 해야 함 (시간적 소모)
AssetBundle 단점
1. 종속성 문제 (A번들과 B번들에서 C자원을 같이 쓰고 있다면 C자원은 두배의 자원 소모가 됨)
Addressable 장점
1. 종속성 문제 해결 (이를 위해서는 Addressable을 조금 다뤄야 함 : https://unitysquare.co.kr/growwith/unityblog/webinarView?id=272)
2. AssetBundle보다 편의성 증가(난 아직 어려움)
3. + AssetBundle의 모든 장점
Addressable 맛보기 (로컬)
1. PackageManager에서 Addressables를 다운로드 받는다
2. 폴더에 있는 Addressable항목을 체크 or AddressablesGroups에 Create버튼을 눌러준다
2 보충설명. AddressablesGroup은 Window>AssetManagerment>Addressables>Groups에 있다
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
public class AddressableStudy : MonoBehaviour
{
[SerializeField] private AssetReferenceGameObject assetReferenceGameObject;
private GameObject spawnedGameObject;
private void Update(){
if(Input.GetKeyDown(KeyCode.T)){
assetReferenceGameObject.InstantiateAsync(transform).Completed += (asyncOperation) => spawnedGameObject = asyncOperation.Result;
}
if(Input.GetKeyDown(KeyCode.U)){
assetReferenceGameObject.ReleaseInstance(spawnedGameObject);
}
}
private void AsyncOperationHandle_Completed(AsyncOperationHandle<GameObject> asyncOperationHandle){
if(asyncOperationHandle.Status == AsyncOperationStatus.Succeeded){
Instantiate(asyncOperationHandle.Result, transform);
} else {
Debug.Log("Failed to load!");
}
}
}
3. Canvas에 다음과 같은 스크립트를 넣어준다
4. 드래그해서 넣어준다
5. 빌드한다 (player빌드시 addressable빌드 자동으로 하겠냐 하는 안내판 나올껀데 자동ok 해준다)
6. 로드시와 언로드시 메모리 차이를 느껴본다
Addressable 맛보기 (원격)
일단 개인서버에 HTTP를 연 뒤에 번들을 올려서 하는 방법으로 할 것이다
ex) AWS의 S3로 하는 것은 구글링하면 바로 나온다
1. Addressable의 에셋세팅과 그룹을 Remote로 해준다
2. Group에서 Addressable을 빌드해준다
3. 빌드된 bundle은 유니티프로젝트>ServerData>StandaloneWindows64 폴더에 있다
5. 서버에 번들 파일을 올린다
6. 서버에 올라간 번들이 잘 받아지는지 테스트를 위해 PlayMode를 변경한다
7. 어 왜안되?
8. 맞다 리모트 경로 바꿔주고 HTTP 허용해주고 다시 재빌드하면 된다
9. 실행 잘 해봤으면 이제 windows로 player 빌드한다
10. 20MB 사진이 압축되어 5MB가 된것 같다 약 5정도의 차이
11. 실행 잘 된다
12. 이미지 바꿔서 수정도 해본다
13. 재빌드 안해도 원격으로 다운 받아서 잘 되는걸 볼 수 있다
참고자료
https://www.youtube.com/watch?v=3f2XjEGDZ2s
https://devshovelinglife.tistory.com/398
https://www.youtube.com/watch?v=wEuFAA-Ktwc