Ejemplo n.º 1
0
        internal void CreateAndLoadAsset(string pathName)
        {
            AssetDatabase.CreateAsset(m_AssetModel as Object, AssetDatabase.GenerateUniqueAssetPath(pathName));
            m_AssetModel.CreateGraph(Path.GetFileNameWithoutExtension(pathName), m_Template.StencilType);
            m_Template?.InitBasicGraph(m_AssetModel.GraphModel);

            m_CommandDispatcher?.Dispatch(new LoadGraphAssetCommand(m_AssetModel));
        }
Ejemplo n.º 2
0
        public void SetCurrentSelection(IGraphAssetModel graphAssetModel, OpenMode mode, GameObject boundObject = null)
        {
            var windows = (GraphViewEditorWindow[])Resources.FindObjectsOfTypeAll(typeof(GraphViewEditorWindow));

            // Only the last focused editor should try to answer a change to the current selection.
            if (s_LastFocusedEditor != GetInstanceID() && windows.Length > 1)
            {
                return;
            }

            var currentOpenedGraph = CommandDispatcher?.State?.WindowState.CurrentGraph ?? default;

            // don't load if same graph and same bound object
            if (CommandDispatcher?.State?.WindowState.AssetModel != null &&
                graphAssetModel == currentOpenedGraph.GetGraphAssetModel() &&
                currentOpenedGraph.BoundObject == boundObject)
            {
                return;
            }

            var graphAssetFilePath = graphAssetModel.GetPath();
            var fileId             = graphAssetModel.GetFileId();

            // If there is not graph asset, unload the current one.
            if (string.IsNullOrWhiteSpace(graphAssetFilePath) || fileId == 0)
            {
                return;
            }

            // Load this graph asset.
            CommandDispatcher?.Dispatch(new LoadGraphAssetCommand(graphAssetFilePath, fileId, PluginRepository, boundObject));

            if (GraphView?.GraphModel?.AssetModel != null)
            {
                UpdateDirtyState(GraphView.GraphModel.AssetModel.Dirty);
            }

            if (mode != OpenMode.OpenAndFocus)
            {
                return;
            }

            // Check if an existing window already has this asset, if yes give it the focus.
            foreach (var window in windows)
            {
                if (window.CommandDispatcher.State.WindowState.AssetModel == graphAssetModel)
                {
                    window.Focus();
                    return;
                }
            }
        }
        protected void AddInitializationField()
        {
            VisualElement initializationElement = null;

            if (Model is IVariableDeclarationModel variableDeclarationModel)
            {
                if (variableDeclarationModel.InitializationModel == null)
                {
                    var stencil = (Stencil)CommandDispatcher.State.WindowState.GraphModel.Stencil;
                    if (stencil.RequiresInitialization(variableDeclarationModel))
                    {
                        initializationElement = new Button(OnInitializationButton)
                        {
                            text = "Create Init value"
                        };
                    }
                }
                else
                {
                    initializationElement = InlineValueEditor.CreateEditorForConstant(
                        View,
                        null,
                        variableDeclarationModel.InitializationModel,
                        (_, v) =>
                    {
                        CommandDispatcher.Dispatch(new UpdateConstantValueCommand(variableDeclarationModel.InitializationModel, v, null));
                    },
                        false);
                }
            }

            if (initializationElement != null)
            {
                AddRow("Initialization", initializationElement, rowInitValueUssClassName);
            }
        }
 protected void OnTooltipChanged(ChangeEvent <string> evt)
 {
     CommandDispatcher.Dispatch(new UpdateTooltipCommand(Model as IVariableDeclarationModel, m_TooltipTextField.value));
 }
 protected void OnExposedChanged(ChangeEvent <bool> evt)
 {
     CommandDispatcher.Dispatch(new ExposeVariableCommand(Model as IVariableDeclarationModel, m_ExposedToggle.value));
 }
 protected void OnTypeChanged(TypeHandle handle)
 {
     CommandDispatcher.Dispatch(new ChangeVariableTypeCommand(Model as IVariableDeclarationModel, handle));
 }
 protected void OnInitializationButton()
 {
     CommandDispatcher.Dispatch(new InitializeVariableCommand(Model as IVariableDeclarationModel));
 }
 protected void OnCollapseChangeEvent(ChangeEvent <bool> evt)
 {
     CommandDispatcher.Dispatch(new CollapseNodeCommand(evt.newValue, NodeModel));
 }
