Esempio n. 1
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);
            }
        }