/// <summary> /// Callback for when the user clicks on a breadcrumb element. /// </summary> /// <param name="graphToLoad">The graph to load.</param> /// <param name="breadcrumbIndex">The index of the breadcrumb element clicked.</param> protected virtual void OnBreadcrumbClick(OpenedGraph graphToLoad, int breadcrumbIndex) { if (graphToLoad.GetGraphAssetModel()?.FriendlyScriptName != null) { m_CommandDispatcher.Dispatch(new LoadGraphAssetCommand(graphToLoad.GetGraphAssetModelPath(), graphToLoad.AssetLocalId, m_GraphView.Window.PluginRepository, graphToLoad.BoundObject, LoadGraphAssetCommand.LoadStrategies.KeepHistory, breadcrumbIndex)); } }
/// <inheritdoc /> public override void ValidateAfterDeserialize() { base.ValidateAfterDeserialize(); if (!m_CurrentGraph.IsValid()) { m_CurrentGraph = new OpenedGraph(null, null); } }
protected void BreadcrumbClickedEvent(int i) { var state = m_CommandDispatcher.State; OpenedGraph graphToLoad = default; var graphModels = state.WindowState.SubGraphStack; if (i < graphModels.Count) { graphToLoad = graphModels[i]; } OnBreadcrumbClick(graphToLoad, i); }
/// <inheritdoc /> public override void ValidateAfterDeserialize() { base.ValidateAfterDeserialize(); // Check that all referenced graphs still exist (assets may have been deleted). if (!m_CurrentGraph.IsValid()) { m_CurrentGraph = new OpenedGraph(null, null); } if (!m_LastOpenedGraph.IsValid()) { m_LastOpenedGraph = new OpenedGraph(null, null); } for (var i = 0; i < m_SubGraphStack.Count; i++) { if (!m_SubGraphStack[i].IsValid()) { m_SubGraphStack[i] = new OpenedGraph(null, null); } } }
/// <summary> /// Default command handler. /// </summary> /// <param name="graphToolState">The state.</param> /// <param name="command">The command.</param> public static void DefaultCommandHandler(GraphToolState graphToolState, LoadGraphAssetCommand command) { if (ReferenceEquals(Selection.activeObject, graphToolState.WindowState.AssetModel)) { Selection.activeObject = null; } if (graphToolState.WindowState.GraphModel != null) { var graphProcessingStateComponent = graphToolState.GraphProcessingState; // force queued graph processing to happen now when unloading a graph if (graphProcessingStateComponent.GraphProcessingPending) { // Do not force graph processing if it's the same graph if ((command.AssetPath != null && graphToolState.WindowState.AssetModel.GetPath() != command.AssetPath) || (command.Asset != null && graphToolState.WindowState.AssetModel != command.Asset)) { GraphProcessingHelper.ProcessGraph(graphToolState.WindowState.GraphModel, command.PluginRepository, RequestGraphProcessingOptions.Default, graphToolState.TracingStatusState.TracingEnabled); } using (var graphProcessingStateUpdater = graphToolState.GraphProcessingState.UpdateScope) { graphProcessingStateUpdater.GraphProcessingPending = false; } } } using (var windowStateUpdater = graphToolState.WindowState.UpdateScope) { if (command.TruncateHistoryIndex >= 0) { windowStateUpdater.TruncateHistory(command.TruncateHistoryIndex); } switch (command.LoadStrategy) { case LoadStrategies.Replace: windowStateUpdater.ClearHistory(); break; case LoadStrategies.PushOnStack: windowStateUpdater.PushCurrentGraph(); break; case LoadStrategies.KeepHistory: break; } var asset = command.Asset; if (asset == null) { asset = OpenedGraph.Load(command.AssetPath, command.FileId); } if (asset == null) { Debug.LogError($"Could not load visual scripting asset at path '{command.AssetPath}'"); return; } graphToolState.LoadGraphAsset(asset, command.BoundObject); var graphModel = graphToolState.WindowState.GraphModel; ((Stencil)graphModel?.Stencil)?.PreProcessGraph(graphModel); CheckGraphIntegrity(graphToolState); } }