public static void ImportAllJSONInDirectoryToGraphFromDialog() { var folderSelected = EditorUtility.OpenFolderPanel("Select folder contains JSON files to import", Application.dataPath + "..", ""); if (string.IsNullOrEmpty(folderSelected)) { return; } var newAssetFolder = CreateFolderForImportedAssets(); var filePaths = FileUtility.GetAllFilePathsInFolder(folderSelected); foreach (var path in filePaths) { var ext = Path.GetExtension(path).ToLower(); if (ext != ".json") { continue; } var jsonContent = File.ReadAllText(path, System.Text.Encoding.UTF8); var name = Path.GetFileNameWithoutExtension(path); var graph = ScriptableObject.CreateInstance <Model.ConfigGraph>(); EditorJsonUtility.FromJsonOverwrite(jsonContent, graph); var graphPath = FileUtility.PathCombine(newAssetFolder, string.Format("{0}.asset", name)); AssetDatabase.CreateAsset(graph, graphPath); } }
public static string FindSettingTemplateFileGUID(Type importerType) { var fileName = GetSettingTemplateFileName(importerType); if (string.IsNullOrEmpty(fileName)) { return(null); } var guids = AssetDatabase.FindAssets(Model.Settings.SETTING_TEMPLATE_DIR_SEARCH_CONDITION); foreach (var guid in guids) { string templateDirPath = AssetDatabase.GUIDToAssetPath(guid); var files = FileUtility.GetAllFilePathsInFolder(templateDirPath); var settingFilePath = files.Find(f => System.IO.Path.GetFileName(f) == fileName); if (!string.IsNullOrEmpty(settingFilePath)) { return(AssetDatabase.AssetPathToGUID(settingFilePath)); } } return(null); }
private void Mirror(BuildTarget target, Model.NodeData node, IEnumerable <PerformGraph.AssetGroups> incoming, IEnumerable <Model.ConnectionData> connectionsToOutput, Action <Model.NodeData, string, float> progressFunc) { try { var srcDir = GetNormalizedPath(m_srcPath[target]); var dstDir = GetNormalizedPath(m_dstPath[target]); if (Directory.Exists(dstDir)) { if (m_mirrorOption[target] == (int)MirrorOption.AlwaysRecreateDestination) { FileUtility.DeleteDirectory(dstDir, true); } else if (m_mirrorOption[target] == (int)MirrorOption.KeepAlreadyCopiedFiles) { var dstFilePaths = FileUtility.GetAllFilePathsInFolder(dstDir); // checking destination files - remove files if not exist in source foreach (var dstPath in dstFilePaths) { var srcPath = dstPath.Replace(dstDir, srcDir); if (!File.Exists(srcPath)) { File.Delete(dstPath); } } } } var targetFilePaths = FileUtility.GetAllFilePathsInFolder(srcDir); int i = 0; foreach (var srcPath in targetFilePaths) { var dstPath = srcPath.Replace(srcDir, dstDir); var dstParentDir = Directory.GetParent(dstPath); if (!dstParentDir.Exists) { var dirPath = dstParentDir.ToString(); Directory.CreateDirectory(dirPath); } var srcInfo = new FileInfo(srcPath); var dstInfo = new FileInfo(dstPath); if (!dstInfo.Exists || srcInfo.LastWriteTimeUtc > dstInfo.LastWriteTimeUtc) { File.Copy(srcPath, dstPath, true); progressFunc(node, string.Format("Copying {0}", Path.GetFileName(srcPath)), (float)(i++) / (float)targetFilePaths.Count); } } } catch (Exception e) { throw new NodeException(node.Name + ":" + e.Message, node); } }
public override void Build(BuildTarget target, Model.NodeData node, IEnumerable <PerformGraph.AssetGroups> incoming, IEnumerable <Model.ConnectionData> connectionsToOutput, PerformGraph.Output Output, Action <Model.NodeData, string, float> progressFunc) { var importPath = GetImportDirectoryPath(m_importDirectoryPath[target]); var isRecursive = m_isRecursive[target] != 0; var isInteractive = m_isInteractive[target] != 0; var files = isRecursive ? FileUtility.GetAllFilePathsInFolder(importPath) : FileUtility.GetFilePathsInFolder(importPath); foreach (var packagePath in files.Where(p => p.EndsWith(".unitypackage"))) { AssetDatabase.ImportPackage(packagePath, isInteractive); } }
public override void Build(BuildTarget target, Model.NodeData node, IEnumerable <PerformGraph.AssetGroups> incoming, IEnumerable <Model.ConnectionData> connectionsToOutput, PerformGraph.Output Output, Action <Model.NodeData, string, float> progressFunc) { if (incoming == null) { return; } var aggregatedGroups = new Dictionary <string, List <AssetReference> >(); aggregatedGroups[key] = new List <AssetReference>(); if (progressFunc != null) { progressFunc(node, "Collecting all inputs...", 0f); } foreach (var ag in incoming) { foreach (var name in ag.assetGroups.Keys) { if (!aggregatedGroups.ContainsKey(name)) { aggregatedGroups[name] = new List <AssetReference>(); } aggregatedGroups[name].AddRange(ag.assetGroups[name].AsEnumerable()); } } var bundleOutputDir = PrepareOutputDirectory(target, node, true, true); var bundleNames = aggregatedGroups.Keys.ToList(); var bundleVariants = new Dictionary <string, List <string> >(); if (progressFunc != null) { progressFunc(node, "Building bundle variants map...", 0.2f); } // get all variant name for bundles foreach (var name in aggregatedGroups.Keys) { if (!bundleVariants.ContainsKey(name)) { bundleVariants[name] = new List <string>(); } var assets = aggregatedGroups[name]; foreach (var a in assets) { var variantName = a.variantName; if (!bundleVariants[name].Contains(variantName)) { bundleVariants[name].Add(variantName); } } } int validNames = 0; foreach (var name in bundleNames) { var assets = aggregatedGroups[name]; // we do not build bundle without any asset if (assets.Count > 0) { validNames += bundleVariants[name].Count; } } AssetBundleBuild[] bundleBuild = new AssetBundleBuild[validNames]; List <AssetImporterSetting> importerSetting = null; if (!m_overwriteImporterSetting) { importerSetting = new List <AssetImporterSetting> (); } int bbIndex = 0; foreach (var name in bundleNames) { foreach (var v in bundleVariants[name]) { var assets = aggregatedGroups[name]; if (assets.Count <= 0) { continue; } bundleBuild[bbIndex].assetBundleName = name; bundleBuild[bbIndex].assetBundleVariant = v; bundleBuild[bbIndex].assetNames = assets.Where(x => x.variantName == v).Select(x => x.importFrom).ToArray(); /** * WORKAROND: This will be unnecessary in future version * Unity currently have issue in configuring variant assets using AssetBundleBuild[] that * internal identifier does not match properly unless you configure value in AssetImporter. */ if (!string.IsNullOrEmpty(v)) { foreach (var path in bundleBuild[bbIndex].assetNames) { AssetImporter importer = AssetImporter.GetAtPath(path); if (importer.assetBundleName != name || importer.assetBundleVariant != v) { if (!m_overwriteImporterSetting) { importerSetting.Add(new AssetImporterSetting(importer)); } importer.SetAssetBundleNameAndVariant(name, v); importer.SaveAndReimport(); } } } ++bbIndex; } } if (progressFunc != null) { progressFunc(node, "Building Asset Bundles...", 0.7f); } AssetBundleManifest m = BuildPipeline.BuildAssetBundles(bundleOutputDir, bundleBuild, (BuildAssetBundleOptions)m_enabledBundleOptions[target], target); var output = new Dictionary <string, List <AssetReference> >(); output[key] = new List <AssetReference>(); var manifestName = GetManifestName(target, node, false); if (!string.IsNullOrEmpty(m_manifestName [target])) { var projectPath = Directory.GetParent(Application.dataPath).ToString(); var finalManifestName = GetManifestName(target, node, true); if (finalManifestName != manifestName) { var from = FileUtility.PathCombine(projectPath, bundleOutputDir, manifestName); var to = FileUtility.PathCombine(projectPath, bundleOutputDir, finalManifestName); var fromPaths = new string[] { from, from + ".manifest" }; var toPaths = new string[] { to, to + ".manifest" }; for (var i = 0; i < fromPaths.Length; ++i) { if (File.Exists(toPaths[i])) { File.Delete(toPaths[i]); } if (File.Exists(fromPaths[i])) { File.Move(fromPaths[i], toPaths[i]); } else { Debug.LogError("File " + fromPaths[i] + " does not exists! Wanted to copy to " + toPaths[i]); } } manifestName = finalManifestName; } } var generatedFiles = FileUtility.GetAllFilePathsInFolder(bundleOutputDir); // add manifest file bundleVariants.Add(manifestName.ToLower(), new List <string> { null }); foreach (var path in generatedFiles) { var fileName = path.Substring(bundleOutputDir.Length + 1); if (IsFileIntendedItem(fileName, bundleVariants)) { if (fileName == manifestName) { output[key].Add(AssetReferenceDatabase.GetAssetBundleManifestReference(path)); } else { output[key].Add(AssetReferenceDatabase.GetAssetBundleReference(path)); } } } if (Output != null) { var dst = (connectionsToOutput == null || !connectionsToOutput.Any())? null : connectionsToOutput.First(); Output(dst, output); } if (importerSetting != null) { importerSetting.ForEach(i => i.WriteBack()); } AssetBundleBuildReport.AddBuildReport(new AssetBundleBuildReport(node, m, manifestName, bundleBuild, output[key], aggregatedGroups, bundleVariants)); }