찾기
내용으로 건너뛰기
추적
문서의 이전 판을 선택했습니다!
저장하면 이 자료로 새 판을 만듭니다.
미디어 파일
=====Keeping Track of loaded AssetBundles===== Unity will only allow you to have a single instance of a particular AssetBundle loaded at one time in your application. What this means is that you cant retrieve an AssetBundle from a WWW object if the same one has been loaded previously and has not been unloaded. In practical terms it means that when you try to access a previously loaded AssetBundle like this: <file csharp>AssetBundle bundle = www.assetBundle;</file> the following error will be thrown <file csharp>Cannot load cached AssetBundle. A file of the same name is already loaded from another AssetBundle</file> and the assetBundle property will return null. Since you cant retrieve the AssetBundle during the second download if the first one is still loaded, what you need to do is to either //unload// the AssetBundle when you are no longer using it, or maintain a reference to it and avoid downloading it if it is already in memory. You can decide the right course of action based on your needs, but our recommendation is that you //unload// the AssetBundle as soon as you are done loading objects. This will free the memory and you will no longer get an error about loading cached AssetBundles. If you do want to keep track of which AssetBundles you have downloaded, you could use a wrapper class to help you manage your downloads like the following: <file csharp>using UnityEngine; using System; using System.Collections; using System.Collections.Generic; static public class AssetBundleManager { // A dictionary to hold the AssetBundle references static private Dictionary<string, AssetBundleRef> dictAssetBundleRefs; static AssetBundleManager (){ dictAssetBundleRefs = new Dictionary<string, AssetBundleRef>(); } // Class with the AssetBundle reference, url and version private class AssetBundleRef { public AssetBundle assetBundle = null; public int version; public string url; public AssetBundleRef(string strUrlIn, int intVersionIn) { url = strUrlIn; version = intVersionIn; } }; // Get an AssetBundle public static AssetBundle getAssetBundle (string url, int version){ string keyName = url + version.ToString(); AssetBundleRef abRef; if (dictAssetBundleRefs.TryGetValue(keyName, out abRef)) return abRef.assetBundle; else return null; } // Download an AssetBundle public static IEnumerator downloadAssetBundle (string url, int version){ string keyName = url + version.ToString(); if (dictAssetBundleRefs.ContainsKey(keyName)) yield return null; else { using(WWW www = WWW.LoadFromCacheOrDownload (url, version)){ yield return www; if (www.error != null) throw new Exception("WWW download:" + www.error); AssetBundleRef abRef = new AssetBundleRef (url, version); abRef.assetBundle = www.assetBundle; dictAssetBundleRefs.Add (keyName, abRef); } } } // Unload an AssetBundle public static void Unload (string url, int version, bool allObjects){ string keyName = url + version.ToString(); AssetBundleRef abRef; if (dictAssetBundleRefs.TryGetValue(keyName, out abRef)){ abRef.assetBundle.Unload (allObjects); abRef.assetBundle = null; dictAssetBundleRefs.Remove(keyName); } } }</file> An example usage of the class would be: <file csharp>using UnityEditor; class ManagedAssetBundleExample : MonoBehaviour { public string url; public int version; AssetBundle bundle; void OnGUI (){ if (GUILayout.Label ("Download bundle"){ bundle = AssetBundleManager.getAssetBundle (url, version); if(!bundle) StartCoroutine (DownloadAB()); } } IEnumerator DownloadAB (){ yield return StartCoroutine(AssetBundleManager.downloadAssetBundle (url, version)); bundle = AssetBundleManager.getAssetBundle (url, version); } void OnDisable (){ AssetBundleManager.Unload (url, version); } }</file> Please bear in mind, that the AssetBundleManager class in this example is static, and any AssetBundles that you are referencing will not be destroyed when loading a new scene. Use this class as a guide but as recommended initially it is best if you //unload// AssetBundles right after they have been used. You can always clone a previously Instantiated object, removing the need to load the AssetBundles again. [[AssetBundlesIntro|back to AssetBundles Intro]] {{tag>유니티 unity}} * 출처: [[http://unitykoreawiki.com/index.php?n=KrMain.keepingtrackofloadedassetbundles|유니티코리아위키]] (CC BY-NC-SA 2.0)
2+1?
이 필드는 비어 있도록 유지하세요:
저장
미리 보기
취소
편집 요약
참고: 이 문서를 편집하면 내용은 다음 라이선스에 따라 배포하는 데 동의하는 것으로 간주합니다:
CC Attribution-Noncommercial-Share Alike 4.0 International
연결문서
AssetBundles (Pro only)
유니티3D ( Unity3D )
문서 도구
문서 보기
이전 판
연결문서
맨 위로
다크 모드로 보기
☀️
Toggle Menu
유니티3D ( Unity3D )
너두 고쳐두 됩니다.
사이트 도구
최근 바뀜
미디어 관리자
사이트맵
사용자 도구
등록
로긴
최근 수정된 문서
timed_intercourse
[매일?]
ovulation_induction
menopause
[검사]
male_factor
[Male Factor]
infertility
ivf
[시술과정]
amh
prolactin
putty
venv
[macOS / Linux (bash/zsh 등)]
postgresql
bitvise_ssh_client
screen
허니미
만듦
고위험_산모
the_siren_s_deception
[그웨덴 농장]
wegovy
[운동 루틴 (주 4~5회 권장)]