public static AssetProcessEventRecord GetRecord() { if (s_record == null) { if (!Load()) { // Create vanilla db s_record = ScriptableObject.CreateInstance <AssetProcessEventRecord>(); s_record.Init(); var DBDir = AssetGraphBasePath.TemporalSettingFilePath; if (!Directory.Exists(DBDir)) { Directory.CreateDirectory(DBDir); } AssetDatabase.CreateAsset(s_record, Model.Settings.Path.EventRecordPath); } } return(s_record); }
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 modifier = m_instance.Get <IModifier>(target); UnityEngine.Assertions.Assert.IsNotNull(modifier); Type targetType = ModifierUtility.GetModifierTargetType(m_instance.ClassName); bool isAnyAssetModified = false; var aggregatedGroups = new Dictionary <string, List <AssetReference> >(); 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()); } } foreach (var assets in aggregatedGroups.Values) { foreach (var asset in assets) { if (asset.assetType == targetType) { if (modifier.IsModified(asset.allData, assets)) { modifier.Modify(asset.allData, assets); asset.SetDirty(); AssetProcessEventRecord.GetRecord().LogModify(asset); isAnyAssetModified = true; // apply asset setting changes to AssetDatabase. if (asset.isSceneAsset) { if (!EditorSceneManager.SaveScene(asset.scene)) { throw new NodeException("Failed to save modified scene:" + asset.importFrom, "See console for details.", node); } } else { AssetDatabase.SaveAssets(); } } asset.ReleaseData(); } } } if (isAnyAssetModified) { AssetDatabase.Refresh(); } if (incoming != null && Output != null) { // Modifier does not add, filter or change structure of group, so just pass given group of assets var dst = (connectionsToOutput == null || !connectionsToOutput.Any())? null : connectionsToOutput.First(); Output(dst, aggregatedGroups); } }
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 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); } }
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); 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); try { m_createDescription.Reset(); var canCreatePrefab = builder.CanCreatePrefab(key, allAssets, ref m_createDescription); Assert.IsTrue(canCreatePrefab, "CanCreatePrefab() should not fail at Build phase."); } catch (Exception e) { throw new NodeException(e.Message, "See reason for detail.", node); } var prefabSavePath = FileUtility.PathCombine(prefabOutputDir, m_createDescription.prefabName + ".prefab"); if (!Directory.Exists(Path.GetDirectoryName(prefabSavePath))) { Directory.CreateDirectory(Path.GetDirectoryName(prefabSavePath)); } if (!File.Exists(prefabSavePath) || PrefabBuildInfo.DoesPrefabNeedRebuilding(prefabOutputDir, this, node, target, key, assets, m_createDescription)) { GameObject obj; GameObject previous = null; try { if (m_loadPreviousPrefab && File.Exists(prefabSavePath)) { previous = PrefabUtility.LoadPrefabContents(prefabSavePath); } obj = builder.CreatePrefab(key, allAssets, previous); } catch (Exception e) { throw new NodeException(e.Message, "See reason for detail.", node); } if (obj == null) { throw new AssetGraphException( $"{node.Name} :PrefabBuilder {builder.GetType().FullName} returned null in CreatePrefab() [groupKey:{key}]"); } LogUtility.Logger.LogFormat(LogType.Log, "{0} is (re)creating Prefab:{1} with {2}({3})", node.Name, m_createDescription.prefabName, PrefabBuilderUtility.GetPrefabBuilderGUIName(m_instance.ClassName), PrefabBuilderUtility.GetPrefabBuilderVersion(m_instance.ClassName)); progressFunc?.Invoke(node, $"Creating {m_createDescription.prefabName}", 0.5f); var isPartOfAsset = PrefabUtility.IsPartOfPrefabAsset(obj); PrefabUtility.SaveAsPrefabAsset(obj, prefabSavePath); if (previous != obj && isPartOfAsset) { PrefabUtility.UnloadPrefabContents(obj); } else { Object.DestroyImmediate(obj); } if (previous) { PrefabUtility.UnloadPrefabContents(previous); } PrefabBuildInfo.SavePrefabBuildInfo(prefabOutputDir, this, node, target, key, assets, m_createDescription); 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); } }
public DisableAssetProcessEventRecordScope() { m_oldState = AssetProcessEventRecord.GetRecord().EnabledRecording; AssetProcessEventRecord.GetRecord().EnabledRecording = false; }