private IEnumerator AddAssetBundle(string bundleUrl, AssetExistStatusEnum bundelExistStatus) { WWW www = new WWW(@"file://" + bundleUrl); while (!www.isDone) { yield return(new WaitForFixedUpdate()); } if (string.IsNullOrEmpty(www.error) && www.assetBundle != null) { AssetBundle bundle = www.assetBundle; AssetBundleStateObj assetStateObj = new AssetBundleStateObj(); assetStateObj.bundelExistStatus = bundelExistStatus; assetStateObj.bundlePath = bundleUrl; UnityEngine.Object[] data = bundle.LoadAllAssets(); for (int i = 0; i < data.Length; i++) { LibaryStateObj libaryObj = new LibaryStateObj(); libaryObj.m_Name = data[i].name; libaryObj.m_Status = LibaryStatusEnum.DIR_ASSETBUNDER; libaryObj.m_Type = data[i].GetType().Name; libaryObj.m_Path = bundleUrl; if (UpdateAssetCallback != null) { UpdateAssetCallback(libaryObj); } //ResLibaryMgr.Instance.UpdateLibary(libaryObj); } if (bundelExistStatus == AssetExistStatusEnum.Globle) { assetStateObj.bundleAsset = bundle; } else { bundle.Unload(false); Resources.UnloadUnusedAssets(); } } www.Dispose(); yield return(1); }
public void UpdateLibary(string localUrl, AssetExistStatusEnum assetStatus = AssetExistStatusEnum.Quote) { FileInfo file = new FileInfo(localUrl); if (file.Exists) { string existension = file.Extension; FileStateObj fileObj = null; if (ResLibaryConfig.ResourceTxtExts.Contains(existension)) { fileObj = new FileStateObj(); fileObj.m_Path = localUrl; fileObj.m_Type = ResLibaryConfig.ExistType[LibaryTypeEnum.LibaryType_TextAsset]; if (assetStatus == AssetExistStatusEnum.Globle) { fileObj.m_Asset = ResLibaryTool.LoadFileStr(localUrl); } } else if (ResLibaryConfig.ResourceImgExts.Contains(existension)) { fileObj = new FileStateObj(); fileObj.m_Path = localUrl; fileObj.m_Type = ResLibaryConfig.ExistType[LibaryTypeEnum.LibaryType_Texture2D]; FileStateObj sfObj = new FileStateObj(); sfObj.m_Path = localUrl; sfObj.m_Type = ResLibaryConfig.ExistType[LibaryTypeEnum.LibaryType_Sprite]; if (assetStatus == AssetExistStatusEnum.Globle) { Texture2D tex2d = ResLibaryTool.readLocalTexture2d(localUrl); fileObj.m_Asset = tex2d; sfObj.m_Asset = Sprite.Create(tex2d, new Rect(0, 0, tex2d.width, tex2d.height), Vector2.zero); } string fullFileName = System.IO.Path.GetFileName(localUrl); //int position = fullFileName.LastIndexOf("."); string fileName = System.IO.Path.GetFileNameWithoutExtension(localUrl);//fullFileName.Substring(0, position - 1); sfObj.m_Name = fileName; if (!resourceDict.ContainsKey(sfObj.m_Type)) { resourceDict[sfObj.m_Type] = new Dictionary <string, FileStateObj>(); } Dictionary <string, FileStateObj> dict = resourceDict[sfObj.m_Type]; dict[sfObj.m_Name] = sfObj; LibaryStateObj libaryObj = new LibaryStateObj(); libaryObj.m_Name = sfObj.m_Name; libaryObj.m_Status = LibaryStatusEnum.DIR_FILE; libaryObj.m_Type = sfObj.m_Type; libaryObj.m_Path = localUrl; if (UpdateAssetCallback != null) { UpdateAssetCallback(libaryObj); } //ResLibaryMgr.Instance.UpdateLibary(libaryObj); } else if (ResLibaryConfig.ResourceVideoExts.Contains(existension)) { fileObj = new FileStateObj(); fileObj.m_Path = localUrl; fileObj.m_Type = ResLibaryConfig.ExistType[LibaryTypeEnum.LibaryType_VideoClip]; fileObj.m_Asset = localUrl; } else if (ResLibaryConfig.ResourceAudioExts.Contains(existension)) { fileObj = new FileStateObj(); fileObj.m_Path = localUrl; fileObj.m_Type = ResLibaryConfig.ExistType[LibaryTypeEnum.LibaryType_AudioClip]; fileObj.m_Asset = localUrl; } if (fileObj != null) { string fullFileName = System.IO.Path.GetFileName(localUrl); //int position = fullFileName.LastIndexOf("."); string fileName = System.IO.Path.GetFileNameWithoutExtension(localUrl);//fullFileName.Substring(0, position - 1); fileObj.m_Name = fileName; if (!resourceDict.ContainsKey(fileObj.m_Type)) { resourceDict[fileObj.m_Type] = new Dictionary <string, FileStateObj>(); } Dictionary <string, FileStateObj> dict = resourceDict[fileObj.m_Type]; dict[fileObj.m_Name] = fileObj; LibaryStateObj libaryObj = new LibaryStateObj(); libaryObj.m_Name = fileObj.m_Name; libaryObj.m_Status = LibaryStatusEnum.DIR_FILE; libaryObj.m_Type = fileObj.m_Type; libaryObj.m_Path = localUrl; if (UpdateAssetCallback != null) { UpdateAssetCallback(libaryObj); } //ResLibaryMgr.Instance.UpdateLibary(libaryObj); } } }
public void UpdateAssetBundle(string bundleUrl, AssetExistStatusEnum bundelExistStatus = AssetExistStatusEnum.Scene) { ResLibaryTool.UTStartCoroutine(AddAssetBundle(bundleUrl, bundelExistStatus)); }