简体   繁体   English

无法加载,因为已经加载了另一个具有相同文件的AssetBundle

[英]Can't be loaded because another AssetBundle with the same files is already loaded

I want to play the video in AR camera. 我想在AR相机中播放视频。 Totally I have 10 videos and one videoplayer. 我总共有10个视频和一个视频播放器。 And I am downloading the video player from the server as an asset bundle with name videoplayer.unit3d and storing into sd card. 我正在从服务器下载视频播放器作为资产捆绑,名称为videoplayer.unit3d并存储到sd卡中。 when I am scanning the imageTarget I am reading the video asset bundle file using AssetBundle.LoadFromFile() function and for the first time its working fine. 当我扫描imageTarget时,我正在使用AssetBundle.LoadFromFile()函数读取视频资产捆绑文件,并且第一次可以正常工作。

If I scan the second imageTarget it is showing following error 如果我扫描第二个imageTarget它显示以下错误

"Can't be loaded because another AssetBundle with the same files is already loaded" “无法加载,因为已经加载了另一个具有相同文件的AssetBundle”

I have tried a bundle.Unload(true); 我已经试过bundle.Unload(true); and Caching.cleanchache() but its not working throwing same error. Caching.cleanchache()但无法正常工作并抛出相同的错误。 Also tried bundle.Unload(false); 还尝试了bundle.Unload(false);

  private void loadObject(string resourcePath, string objectName, TrackableBehaviour trackableBehaviuor, string videoUrl) { Debug.Log("Resource path " + resourcePath + " objectName " + objectName); Debug.Log("Video Url from sd card " + videoUrl); FileInfo fileInfo = new FileInfo(resourcePath); if (!fileInfo.Exists) return; Debug.Log("File is present"); AssetBundle bundle = AssetBundle.LoadFromFile(resourcePath, 0, 0);//www.assetBundle; Debug.Log("Bundle data is " + bundle); if (bundle == null) { AndroidJavaObject jObject = new AndroidJavaObject("com.ezvidya.buzzle.activity.UnityActivity"); jObject.Call("showErrorDialog"); return; } else { AndroidJavaObject jo = new AndroidJavaObject("com.ezvidya.buzzle.activity.UnityActivity"); jo.Call("closeScanDialog"); } //Load an asset from the loaded bundle AssetBundleRequest bundleRequest = bundle.LoadAssetAsync(objectName, typeof(GameObject)); //bundle.Unload(false); Caching.CleanCache(); //get object GameObject cubeFromSDCard = bundleRequest.asset as GameObject; if (cubeFromSDCard != null) { // instantiate augmentation object and parent to trackable GameObject augmentation = (GameObject)GameObject.Instantiate(cubeFromSDCard); augmentation.transform.parent = trackableBehaviuor.gameObject.transform; augmentation.transform.localPosition = cubeFromSDCard.transform.localPosition;//new Vector3(0f, 0f, 0f); augmentation.transform.localRotation = cubeFromSDCard.transform.localRotation;//Quaternion.identity; augmentation.transform.localEulerAngles = cubeFromSDCard.transform.localEulerAngles; augmentation.transform.localScale = cubeFromSDCard.transform.localScale;// new Vector3(22f, 22f, 22f); Debug.Log("$$$$$$$$$$$$$$$$ Local Position from asset object " + cubeFromSDCard.transform.localPosition); Debug.Log("$$$$$$$$$$$$$$$$ Local Rotation from asset object " + cubeFromSDCard.transform.localEulerAngles); Debug.Log("$$$$$$$$$$$$$$$$ Local Scale from asset object " + cubeFromSDCard.transform.localScale); Debug.Log("$$$$$$$$$$$$$$$$ Position from asset object " + cubeFromSDCard.transform.position); Debug.Log("$$$$$$$$$$$$$$$$ Rotation from asset object " + cubeFromSDCard.transform.eulerAngles); Debug.Log("$$$$$$$$$$$$$$$$ Scale from asset object " + cubeFromSDCard.transform.lossyScale); // Caching.CleanCache(); if (videoUrl != null && videoUrl.Length > 0) { VideoPlaybackBehaviour video = augmentation.GetComponent<VideoPlaybackBehaviour>(); video.m_autoPlay = true; Debug.Log("Autoplay is " + video.AutoPlay); video.m_path = videoUrl; // Pause other videos before playing this one // Play this video on texture where it left off //OnTrackingFound(false); if (video != null && video.AutoPlay) { VideoPlayerHelper.MediaState state = video.VideoPlayer.GetStatus(); if (state == VideoPlayerHelper.MediaState.PAUSED || state == VideoPlayerHelper.MediaState.READY || state == VideoPlayerHelper.MediaState.STOPPED) { // Pause other videos before playing this one PauseOtherVideos(video); // Play this video on texture where it left off video.VideoPlayer.Play(false, 0); } else if (state == VideoPlayerHelper.MediaState.REACHED_END) { // Pause other videos before playing this one PauseOtherVideos(video); // Play this video from the beginning video.VideoPlayer.Play(false, 0); } } } augmentation.gameObject.SetActive(true); } //bundle.Unload(false); } 

I have found the answer, After Instantiate the Gameobject just call bundle.Unload(false); 我找到了答案, Instantiate Gameobject之后,只需调用bundle.Unload(false); it solved my problem. 它解决了我的问题。

I have resolved this problem using add below two lines, 我使用两行下面的添加解决了这个问题,

private AssetBundle myLoadedAssetBundle;
string bundleUrl="";
IEnumerator LoadAssetBundle ()
{
    if (myLoadedAssetBundle != null) {
        myLoadedAssetBundle.Unload(false); //scene is unload from here
    }

    while (!Caching.ready)
        yield return null;

    WWW www = WWW.LoadFromCacheOrDownload(bundleUrl, 1);
    yield return www;

    if (!string.IsNullOrEmpty(www.error))
    {
        Debug.Log(www.error);
        yield return null;
    }
    myLoadedAssetBundle = www.assetBundle;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法加载,因为已经加载了另一个具有相同文件的 AssetBundle。 加载不同包时出错 - can't be loaded because another AssetBundle with the same files is already loaded. error while loading different bundles 无法加载缓存的AssetBundle。 已经从另一个AssetBundle加载了同名文件 - Cannot load cached AssetBundle. A file of the same name is already loaded from another AssetBundle C#找不到已加载的程序集 - C# can't find assembly which is already loaded 无法加载LoadStateEventArgs - LoadStateEventArgs can't loaded 无法引用在不同脚本中作为组件加载到游戏对象上的脚本,该脚本也作为组件加载到同一游戏对象上 - Can't reference a script that is loaded as a component on a GameObject in a different script that is also loaded as a component on same GameObject 实例化游戏 object 从 assetbundle 加载 lost animation clip - Instantiate game object loaded from assetbundle lost animation clip 如何在没有错误的情况下加载我的场景 [场景尚未添加到构建设置或 AssetBundle 尚未加载] - how can I load my scenes without the error [scene has not been added to the build settings or the AssetBundle has not been loaded] “附加类型为T的实体失败,因为同一类型的另一个实体已经具有相同的主键值” - “Attaching an entity of type T failed because another entity of the same type already has the same primary key value” 即使已经动态加载了MVC登录页面,也找不到DLL - MVC login page can't find a DLL even though it is already been dynamically loaded 防止.load()如果已经加载? - Preventing .load() if already loaded?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM