public static AssetReferenceDatabase GetDatabase() { if (s_database == null) { if (!Load()) { // Create vanilla db s_database = ScriptableObject.CreateInstance <AssetReferenceDatabase>(); s_database.m_assets = new List <AssetReference>(); s_database.m_dictionary = new SortedList <string, AssetReference>(); s_database.m_version = DB_VERSION; var DBDir = Model.Settings.Path.SettingFilePath; if (!Directory.Exists(DBDir)) { Directory.CreateDirectory(DBDir); } AssetDatabase.CreateAsset(s_database, Model.Settings.Path.DatabasePath); } } return(s_database); }
void Load(BuildTarget target, Model.NodeData node, IEnumerable <Model.ConnectionData> connectionsToOutput, PerformGraph.Output Output) { if (connectionsToOutput == null || Output == null) { return; } // SOMEWHERE_FULLPATH/PROJECT_FOLDER/Assets/ var assetsFolderPath = Application.dataPath + Model.Settings.UNITY_FOLDER_SEPARATOR; var outputSource = new List <AssetReference>(); var targetFilePaths = FileUtility.GetAllFilePathsInFolder(GetLoaderFullLoadPath(target)); foreach (var targetFilePath in targetFilePaths) { // already contained into Assets/ folder. // imported path is Assets/SOMEWHERE_FILE_EXISTS. if (targetFilePath.StartsWith(assetsFolderPath)) { var relativePath = targetFilePath.Replace(assetsFolderPath, Model.Settings.Path.ASSETS_PATH); if (TypeUtility.IsGraphToolSystemAsset(relativePath)) { continue; } var r = AssetReferenceDatabase.GetReference(relativePath); if (r == null) { continue; } if (!TypeUtility.IsLoadingAsset(r)) { continue; } if (r != null) { outputSource.Add(r); } continue; } throw new NodeException(node.Name + ": Invalid Load Path. Path must start with Assets/", node.Name); } var output = new Dictionary <string, List <AssetReference> > { { "0", outputSource } }; var dst = (connectionsToOutput == null || !connectionsToOutput.Any())? null : connectionsToOutput.First(); Output(dst, output); }
public Dictionary <string, List <AssetReference> > ToGroupDictionary() { Dictionary <string, List <AssetReference> > dic = new Dictionary <string, List <AssetReference> >(); foreach (var g in m_groups) { dic [g.name] = g.assets.Select(a => AssetReferenceDatabase.GetReference(a)).ToList(); } return(dic); }
public static void MoveReference(string oldPath, string newPath) { AssetReferenceDatabase db = GetDatabase(); if (db.m_dictionary.ContainsKey(oldPath)) { var r = db.m_dictionary[oldPath]; db.m_dictionary.Remove(oldPath); db.m_dictionary[newPath] = r; r.importFrom = newPath; } }
public static void DeleteReference(string relativePath) { AssetReferenceDatabase db = GetDatabase(); if (db.m_dictionary.ContainsKey(relativePath)) { var r = db.m_dictionary[relativePath]; db.m_assets.Remove(r); db.m_dictionary.Remove(relativePath); SetDBDirty(); } }
void Load(BuildTarget target, Model.NodeData node, IEnumerable <Model.ConnectionData> connectionsToOutput, PerformGraph.Output Output) { if (connectionsToOutput == null || Output == null) { return; } var cond = m_searchFilter[target]; var assetsFolderPath = Application.dataPath + Model.Settings.UNITY_FOLDER_SEPARATOR; var outputSource = new List <AssetReference>(); var guids = AssetDatabase.FindAssets(cond); foreach (var guid in guids) { var targetFilePath = AssetDatabase.GUIDToAssetPath(guid); if (TypeUtility.IsGraphToolSystemAsset(targetFilePath)) { continue; } var relativePath = targetFilePath.Replace(assetsFolderPath, Model.Settings.Path.ASSETS_PATH); var r = AssetReferenceDatabase.GetReference(relativePath); if (!TypeUtility.IsLoadingAsset(r)) { continue; } if (r != null) { outputSource.Add(AssetReferenceDatabase.GetReference(relativePath)); } } var output = new Dictionary <string, List <AssetReference> > { { "0", outputSource } }; var dst = (connectionsToOutput == null || !connectionsToOutput.Any())? null : connectionsToOutput.First(); Output(dst, output); }
void Load(BuildTarget target, Model.NodeData node, IEnumerable <Model.ConnectionData> connectionsToOutput, PerformGraph.Output Output) { if (connectionsToOutput == null || Output == null) { return; } var outputSource = new List <AssetReference>(); if (m_lastImportedAssetPaths != null) { foreach (var path in m_lastImportedAssetPaths) { if (TypeUtility.IsGraphToolSystemAsset(path)) { continue; } var r = AssetReferenceDatabase.GetReference(path); if (!TypeUtility.IsLoadingAsset(r)) { continue; } if (r != null) { outputSource.Add(r); } } } var output = new Dictionary <string, List <AssetReference> > { { "0", outputSource } }; var dst = (connectionsToOutput == null || !connectionsToOutput.Any())? null : connectionsToOutput.First(); Output(dst, output); }
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { LogUtility.Logger.Log("[OnPostprocessAllAssets]"); foreach (string str in deletedAssets) { AssetReferenceDatabase.DeleteReference(str); } for (int i = 0; i < movedAssets.Length; i++) { AssetReferenceDatabase.MoveReference(movedFromAssetPaths[i], movedAssets[i]); } NotifyAssetPostprocessorGraphs(importedAssets, deletedAssets, movedAssets, movedFromAssetPaths); AssetBundleGraphEditorWindow.NotifyAssetsReimportedToAllWindows(importedAssets, deletedAssets, movedAssets, movedFromAssetPaths); }
private static AssetReference GetReference(string relativePath, CreateReference creator) { AssetReferenceDatabase db = GetDatabase(); if (db.m_dictionary.ContainsKey(relativePath)) { return(db.m_dictionary[relativePath]); } else { try { AssetReference r = creator(); db.m_assets.Add(r); db.m_dictionary.Add(relativePath, r); AssetReferenceDatabase.SetDBDirty(); return(r); } catch (AssetReferenceException) { // if give asset is invalid, return null return(null); } } }
private static bool Load() { bool loaded = false; try { var dbPath = Model.Settings.Path.DatabasePath; if (File.Exists(dbPath)) { AssetReferenceDatabase db = AssetDatabase.LoadAssetAtPath <AssetReferenceDatabase>(dbPath); if (db != null && db.m_version == DB_VERSION) { db.m_dictionary = new SortedList <string, AssetReference>(); foreach (var r in db.m_assets) { db.m_dictionary.Add(r.importFrom, r); } s_database = db; loaded = true; } else { if (db != null) { Resources.UnloadAsset(db); } } } } catch (Exception e) { LogUtility.Logger.LogWarning(LogUtility.kTag, e); } return(loaded); }
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 = FileUtility.EnsurePrefabBuilderCacheDirExists(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()); } } foreach (var key in aggregatedGroups.Keys) { var assets = aggregatedGroups[key]; var allAssets = LoadAllAssets(assets); var prefabFileName = builder.CanCreatePrefab(key, allAssets); var prefabSavePath = FileUtility.PathCombine(prefabOutputDir, prefabFileName + ".prefab"); if (!Directory.Exists(Path.GetDirectoryName(prefabSavePath))) { Directory.CreateDirectory(Path.GetDirectoryName(prefabSavePath)); } if (PrefabBuildInfo.DoesPrefabNeedRebuilding(this, node, target, key, assets)) { UnityEngine.GameObject obj = builder.CreatePrefab(key, allAssets); if (obj == null) { throw new AssetBundleGraphException(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(this, node, target, key, assets); GameObject.DestroyImmediate(obj); } UnloadAllAssets(assets); 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); } }
public override void Prepare(BuildTarget target, Model.NodeData node, IEnumerable <PerformGraph.AssetGroups> incoming, IEnumerable <Model.ConnectionData> connectionsToOutput, PerformGraph.Output Output) { ValidatePrefabBuilder(node, target, incoming, () => { throw new NodeException(node.Name + " :PrefabBuilder is not configured. Please configure from Inspector.", node.Id); }, () => { throw new NodeException(node.Name + " :Failed to create PrefabBuilder from settings. Please fix settings from Inspector.", node.Id); }, (string groupKey) => { throw new NodeException(string.Format("{0} :Can not create prefab with incoming assets for group {1}.", node.Name, groupKey), node.Id); }, (AssetReference badAsset) => { throw new NodeException(string.Format("{0} :Can not import incoming asset {1}.", node.Name, badAsset.fileNameAndExtension), node.Id); } ); if (incoming == null) { return; } var builder = m_instance.Get <IPrefabBuilder>(target); UnityEngine.Assertions.Assert.IsNotNull(builder); var prefabOutputDir = FileUtility.EnsurePrefabBuilderCacheDirExists(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()); } } foreach (var key in aggregatedGroups.Keys) { var assets = aggregatedGroups[key]; var thresold = PrefabBuilderUtility.GetPrefabBuilderAssetThreshold(m_instance.ClassName); if (thresold < assets.Count) { var guiName = PrefabBuilderUtility.GetPrefabBuilderGUIName(m_instance.ClassName); throw new NodeException(string.Format("{0} :Too many assets passed to {1} for group:{2}. {3}'s threshold is set to {4}", node.Name, guiName, key, guiName, thresold), node.Id); } List <UnityEngine.Object> allAssets = LoadAllAssets(assets); var prefabFileName = builder.CanCreatePrefab(key, allAssets); if (output != null && prefabFileName != null) { output[key] = new List <AssetReference> () { AssetReferenceDatabase.GetPrefabReference(FileUtility.PathCombine(prefabOutputDir, prefabFileName + ".prefab")) }; } UnloadAllAssets(assets); } if (Output != null) { var dst = (connectionsToOutput == null || !connectionsToOutput.Any())? null : connectionsToOutput.First(); Output(dst, output); } }
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 generatedFiles = FileUtility.GetAllFilePathsInFolder(bundleOutputDir); var manifestName = GetManifestName(target); // 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)); }
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); 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 Prepare(BuildTarget target, Model.NodeData node, IEnumerable <PerformGraph.AssetGroups> incoming, IEnumerable <Model.ConnectionData> connectionsToOutput, PerformGraph.Output Output) { ValidateAssetGenerator(node, target, incoming, () => { throw new NodeException(node.Name + " :AssetGenerator is not specified. Please select generator from Inspector.", node.Id); }, () => { throw new NodeException(node.Name + " :Failed to create AssetGenerator from settings. Please fix settings from Inspector.", node.Id); }, (AssetReference badAsset, string msg) => { throw new NodeException(string.Format("{0} :{1} : Source: {2}", node.Name, msg, badAsset.importFrom), node.Id); }, (AssetReference badAsset) => { throw new NodeException(string.Format("{0} :Can not import incoming asset {1}.", node.Name, badAsset.fileNameAndExtension), node.Id); } ); 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 = FileUtility.EnsureAssetGeneratorCacheDirExists(target, node); var generator = entry.m_instance.Get <IAssetGenerator>(target); UnityEngine.Assertions.Assert.IsNotNull(generator); var newItem = FileUtility.PathCombine(assetOutputDir, entry.m_id, 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]); } } }