Ejemplo n.º 1
0
        public void OnDropFailed(GraphNode eventSource, Vector2 mousePos)
        {
            ShowNodeCreationPopup(mousePos, (type) =>
            {
                var obj = ScriptableObject.CreateInstance(type) as ActionGraphNode;
                if (obj)
                {
                    obj.EditorPosition = View.GetScrollPos();
                    obj.Graph          = Asset;
                    obj.name           = $"New {type.Name}";

                    string undoName = $"Created {obj.name} node";

                    Undo.SetCurrentGroupName(undoName);
                    Undo.RecordObject(Asset, undoName);

                    GraphNode.MakeConnection(eventSource, AddNewNode(obj));

                    View.Repaint();
                }
                else
                {
                    Debug.LogErrorFormat("Unable to create node!");
                }
            });
        }
Ejemplo n.º 2
0
        public ActionGraphView()
        {
            Presenter = new ActionGraphPresenter(this);
            Nodes.OnRightClick.Reassign(data =>
            {
                var node = Nodes.AllNodes.FirstOrDefault
                           (
                    n => n.PhysicalRect.Contains(
                        (data.MousePos * Nodes.ZoomLevel)
                        )) as ActionGraphEditorNode;

                if (node != null)
                {
                    Presenter.OnNodeRightClick(node, data.MousePos);
                }
                else
                {
                    Presenter.OnRightClick(data.MousePos);
                }

                return(true);
            });

            Nodes.OnConnection.Reassign((data =>
            {
                if (data.Target != null)
                {
                    if (GraphNode.CanMakeConnection(data.Source, data.Target))
                    {
                        Presenter.OnConnectChildNode(GraphNode.MakeConnection(data.Source, data.Target));
                        return(true);
                    }
                }

                return(false);
            }));

            Nodes.OnConnection.AddPost(data =>
            {
                if (data.Target == null)
                {
                    Presenter.OnDropFailed(data.Source, data.MousePos);
                }
            });

            Nodes.OnDeleteNode.AddPost(data =>
            {
                Presenter.OnNodeDeleted(data.Node as ActionGraphEditorNode);
                Nodes.AllNodes.Remove(data.Node);
            });

            Nodes.OnSlotClicked.Reassign(data =>
            {
                Presenter.OnNodeConnectorClicked(data.Source, data.Source.Owner.GetSlotPosition(data.Source));
                return(true);
            });
        }
Ejemplo n.º 3
0
        private void ConnectNodeEditor(GraphNode parent, ActionGraphNode child)
        {
            ActionGraphEditorNode foundNode;

            if (NodeLookup.TryGetValue(child, out foundNode))
            {
                if (GraphNode.CanMakeConnection(parent, foundNode))
                {
                    GraphNode.MakeConnection(parent, foundNode);
                }
            }
            else
            {
                Debug.LogError($"Couldn't find editor node for {child.name}", child);
            }
        }
Ejemplo n.º 4
0
        public GraphNodeEditor()
        {
            AllNodes = new List <GraphNode>();
            OnDeleteNode.Reassign(data =>
            {
                foreach (GraphNode baseNode in AllNodes)
                {
                    baseNode.RemoveConnection(data.Node);
                }

                AllNodes.Remove(data.Node);

                data.Node.OnDelete();

                return(true);
            });

            OnSelectNode.Reassign(data =>
            {
                data.Node.SetSelected(true);
                SelectedNodes.Add(data.Node);
                return(true);
            });

            OnDeselectNode.Reassign(data =>
            {
                data.Node.SetSelected(false);
                SelectedNodes.Remove(data.Node);
                return(true);
            });

            OnConnection.Reassign(data =>
            {
                if (data.Target != null)
                {
                    if (GraphNode.CanMakeConnection(data.Source, data.Target))
                    {
                        GraphNode.MakeConnection(data.Source, data.Target);
                        return(true);
                    }

                    return(false);
                }

                return(false);
            });
        }