static private PrefabBuildInfo GetPrefabBuildInfo(PrefabBuilder builder, Model.NodeData node, BuildTarget target, string groupKey) { var prefabCacheDir = FileUtility.EnsureCacheDirExists(target, node, PrefabBuilder.kCacheDirName); var buildInfoPath = FileUtility.PathCombine(prefabCacheDir, groupKey + ".asset"); return(AssetDatabase.LoadAssetAtPath <PrefabBuildInfo>(buildInfoPath)); }
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 Model.ConfigGraph ImportJSONToGraphFromDialog(Model.ConfigGraph graph) { string fileSelected = EditorUtility.OpenFilePanelWithFilters("Select JSON files to import", Application.dataPath, new string[] { "JSON files", "json", "All files", "*" }); if (string.IsNullOrEmpty(fileSelected)) { return(null); } string name = Path.GetFileNameWithoutExtension(fileSelected); var jsonContent = File.ReadAllText(fileSelected, System.Text.Encoding.UTF8); if (graph != null) { Undo.RecordObject(graph, "Import"); EditorJsonUtility.FromJsonOverwrite(jsonContent, graph); } else { graph = ScriptableObject.CreateInstance <Model.ConfigGraph>(); EditorJsonUtility.FromJsonOverwrite(jsonContent, graph); var newAssetFolder = CreateFolderForImportedAssets(); var graphPath = FileUtility.PathCombine(newAssetFolder, string.Format("{0}.asset", name)); AssetDatabase.CreateAsset(graph, graphPath); } return(graph); }
private void CreateConfigurator(Model.NodeData node, Type importerType) { var configFileGUID = ImporterConfiguratorUtility.FindSettingTemplateFileGUID(importerType); var configFilePath = AssetDatabase.GUIDToAssetPath(configFileGUID); if (string.IsNullOrEmpty(configFilePath)) { throw new NodeException(node.Name + " :Setting template file not found. Incoming file type must be properly configured with CustomImporterConfigurator.", node); } var samplingDirectoryPath = FileUtility.PathCombine(Model.Settings.Path.SavedSettingsPath, "ImportSettings", node.Id); if (!Directory.Exists(samplingDirectoryPath)) { Directory.CreateDirectory(samplingDirectoryPath); } IAssetImporterConfigurator configurator = ImporterConfiguratorUtility.CreateConfigurator(importerType); if (configurator == null) { throw new NodeException(node.Name + " :Failed to create importer configurator for " + importerType.FullName, node); } m_configuratorInstance.SetDefaultValue(configurator); var targetFilePath = FileUtility.PathCombine(samplingDirectoryPath, Path.GetFileName(configFilePath)); FileUtility.CopyFile(configFilePath, targetFilePath); AssetDatabase.Refresh(ImportAssetOptions.ImportRecursive); m_referenceAssetGuid = AssetDatabase.AssetPathToGUID(targetFilePath); m_configureImporterFor = null; }
public static string GetPathWithProjectPath(string pathUnderProjectFolder) { var assetPath = Application.dataPath; var projectPath = Directory.GetParent(assetPath).ToString(); return(FileUtility.PathCombine(projectPath, pathUnderProjectFolder)); }
public override bool OnAssetsReimported( Model.NodeData nodeData, AssetReferenceStreamManager streamManager, BuildTarget target, AssetPostprocessorContext ctx, bool isBuilding) { var samplingDirectoryPath = FileUtility.PathCombine(Model.Settings.Path.SavedSettingsPath, "ImportSettings", nodeData.Id); foreach (var importedAsset in ctx.ImportedAssets) { if (importedAsset.importFrom.StartsWith(samplingDirectoryPath)) { return(true); } // Test this later // if (m_customSettingAssetGuid != null) { // if(imported.StartsWith(AssetDatabase.GUIDToAssetPath(m_customSettingAssetGuid))) { // return true; // } // } } return(false); }
public override void Prepare(BuildTarget target, Model.NodeData node, IEnumerable <PerformGraph.AssetGroups> incoming, IEnumerable <Model.ConnectionData> connectionsToOutput, PerformGraph.Output Output) { if (incoming != null && Output != null) { var dst = (connectionsToOutput == null || !connectionsToOutput.Any())? null : connectionsToOutput.First(); var projectPath = Directory.GetParent(Application.dataPath).ToString(); foreach (var ag in incoming) { var outputDict = new Dictionary <string, List <AssetReference> >(); foreach (var key in ag.assetGroups.Keys) { var packageName = GetPackageNameForGroup(target, key); outputDict.Add(key, new List <AssetReference> { AssetReference.CreateUnityPackageReference(FileUtility.PathCombine(projectPath, packageName)) }); } Output(dst, outputDict); } } }
static private AssetGenerateInfo GetAssetGenerateInfo(AssetGenerator.GeneratorEntry entry, Model.NodeData node, BuildTarget target, AssetReference asset) { var cacheDir = FileUtility.EnsureCacheDirExists(target, node, AssetGenerator.kCacheDirName); var generateInfoDir = FileUtility.PathCombine(cacheDir, entry.m_id); var generatorInfoPath = FileUtility.PathCombine(generateInfoDir, asset.fileNameAndExtension + ".asset"); return(AssetDatabase.LoadAssetAtPath <AssetGenerateInfo>(generatorInfoPath)); }
public override void OnNodeDelete(Model.NodeData nodeData) { var savedSettingDir = FileUtility.PathCombine(Model.Settings.Path.SavedSettingsPath, "ImportSettings", nodeData.Id); if (AssetDatabase.IsValidFolder(savedSettingDir)) { FileUtility.DeleteDirectory(savedSettingDir, true); } }
public void ResetConfig(Model.NodeData node) { m_useCustomSettingAsset = false; CustomSettingAssetGuid = string.Empty; m_referenceAssetGuid = null; m_configuratorInstance = new SerializableMultiTargetInstance(); var sampleFileDir = FileUtility.PathCombine(Model.Settings.Path.SavedSettingsPath, "ImportSettings", node.Id); FileUtility.RemakeDirectory(sampleFileDir); }
public void Import(V1.NodeData v1, Model.NodeData v2) { m_loadPath = new SerializableMultiTargetString(v1.LoaderLoadPath); m_loadPathGuid = new SerializableMultiTargetString(); foreach (var v in m_loadPath.Values) { var loadPath = FileUtility.PathCombine(Model.Settings.Path.ASSETS_PATH, v.value); m_loadPathGuid [v.targetGroup] = AssetDatabase.AssetPathToGUID(loadPath); } }
public Loader(string path) { var normalizedPath = NormalizeLoadPath(path); var loadPath = FileUtility.PathCombine(Model.Settings.Path.ASSETS_PATH, normalizedPath); var guid = AssetDatabase.AssetPathToGUID(loadPath); m_loadPath = new SerializableMultiTargetString(normalizedPath); m_loadPathGuid = new SerializableMultiTargetString(guid); m_respondToAssetChange = false; }
private string GetLoadPath(BuildTarget g) { var path = m_loadPath [g]; if (string.IsNullOrEmpty(path)) { return("Assets"); } else { return(FileUtility.PathCombine(Model.Settings.Path.ASSETS_PATH, path)); } }
static public void SavePrefabBuildInfo(string buildPath, PrefabBuilder builder, Model.NodeData node, BuildTarget target, string groupKey, List <AssetReference> assets) { var prefabCacheDir = FileUtility.EnsureCacheDirExists(target, node, PrefabBuilder.kCacheDirName); var buildInfoPath = FileUtility.PathCombine(prefabCacheDir, groupKey + ".asset"); var version = PrefabBuilderUtility.GetPrefabBuilderVersion(builder.Builder.ClassName); var buildInfo = ScriptableObject.CreateInstance <PrefabBuildInfo>(); buildInfo.Initialize(buildPath, groupKey, builder.Builder.ClassName, builder.Builder[target], version, builder.Options, assets); AssetDatabase.CreateAsset(buildInfo, buildInfoPath); }
public bool GenerateAsset(AssetReference asset, string generateAssetPath) { var tex = AssetDatabase.LoadAssetAtPath <Texture2D>(asset.importFrom); if (tex == null) { return(false); } Texture2D output = null; switch (m_filterType) { case TextureFilterType.Bilinear: output = CreateScaledTextureBL(tex); break; case TextureFilterType.Point: output = CreateScaledTexturePT(tex); break; } Resources.UnloadAsset(tex); // Encode texture into the EXR byte[] bytes = null; switch (m_outputType) { case TextureOutputType.JPG: bytes = output.EncodeToJPG(); break; case TextureOutputType.PNG: bytes = output.EncodeToPNG(); break; #if UNITY_5_6_OR_NEWER case TextureOutputType.EXR: bytes = output.EncodeToEXR(m_exrFlags); break; #endif } string fullPath = FileUtility.PathCombine(Directory.GetParent(Application.dataPath).ToString(), generateAssetPath); File.WriteAllBytes(fullPath, bytes); Object.DestroyImmediate(output); return(true); }
public static string EnsureCacheDirExists(BuildTarget t, Model.NodeData node, string name) { var cacheDir = FileUtility.PathCombine(Model.Settings.Path.CachePath, name, node.Id, SystemDataUtility.GetPathSafeTargetName(t)); if (!Directory.Exists(cacheDir)) { Directory.CreateDirectory(cacheDir); } if (!cacheDir.EndsWith(Model.Settings.UNITY_FOLDER_SEPARATOR.ToString())) { cacheDir = cacheDir + Model.Settings.UNITY_FOLDER_SEPARATOR.ToString(); } return(cacheDir); }
public bool GenerateAsset(AssetReference asset, string generateAssetPath) { bool generated = false; try { string fullPath = FileUtility.PathCombine(Directory.GetParent(Application.dataPath).ToString(), generateAssetPath); File.Copy(asset.absolutePath, fullPath, true); generated = true; } catch (Exception e) { LogUtility.Logger.LogError("Duplicator", e.Message); } return(generated); }
public static string EnsureAssetBundleCacheDirExists(BuildTarget t, Model.NodeData node, bool remake = false) { var cacheDir = FileUtility.PathCombine(Model.Settings.Path.BundleBuilderCachePath, node.Id, BuildTargetUtility.TargetToAssetBundlePlatformName(t)); if (!Directory.Exists(cacheDir)) { Directory.CreateDirectory(cacheDir); } else { if (remake) { RemakeDirectory(cacheDir); } } return(cacheDir); }
private static void CreateCUITool() { var appPath = EditorApplication.applicationPath.Replace(Model.Settings.UNITY_FOLDER_SEPARATOR, Path.DirectorySeparatorChar); var appCmd = string.Format("{0}{1}", appPath, (Application.platform == RuntimePlatform.WindowsEditor) ? "" : "/Contents/MacOS/Unity"); var argPass = (Application.platform == RuntimePlatform.WindowsEditor)? "%1 %2 %3 %4 %5 %6 %7 %8 %9" : "$*"; var cmd = string.Format(kCommandStr, appCmd, FileUtility.ProjectPathWithSlash(), kCommandMethod, argPass); var ext = (Application.platform == RuntimePlatform.WindowsEditor)? "bat" : "sh"; var cmdFile = string.Format(kCommandName, ext); var destinationPath = FileUtility.PathCombine(Model.Settings.Path.CUISpacePath, cmdFile); Directory.CreateDirectory(Model.Settings.Path.CUISpacePath); File.WriteAllText(destinationPath, cmd); AssetDatabase.Refresh(); }
private string PrepareOutputDirectory(BuildTarget target, Model.NodeData node, AssetReference a) { var outputOption = (OutputOption)m_outputOption [target]; if (outputOption == OutputOption.CreateInSelectedDirectory) { return(Path.Combine("Assets", m_outputDir [target])); } if (outputOption == OutputOption.CreateInCacheDirectory) { return(FileUtility.EnsureCacheDirExists(target, node, kCacheDirName)); } var sourceDir = Path.GetDirectoryName(a.importFrom); return(FileUtility.PathCombine(sourceDir, m_outputDir [target])); }
static public void SaveAssetGenerateInfo(AssetGenerator.GeneratorEntry entry, Model.NodeData node, BuildTarget target, AssetReference asset) { var cacheDir = FileUtility.EnsureCacheDirExists(target, node, AssetGenerator.kCacheDirName); var generateInfoDir = FileUtility.PathCombine(cacheDir, entry.m_id); if (!Directory.Exists(generateInfoDir)) { Directory.CreateDirectory(generateInfoDir); } var generatorInfoPath = FileUtility.PathCombine(generateInfoDir, asset.fileNameAndExtension + ".asset"); var version = AssetGeneratorUtility.GetVersion(entry.m_instance.ClassName); var info = ScriptableObject.CreateInstance <AssetGenerateInfo>(); info.Initialize(entry.m_instance.ClassName, entry.m_instance[target], version, asset); AssetDatabase.CreateAsset(info, generatorInfoPath); }
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; } bool isAnyAssetGenerated = false; foreach (var entry in m_entries) { var generator = entry.m_instance.Get <IAssetGenerator>(target); UnityEngine.Assertions.Assert.IsNotNull(generator); foreach (var ag in incoming) { foreach (var assets in ag.assetGroups.Values) { foreach (var a in assets) { var assetOutputDir = PrepareOutputDirectory(target, node, a); var assetSaveDir = FileUtility.PathCombine(assetOutputDir, GetGeneratorIdForSubPath(target, entry)); var assetSavePath = FileUtility.PathCombine(assetSaveDir, a.fileName + generator.GetAssetExtension(a)); if (!File.Exists(assetSavePath) || AssetGenerateInfo.DoesAssetNeedRegenerate(entry, node, target, a)) { if (!Directory.Exists(assetSaveDir)) { Directory.CreateDirectory(assetSaveDir); } if (!generator.GenerateAsset(a, assetSavePath)) { throw new AssetGraphException( $"{node.Name} :Failed to generate asset for {entry.m_name}"); } if (!File.Exists(assetSavePath)) { throw new AssetGraphException( $"{node.Name} :{entry.m_name} returned success, but generated asset not found."); } AssetProcessEventRecord.GetRecord().LogModify(AssetDatabase.AssetPathToGUID(assetSavePath)); isAnyAssetGenerated = true; LogUtility.Logger.LogFormat(LogType.Log, "{0} is (re)generating Asset:{1} with {2}({3})", node.Name, assetSavePath, AssetGeneratorUtility.GetGUIName(entry.m_instance.ClassName), AssetGeneratorUtility.GetVersion(entry.m_instance.ClassName)); if (progressFunc != null) { progressFunc(node, $"Creating {assetSavePath}", 0.5f); } AssetGenerateInfo.SaveAssetGenerateInfo(entry, node, target, a); } } } } } if (isAnyAssetGenerated) { AssetDatabase.Refresh(); } }
public override void Prepare(BuildTarget target, Model.NodeData node, IEnumerable <PerformGraph.AssetGroups> incoming, IEnumerable <Model.ConnectionData> connectionsToOutput, PerformGraph.Output Output) { ValidateAssetGenerator(node, target, incoming, () => { throw new NodeException("AssetGenerator is not specified.", "Select generator from inspector.", node); }, () => { throw new NodeException("Failed to create AssetGenerator from settings.", "Fix AssetGenerator settings from inspector", node); }, (AssetReference badAsset) => { throw new NodeException($"Generator not create asset from source : Source: {badAsset.importFrom}", "Remove source asset from node input.", node); }, (AssetReference badAsset) => { throw new NodeException($"Can not import incoming asset {badAsset.fileNameAndExtension}.", "Remove source asset from node input.", node); } ); if (incoming == null) { return; } if (connectionsToOutput == null || Output == null) { return; } var allOutput = new Dictionary <string, Dictionary <string, List <AssetReference> > >(); foreach (var outPoints in node.OutputPoints) { allOutput[outPoints.Id] = new Dictionary <string, List <AssetReference> >(); } var defaultOutputCond = connectionsToOutput.Where(c => c.FromNodeConnectionPointId == m_defaultOutputPointId); Model.ConnectionData defaultOutput = null; if (defaultOutputCond.Any()) { defaultOutput = defaultOutputCond.First(); } foreach (var ag in incoming) { if (defaultOutput != null) { Output(defaultOutput, ag.assetGroups); } foreach (var groupKey in ag.assetGroups.Keys) { foreach (var a in ag.assetGroups[groupKey]) { foreach (var entry in m_entries) { var assetOutputDir = PrepareOutputDirectory(target, node, a); var generator = entry.m_instance.Get <IAssetGenerator>(target); UnityEngine.Assertions.Assert.IsNotNull(generator); var newItem = FileUtility.PathCombine(assetOutputDir, GetGeneratorIdForSubPath(target, entry), a.fileName + generator.GetAssetExtension(a)); var output = allOutput[entry.m_id]; if (!output.ContainsKey(groupKey)) { output[groupKey] = new List <AssetReference>(); } output[groupKey].Add(AssetReferenceDatabase.GetReferenceWithType(newItem, generator.GetAssetType(a))); } } } } foreach (var dst in connectionsToOutput) { if (allOutput.ContainsKey(dst.FromNodeConnectionPointId)) { Output(dst, allOutput[dst.FromNodeConnectionPointId]); } } }
private void Export(BuildTarget target, Model.NodeData node, IEnumerable <PerformGraph.AssetGroups> incoming, IEnumerable <Model.ConnectionData> connectionsToOutput, Action <Model.NodeData, string, float> progressFunc) { if (incoming == null) { return; } var exportPath = GetExportPath(m_exportPath[target]); if (m_exportOption[target] == (int)ExportOption.DeleteAndRecreateExportDirectory) { if (Directory.Exists(exportPath)) { FileUtility.DeleteDirectory(exportPath, true); } } if (m_exportOption[target] != (int)ExportOption.ErrorIfNoExportDirectoryFound) { if (!Directory.Exists(exportPath)) { Directory.CreateDirectory(exportPath); } } var report = new ExportReport(node); var cacheFolderDepth = Model.Settings.Path.BundleBuilderCachePath.Split(Model.Settings.UNITY_FOLDER_SEPARATOR).Length; foreach (var ag in incoming) { foreach (var groupKey in ag.assetGroups.Keys) { var inputSources = ag.assetGroups[groupKey]; foreach (var source in inputSources) { var destinationSourcePath = source.importFrom; string destination = null; if (m_flattenDir[target] == 0) { // in bundleBulider, use platform-package folder for export destination. if (destinationSourcePath.StartsWith(Model.Settings.Path.BundleBuilderCachePath)) { var splitted = destinationSourcePath.Split(Model.Settings.UNITY_FOLDER_SEPARATOR); var reducedArray = new string[splitted.Length - cacheFolderDepth]; Array.Copy(splitted, cacheFolderDepth, reducedArray, 0, reducedArray.Length); var fromDepthToEnd = string.Join(Model.Settings.UNITY_FOLDER_SEPARATOR.ToString(), reducedArray); destinationSourcePath = fromDepthToEnd; } destination = FileUtility.PathCombine(exportPath, destinationSourcePath); } else { destination = FileUtility.PathCombine(exportPath, source.fileNameAndExtension); } var parentDir = Directory.GetParent(destination).ToString(); if (!Directory.Exists(parentDir)) { Directory.CreateDirectory(parentDir); } if (File.Exists(destination)) { File.Delete(destination); } if (string.IsNullOrEmpty(source.importFrom)) { report.AddErrorEntry(source.absolutePath, destination, "Source Asset import path is empty; given asset is not imported by Unity."); continue; } try { if (progressFunc != null) { progressFunc(node, string.Format("Copying {0}", source.fileNameAndExtension), 0.5f); } File.Copy(source.importFrom, destination); report.AddExportedEntry(source.importFrom, destination); } catch (Exception e) { report.AddErrorEntry(source.importFrom, destination, e.Message); } source.exportTo = destination; } } } AssetBundleBuildReport.AddExportReport(report); }
public override void OnInspectorGUI(NodeGUI node, AssetReferenceStreamManager streamManager, NodeGUIEditor editor, Action onValueChanged) { if (m_loadPath == null) { return; } EditorGUILayout.HelpBox("Load From Directory: Load assets from given directory path.", MessageType.Info); editor.UpdateNodeName(node); GUILayout.Space(10f); bool bRespondAP = EditorGUILayout.ToggleLeft("Respond To Asset Change", m_respondToAssetChange); if (bRespondAP != m_respondToAssetChange) { using (new RecordUndoScope("Remove Target Load Path Settings", node, true)) { m_respondToAssetChange = bRespondAP; } } GUILayout.Space(4f); //Show target configuration tab editor.DrawPlatformSelector(node); using (new EditorGUILayout.VerticalScope(GUI.skin.box)) { var disabledScope = editor.DrawOverrideTargetToggle(node, m_loadPath.ContainsValueOf(editor.CurrentEditingGroup), (bool b) => { using (new RecordUndoScope("Remove Target Load Path Settings", node, true)) { if (b) { m_loadPath[editor.CurrentEditingGroup] = m_loadPath.DefaultValue; m_loadPathGuid[editor.CurrentEditingGroup] = m_loadPathGuid.DefaultValue; } else { m_loadPath.Remove(editor.CurrentEditingGroup); m_loadPathGuid.Remove(editor.CurrentEditingGroup); } onValueChanged(); } }); using (disabledScope) { var path = m_loadPath[editor.CurrentEditingGroup]; EditorGUILayout.LabelField("Load Path:"); string newLoadPath = null; newLoadPath = editor.DrawFolderSelector(Model.Settings.Path.ASSETS_PATH, "Select Asset Folder", path, FileUtility.PathCombine(Model.Settings.Path.ASSETS_PATH, path), (string folderSelected) => { return(NormalizeLoadPath(folderSelected)); } ); var dirPath = Path.Combine(Model.Settings.Path.ASSETS_PATH, newLoadPath); if (newLoadPath != path) { using (new RecordUndoScope("Load Path Changed", node, true)){ m_loadPath[editor.CurrentEditingGroup] = newLoadPath; m_loadPathGuid [editor.CurrentEditingGroup] = AssetDatabase.AssetPathToGUID(dirPath); onValueChanged(); } } bool dirExists = Directory.Exists(dirPath); GUILayout.Space(10f); using (new EditorGUILayout.HorizontalScope()) { using (new EditorGUI.DisabledScope(string.IsNullOrEmpty(newLoadPath) || !dirExists)) { GUILayout.FlexibleSpace(); if (GUILayout.Button("Highlight in Project Window", GUILayout.Width(180f))) { // trailing is "/" not good for LoadMainAssetAtPath if (dirPath[dirPath.Length - 1] == '/') { dirPath = dirPath.Substring(0, dirPath.Length - 1); } var obj = AssetDatabase.LoadMainAssetAtPath(dirPath); EditorGUIUtility.PingObject(obj); } } } if (!dirExists) { var parentDirPath = Path.GetDirectoryName(dirPath); bool parentDirExists = Directory.Exists(parentDirPath); if (parentDirExists) { EditorGUILayout.LabelField("Available Directories:"); string[] dirs = Directory.GetDirectories(parentDirPath); foreach (string s in dirs) { EditorGUILayout.LabelField(s); } } } } } }
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 dstPath = GetDestinationPath(m_destinationPath[target]); if (m_destinationOption[target] == (int)DestinationDirectoryOption.DeleteAndRecreateExportDirectory) { if (Directory.Exists(dstPath)) { FileUtility.DeleteDirectory(dstPath, true); } } if (m_destinationOption[target] != (int)DestinationDirectoryOption.ErrorIfNoExportDirectoryFound) { if (!Directory.Exists(dstPath)) { Directory.CreateDirectory(dstPath); } } var opTypeName = m_operationType == FileOperationType.Copy ? "Copy" : "Move"; var isDestinationWithinProject = dstPath.StartsWith(Application.dataPath); var projectPathLength = Directory.GetParent(Application.dataPath).ToString().Length + 1; foreach (var ag in incoming) { foreach (var groupKey in ag.assetGroups.Keys) { var inputSources = ag.assetGroups[groupKey]; foreach (var source in inputSources) { var destination = FileUtility.PathCombine(dstPath, GetReducedPath(source)); var parentDir = Directory.GetParent(destination).ToString(); if (!Directory.Exists(parentDir)) { Directory.CreateDirectory(parentDir); } if (File.Exists(destination)) { File.Delete(destination); } if (string.IsNullOrEmpty(source.importFrom)) { continue; } try { progressFunc?.Invoke(node, $"{opTypeName} {source.fileNameAndExtension}", 0.5f); if (m_operationType == FileOperationType.Copy) { if (source.isProjectAsset && isDestinationWithinProject) { var relativePath = destination.Substring(projectPathLength); AssetDatabase.CopyAsset(source.importFrom, relativePath); } else { File.Copy(source.importFrom, destination); } } else { if (source.isProjectAsset && isDestinationWithinProject) { var relativePath = destination.Substring(projectPathLength); AssetDatabase.MoveAsset(source.importFrom, relativePath); } else { File.Move(source.importFrom, destination); } } } catch (Exception) { // ignored } } } } }
public override void Prepare(BuildTarget target, Model.NodeData node, IEnumerable <PerformGraph.AssetGroups> incoming, IEnumerable <Model.ConnectionData> connectionsToOutput, PerformGraph.Output Output) { // BundleBuilder do nothing without incoming connections if (incoming == null) { return; } var bundleOutputDir = PrepareOutputDirectory(target, node, false, true); var bundleNames = incoming.SelectMany(v => v.assetGroups.Keys).Distinct().ToList(); var bundleVariants = new Dictionary <string, List <string> >(); // get all variant name for bundles foreach (var ag in incoming) { foreach (var name in ag.assetGroups.Keys) { if (!bundleVariants.ContainsKey(name)) { bundleVariants[name] = new List <string>(); } var assets = ag.assetGroups[name]; foreach (var a in assets) { var variantName = a.variantName; if (!bundleVariants[name].Contains(variantName)) { bundleVariants[name].Add(variantName); } } } } // add manifest file var manifestName = GetManifestName(target, node, true); bundleNames.Add(manifestName); bundleVariants[manifestName] = new List <string>() { "" }; if (connectionsToOutput != null && Output != null) { UnityEngine.Assertions.Assert.IsTrue(connectionsToOutput.Any()); var outputDict = new Dictionary <string, List <AssetReference> >(); outputDict[key] = new List <AssetReference>(); foreach (var name in bundleNames) { foreach (var v in bundleVariants[name]) { string bundleName = (string.IsNullOrEmpty(v))? name : name + "." + v; AssetReference bundle = AssetReferenceDatabase.GetAssetBundleReference(FileUtility.PathCombine(bundleOutputDir, bundleName)); AssetReference manifest = AssetReferenceDatabase.GetAssetBundleReference(FileUtility.PathCombine(bundleOutputDir, bundleName + Model.Settings.MANIFEST_FOOTER)); outputDict[key].Add(bundle); outputDict[key].Add(manifest); } } var dst = (connectionsToOutput == null || !connectionsToOutput.Any())? null : connectionsToOutput.First(); Output(dst, outputDict); } }
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 builder = m_instance.Get <IPrefabBuilder>(target); UnityEngine.Assertions.Assert.IsNotNull(builder); var prefabOutputDir = PrepareOutputDirectory(target, node); Dictionary <string, List <AssetReference> > output = null; if (Output != null) { output = new Dictionary <string, List <AssetReference> >(); } var aggregatedGroups = new Dictionary <string, List <AssetReference> >(); foreach (var ag in incoming) { foreach (var key in ag.assetGroups.Keys) { if (!aggregatedGroups.ContainsKey(key)) { aggregatedGroups[key] = new List <AssetReference>(); } aggregatedGroups[key].AddRange(ag.assetGroups[key].AsEnumerable()); } } var anyPrefabCreated = false; foreach (var key in aggregatedGroups.Keys) { var assets = aggregatedGroups[key]; var allAssets = LoadAllAssets(assets); GameObject previousPrefab = null; //TODO var prefabFileName = builder.CanCreatePrefab(key, allAssets, previousPrefab); var prefabSavePath = FileUtility.PathCombine(prefabOutputDir, prefabFileName + ".prefab"); if (!Directory.Exists(Path.GetDirectoryName(prefabSavePath))) { Directory.CreateDirectory(Path.GetDirectoryName(prefabSavePath)); } if (!File.Exists(prefabSavePath) || PrefabBuildInfo.DoesPrefabNeedRebuilding(prefabOutputDir, this, node, target, key, assets)) { UnityEngine.GameObject obj = builder.CreatePrefab(key, allAssets, previousPrefab); if (obj == null) { throw new AssetGraphException(string.Format("{0} :PrefabBuilder {1} returned null in CreatePrefab() [groupKey:{2}]", node.Name, builder.GetType().FullName, key)); } LogUtility.Logger.LogFormat(LogType.Log, "{0} is (re)creating Prefab:{1} with {2}({3})", node.Name, prefabFileName, PrefabBuilderUtility.GetPrefabBuilderGUIName(m_instance.ClassName), PrefabBuilderUtility.GetPrefabBuilderVersion(m_instance.ClassName)); if (progressFunc != null) { progressFunc(node, string.Format("Creating {0}", prefabFileName), 0.5f); } PrefabUtility.CreatePrefab(prefabSavePath, obj, m_replacePrefabOptions); PrefabBuildInfo.SavePrefabBuildInfo(prefabOutputDir, this, node, target, key, assets); GameObject.DestroyImmediate(obj); anyPrefabCreated = true; AssetProcessEventRecord.GetRecord().LogModify(AssetDatabase.AssetPathToGUID(prefabSavePath)); } UnloadAllAssets(assets); if (anyPrefabCreated) { AssetDatabase.SaveAssets(); } if (output != null) { output[key] = new List <AssetReference> () { AssetReferenceDatabase.GetPrefabReference(prefabSavePath) }; } } if (Output != null) { var dst = (connectionsToOutput == null || !connectionsToOutput.Any())? null : connectionsToOutput.First(); Output(dst, output); } }
private string GetLoaderFullLoadPath(BuildTarget g) { return(FileUtility.PathCombine(Application.dataPath, m_searchFilter[g])); }
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)); }