public IEnumerator TestYeildLoadAssetBundle() { string bundleName = "prefabs/myprefab"; BundleLoaderEnumerator bundleLoaderEnumerator = m_AssetManager.YieldLoadAssetBundle(bundleName, false); yield return(bundleLoaderEnumerator); AssetBundleReference result = bundleLoaderEnumerator.assetBundleReference; Assert.AreNotEqual(result, null); #if ASSETMANAGE_BUNDLE_CACHE_ON //check file Exists string filepath = AssetPaths.FullPathForFilename(bundleName); Assert.AreEqual(System.IO.File.Exists(filepath), true); //check cache info RequestManager rm = m_AssetManager.requestManager as RequestManager; if (rm != null && rm.cacheManager != null) { Assert.AreNotEqual(rm.cacheManager.cacheItems, null); CacheItem cacheItem = null; if (rm.cacheManager.cacheItems.TryGetValue(bundleName, out cacheItem)) { Assert.AreEqual(string.IsNullOrEmpty(cacheItem.hash), false); } else { Assert.Fail("Can't find cache item " + bundleName); } } #endif bundleLoaderEnumerator.Dispose(); }
public IFileInfo GetFileInfo(string subpath) { if (!_fileInfos.TryGetValue(subpath, out var fileInfo)) { if (!AssetPaths.Contains(Root + subpath, StringComparer.Ordinal)) { return(new NotFoundFileInfo(subpath)); } lock (_fileInfos) { if (!_fileInfos.TryGetValue(subpath, out fileInfo)) { var resourcePath = _baseNamespace + subpath.Replace('/', '>'); var fileName = Path.GetFileName(subpath); if (Assembly.GetManifestResourceInfo(resourcePath) == null) { return(new NotFoundFileInfo(fileName)); } _fileInfos[subpath] = fileInfo = new EmbeddedResourceFileInfo( Assembly, resourcePath, fileName, _lastModified); } } } return(fileInfo); }
// Load icon from Info.IconFileName, add it to AssetPaths private void ImportIcon() { bool hasIconFileName = !string.IsNullOrEmpty(Info.IconFileName); if (hasIconFileName || layerAutomaticIcon != null) { /* Note: At one point I tried to optimize it, by detecting when * icon is already in the assets * ( Info.IconFileName.StartsWith(Application.dataPath) ) * and then just adding the existing asset-relative path to AssetPaths. * * But it doesn't work: we need the file to be called "icon.asset" * ("icon.png" is ignored by Unity bundle building, as it has unrecognized * extension). So we need to read + write the file anyway. */ Texture2D texture; if (hasIconFileName) { byte[] data = File.ReadAllBytes(Info.IconFileName); texture = new Texture2D(1, 1); texture.LoadImage(data); } else { texture = layerAutomaticIcon; } string iconAssetPath = AssetDirs.TempAssetsDir + "/icon.asset"; AssetDatabase.CreateAsset(texture, iconAssetPath); AssetPaths.Add(iconAssetPath); } }
// Exports finished GameObject to a .prefab private void CreatePrefab(ModelLayerInfo layerInfo, GameObject modelGameObject, string objectName) { string rootAssetsDir = AssetDirs.TempAssetsDir + "/" + Info.Caption; AssetDirs.CreateAssetDirectory(rootAssetsDir); string prefabPath = rootAssetsDir + "/" + objectName + ".prefab"; AssetPaths.Add(prefabPath); PrefabUtility.SaveAsPrefabAsset(modelGameObject, prefabPath); }
public IEnumerator TestLoadAssetBundle() { string bundleName = "prefabs/myprefab"; AssetBundleReference result = null; bool isDone = false; m_AssetManager.LoadAssetBundle(bundleName, false, (abr) => { isDone = true; result = abr; }); while (!isDone) { yield return(null); } Assert.AreNotEqual(result, null); #if ASSETMANAGE_BUNDLE_CACHE_ON //check file Exists string filepath = AssetPaths.FullPathForFilename(bundleName); Assert.AreEqual(System.IO.File.Exists(filepath), true); //check cache info RequestManager rm = m_AssetManager.requestManager as RequestManager; if (rm != null && rm.cacheManager != null) { Assert.AreNotEqual(rm.cacheManager.cacheItems, null); CacheItem cacheItem = null; if (rm.cacheManager.cacheItems.TryGetValue(bundleName, out cacheItem)) { Assert.AreEqual(string.IsNullOrEmpty(cacheItem.hash), false); } else { Assert.Fail("Can't find cache item " + bundleName); } } #endif }
// Saves imported model to a Unity-friendly files, to be put in AssetBundles. private void SaveFilesForExport(ModelLayerInfo layerInfo, string objectName, Mesh modelMesh, GameObject modelGameObject) { string rootAssetsDir = AssetDirs.TempAssetsDir + "/" + Info.Caption; AssetDirs.CreateAssetDirectory(rootAssetsDir); string meshPath = rootAssetsDir + "/" + objectName + ".asset"; AssetPaths.Add(meshPath); AssetDatabase.CreateAsset(modelMesh, meshPath); string gameObjectPath = rootAssetsDir + "/" + objectName + ".prefab"; AssetPaths.Add(gameObjectPath); PrefabUtility.SaveAsPrefabAsset(modelGameObject, gameObjectPath); if (layerInfo.UseAsIcon) { PrepareForPreview(modelGameObject); LayerAutomaticIconGenerate(modelGameObject); } }
// Saves imported model to a Unity-friendly files, to be put in AssetBundles. private void SaveFilesForExport(GameObject modelGameObject, ModelLayerInfo layerInfo, string objectName) { string rootAssetsDir = AssetDirs.TempAssetsDir + "/" + Info.Caption; AssetDirs.CreateAssetDirectory(rootAssetsDir); Mesh modelMesh = modelGameObject.GetComponent <MeshFilter>().mesh; string meshPath = rootAssetsDir + "/" + objectName + ".asset"; AssetPaths.Add(meshPath); AssetDatabase.CreateAsset(modelMesh, meshPath); string rawDataPath = layerInfo.Directory + @"\" + "data.raw"; // This is strange to copy data first as Asset then copy asset to build dir string tmpDataPath = rootAssetsDir + "/tmp_data.bytes"; string dataPath = rootAssetsDir + "/" + objectName + "_data.bytes"; if (File.Exists(tmpDataPath)) { FileUtil.DeleteFileOrDirectory(tmpDataPath); } FileUtil.CopyFileOrDirectory(rawDataPath, tmpDataPath); AssetPaths.Add(dataPath); AssetDatabase.Refresh(); AssetDatabase.CopyAsset(tmpDataPath, dataPath); string gameObjectPath = rootAssetsDir + "/" + objectName + ".prefab"; AssetPaths.Add(gameObjectPath); PrefabUtility.SaveAsPrefabAsset(modelGameObject, gameObjectPath); if (layerInfo.UseAsIcon) { PrepareForPreview(modelGameObject); LayerAutomaticIconGenerate(modelGameObject); } }
public void SetOptions(VFSGroupOption option) { mOption = option; GroupName = option.GroupName; foreach (var path in option.FolderPaths) { if (!path.EndsWith("/")) { string _path = path + "/"; FolderPaths.Add(_path); FolderPathsLower.Add(_path.ToLower()); } else { FolderPaths.Add(path); FolderPathsLower.Add(path.ToLower()); } } foreach (var path in option.AssetPaths) { AssetPaths.Add(path); AssetPathsLower.Add(path.ToLower()); } //忽略子目录,子目录必须是FolderPaths的子目录,这里初始化的时候过滤一下无效的配置,节省后面的运算 foreach (var path in option.IgnoreSubPath) { string _path = (path.EndsWith("/")) ? path : path + "/"; string path_lower = _path.ToLower(); foreach (var folder in FolderPathsLower) { if (VFSUtil.IsSubpath(path_lower, folder, false)) { IgnoreSubpath.Add(_path); IgnoreSubpathLower.Add(path_lower); break; } } } //忽略后缀名 foreach (var ext in option.IngnoreExtName) { IgnoreExtensionLower.Add(ext.StartsWith(".") ? ext.ToLower() : "." + ext.ToLower()); } //特殊打包规则 foreach (var rule in option.FolderSpecialBuildRules) { bool flag = true; if (rule.DevType == FolderBuildDevelopType.normal && rule.BuildType == FolderBuildType.normal) { flag = false;//这是条没必要的规则 } if (rule.FolderPath.IsNullOrEmpty() || rule.FolderPath.IsNullOrWhiteSpace()) { flag = false; } string _folder_path = (rule.FolderPath.EndsWith("/")) ? rule.FolderPath : rule.FolderPath + "/"; string _folder_lower = _folder_path.ToLower(); if (!IsSubfolderOfFolderList(_folder_path)) { flag = false; } if (flag) { var _rule = rule; _rule.FolderPath = _folder_path; var lower_rule = rule; lower_rule.FolderPath = _folder_lower; SpecialFolderBuildRules.Add(_rule); SpecialFolderBuildRulesLower.Add(lower_rule); } } }