static State LoadGraphAsset(State previousState, LoadGraphAssetAction action)
        {
            if (ReferenceEquals(Selection.activeObject, previousState.AssetModel))
            {
                Selection.activeObject = null;
            }
            previousState.AssetModel?.Dispose();
            previousState.EditorDataModel.PluginRepository?.UnregisterPlugins();

            var asset = AssetDatabase.LoadAssetAtPath <GraphAssetModel>(action.AssetPath);

            if (!asset)
            {
                Debug.LogError($"Could not load visual scripting asset at path '{action.AssetPath}'");
                return(previousState);
            }
            AssetWatcher.Instance.WatchGraphAssetAtPath(action.AssetPath, asset);

            switch (action.LoadType)
            {
            case LoadGraphAssetAction.Type.Replace:
                previousState.EditorDataModel.PreviousGraphModels.Clear();
                break;

            case LoadGraphAssetAction.Type.PushOnStack:
                previousState.EditorDataModel.PreviousGraphModels.Add(new OpenedGraph((GraphAssetModel)previousState.CurrentGraphModel?.AssetModel, previousState.EditorDataModel?.BoundObject));
                break;

            case LoadGraphAssetAction.Type.KeepHistory:
                break;
            }

            previousState.AssetModel = asset;
            previousState.EditorDataModel.BoundObject = action.BoundObject;
            previousState.MarkForUpdate(UpdateFlags.All);

            var graphModel = previousState.CurrentGraphModel;

            if (graphModel?.Stencil != null)
            {
                graphModel.Stencil.PreProcessGraph((VSGraphModel)previousState.CurrentGraphModel);
                if (action.AlignAfterLoad)
                {
                    graphModel.LastChanges.ModelsToAutoAlign.AddRange(graphModel.Stencil.GetEntryPoints((VSGraphModel)graphModel));
                }
            }

            CheckGraphIntegrity(previousState);

            return(previousState);
        }
Esempio n. 2
0
        static State LoadGraphAsset(State previousState, LoadGraphAssetAction action)
        {
            if (ReferenceEquals(Selection.activeObject, previousState.AssetModel))
            {
                Selection.activeObject = null;
            }
            previousState.AssetModel?.Dispose();
            previousState.EditorDataModel.PluginRepository.UnregisterPlugins();

            var asset = AssetDatabase.LoadAssetAtPath <GraphAssetModel>(action.AssetPath);

            if (!asset)
            {
                Debug.LogError($"Could not load visual scripting asset at path '{action.AssetPath}'");
                return(previousState);
            }

            switch (action.LoadType)
            {
            case LoadGraphAssetAction.Type.Replace:
                previousState.EditorDataModel.PreviousGraphModels.Clear();
                break;

            case LoadGraphAssetAction.Type.PushOnStack:
                previousState.EditorDataModel.PreviousGraphModels.Add((GraphModel)previousState.CurrentGraphModel);
                break;

            case LoadGraphAssetAction.Type.KeepHistory:
                break;
            }

            previousState.AssetModel = asset;
            previousState.MarkForUpdate(UpdateFlags.All);

            if (previousState.CurrentGraphModel?.Stencil != null)
            {
                previousState.CurrentGraphModel.Stencil.PreProcessGraph((VSGraphModel)previousState.CurrentGraphModel);
            }

            previousState.requestNodeAlignment = action.AlignAfterLoad;

            CheckGraphIntegrity(previousState);

            return(previousState);
        }