コード例 #1
0
        void ObserveNow(GraphToolState state, bool forceUpdate)
        {
            using (var gvObservation = this.ObserveState(state.GraphViewState))
                using (var tsObservation = this.ObserveState(state.TracingStatusState))
                {
                    var gvUpdateType = gvObservation.UpdateType;
                    if (gvUpdateType == UpdateType.Partial)
                    {
                        // Adjust gvUpdateType if there was no modifications on the graph model
                        var changeset = state.GraphViewState.GetAggregatedChangeset(gvObservation.LastObservedVersion);
                        if (!changeset.NewModels.Any() && !changeset.ChangedModels.Any() && !changeset.DeletedModels.Any())
                        {
                            gvUpdateType = UpdateType.None;
                        }
                    }

                    if (forceUpdate || gvUpdateType.Combine(tsObservation.UpdateType) != UpdateType.None)
                    {
                        var results = state.GraphViewState.GraphModel.ProcessGraph(m_PluginRepository,
                                                                                   RequestGraphProcessingOptions.Default, state.TracingStatusState.TracingEnabled);

                        if (results != null || state.GraphProcessingState.GraphProcessingPending)
                        {
                            using (var updater = state.GraphProcessingState.UpdateScope)
                            {
                                updater.GraphProcessingPending = false;

                                if (results != null)
                                {
                                    updater.SetResults(results,
                                                       GraphProcessingHelper.GetErrors((Stencil)state.GraphViewState.GraphModel.Stencil, results));
                                }
                            }
                        }
                    }
                }
        }
コード例 #2
0
        /// <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);
            }
        }