Resources.검증 BestPractices 로드 (1, 로드 및 제거)
Unity 2018.3.5f1
https://unity3d.com/jp/learn/tutorials/topics/best-practices/resources-folder
Unity 공식 강좌 요약
가장 좋은 방법을 사용하지 마라
메모리 관리 어려움
• 자산 관리의 어려움
• 배송 기능 저하
• 빠른 프로토타입 제작은 좋지만 제품판에서는 제외
/리소스 폴더 아래의 Asset이 정렬됨
다음에는 편하게 사용할 수 있어요.
・ 프로젝트의 존속기간은 일반적으로 필요하다
메모리 집약형 아님
• 패치하는 경향이 없거나 플랫폼과 장치 간에 차이가 없음
최소 부트
무엇보다도 좋다
가장 좋은 방법을 사용하지 마라
무슨 뜻이야?
간단하게 아래의 원본 코드를 써서 검증하였다
ResourcesLoader.cs
using System.Collections;
using UnityEngine;
public class ResourcesLoader : MonoBehaviour
{
protected System.Type LoadObjectType;
[SerializeField, Header("ResourcesLoadのPathを指定")]
private string ResourcesLoadPath;
private UnityEngine.Object Asset;
private void Awake()
{
SetLoadObjectType();
}
private IEnumerator Start()
{
var request = Resources.LoadAsync(ResourcesLoadPath, LoadObjectType);
yield return request;
Asset = request.asset;
OnLoadComplete(Asset);
}
private void OnDestroy()
{
if (Asset != null)
{
Resources.UnloadAsset(Asset);
Asset = null;
}
}
protected virtual void SetLoadObjectType()
{
LoadObjectType = typeof(Object);
}
protected virtual void OnLoadComplete(Object _object)
{
;
}
}
대체로 어떤 행동일까1. GameObject 생성 후 리소스 LoadPath에 설정된 Path에서 리소스를 비동기적으로 읽기
2. 로드가 완료되면 OnLoadComplete가 호출됩니다.
3. GameObject가 삭제된 후 Resources.UnloadAsset 호출
검증하기 전에 카메라만 있는 Scene에서 Asset이 어떤지.
Profiler에서 Detailed 디스플레이에서 Memory 항목을 Asset의 Sample에서 가져옵니다.

AddComponent, test를 위해 GameObject를 적절히 제작합니다.png을 읽는 것은

Prefab, Transform, MonoBehaviour 등이 증가하지만 Load와 관련된 것만 열기
그리고 Game Object를 삭제하면...

Sprite 정보를 이미지 데이터 로드에서 해제하지 않음
무늬 주체만 방출된 것 같습니다.
소스 코드에서 리소스의 Asset을 읽고 삭제했기 때문에 관련된 것은
끄려고 했는데 완전히 끄면 안 될 것 같아.
계속하다
Reference
이 문제에 관하여(Resources.검증 BestPractices 로드 (1, 로드 및 제거)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/tessa256/items/05bec7892657b2afa9d0텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)