Ejemplo n.º 9
0
 protected void OnCollapseButtonChange(ChangeEvent <bool> e)
 {
     CommandDispatcher.Dispatch(new CollapseVariableInBlackboard(Model as IVariableDeclarationModel, e.newValue));
 }
Ejemplo n.º 10
0
        protected virtual void OnEnable()
        {
            // When we open a window (including when we start the Editor), a new GUID is assigned.
            // When a window is opened and there is a domain reload, the GUID stays the same.
            if (m_GUID == default)
            {
                m_GUID = SerializableGUID.Generate();
            }

            var initialState = CreateInitialState();

            CommandDispatcher = new CommandDispatcher(initialState);

            PluginRepository = new PluginRepository(this);

            rootVisualElement.Clear();
            rootVisualElement.pickingMode = PickingMode.Ignore;

            m_GraphContainer = new VisualElement {
                name = "graphContainer"
            };
            m_GraphView    = CreateGraphView();
            m_MainToolbar  = CreateMainToolbar();
            m_ErrorToolbar = CreateErrorToolbar();
            m_BlankPage    = CreateBlankPage();
            m_BlankPage?.CreateUI();

            if (m_MainToolbar != null)
            {
                rootVisualElement.Add(m_MainToolbar);
            }
            // AddTracingTimeline();
            rootVisualElement.Add(m_GraphContainer);
            if (m_ErrorToolbar != null)
            {
                m_GraphView.Add(m_ErrorToolbar);
            }

            m_GraphContainer.Add(m_GraphView);

            rootVisualElement.name = "gtfRoot";
            rootVisualElement.AddStylesheet("GraphViewWindow.uss");

            // PF FIXME: Use EditorApplication.playModeStateChanged / AssemblyReloadEvents ? Make sure it works on all domain reloads.

            // After a domain reload, all loaded objects will get reloaded and their OnEnable() called again
            // It looks like all loaded objects are put in a deserialization/OnEnable() queue
            // the previous graph's nodes/edges/... might be queued AFTER this window's OnEnable
            // so relying on objects to be loaded/initialized is not safe
            // hence, we need to defer the loading command
            rootVisualElement.schedule.Execute(() =>
            {
                var lastGraphFilePath = CommandDispatcher.State.WindowState.LastOpenedGraph.GetGraphAssetModelPath();
                var lastGraphId       = CommandDispatcher.State.WindowState.LastOpenedGraph.AssetLocalId;
                if (!string.IsNullOrEmpty(lastGraphFilePath))
                {
                    try
                    {
                        CommandDispatcher.Dispatch(new LoadGraphAssetCommand(
                                                       lastGraphFilePath,
                                                       lastGraphId,
                                                       PluginRepository,
                                                       CommandDispatcher.State.WindowState.LastOpenedGraph.BoundObject,
                                                       LoadGraphAssetCommand.LoadStrategies.KeepHistory));
                    }
                    catch (Exception e)
                    {
                        Debug.LogError(e);
                    }
                }
            }).ExecuteLater(0);

            m_GraphProcessingPendingLabel = new Label("Graph Processing Pending")
            {
                name = "graph-processing-pending-label"
            };

            if (WithSidePanel)
            {
                m_SidePanel = CreateModelInspectorView();
            }

            if (m_SidePanel != null)
            {
                m_GraphContainer.Add(m_SidePanel);
            }

            rootVisualElement.RegisterCallback <AttachToPanelEvent>(OnEnterPanel);
            rootVisualElement.RegisterCallback <DetachFromPanelEvent>(OnLeavePanel);
            // that will be true when the window is restored during the editor startup, so OnEnterPanel won't be called later
            if (rootVisualElement.panel != null)
            {
                OnEnterPanel(null);
            }

            titleContent = new GUIContent("Graph Tool");

            m_LockTracker.lockStateChanged.AddListener(OnLockStateChanged);

            m_AutomaticGraphProcessor = new AutomaticGraphProcessor(PluginRepository);
            CommandDispatcher.RegisterObserver(m_AutomaticGraphProcessor);
            rootVisualElement.RegisterCallback <MouseMoveEvent>(ResetGraphProcessorTimer);

            m_GraphProcessingStatusObserver = new GraphProcessingStatusObserver(m_GraphProcessingPendingLabel, m_ErrorToolbar);
            CommandDispatcher.RegisterObserver(m_GraphProcessingStatusObserver);

            m_SidePanelObserver = new SidePanelObserver(this);
            CommandDispatcher.RegisterObserver(m_SidePanelObserver);
        }