示例#1
0
        public virtual void Initialize(UGraphView owner, TransitionEvent transition)
        {
            this.transition = transition;
            AddToClassList("transition");
            this.AddStyleSheet("uNodeStyles/NativeNodeStyle");
            this.AddStyleSheet(UIElementUtility.Theme.nodeStyle);
            Initialize(owner);
            ReloadView();

            border.style.overflow = Overflow.Visible;

            titleIcon.RemoveFromHierarchy();
            m_CollapseButton.RemoveFromHierarchy();

            RegisterCallback <MouseDownEvent>((e) => {
                if (e.button == 0 && e.clickCount == 2)
                {
                    ActionPopupWindow.ShowWindow(owner.GetTopMousePosition(e), transition.Name,
                                                 (ref object obj) => {
                        object str = EditorGUILayout.TextField(obj as string);
                        if (obj != str)
                        {
                            obj             = str;
                            transition.Name = obj as string;
                            if (GUI.changed)
                            {
                                uNodeGUIUtility.GUIChanged(transition);
                            }
                        }
                    }).headerName = "Edit name";
                }
            });
        }
示例#2
0
        public override void Initialize(UGraphView owner, NodeComponent node)
        {
            this.owner = owner;
            targetNode = node;
            title      = targetNode.GetNodeName();
            titleButtonContainer.RemoveFromHierarchy();
            this.AddStyleSheet("uNodeStyles/NativeRegionStyle");
            var border = this.Q("node-border");

            border.style.overflow = Overflow.Visible;
            horizontalDivider     = border.Q("contents").Q("divider");

            comment = new Label(node.comment);
            inputContainer.Add(comment);

            titleContainer.RegisterCallback <MouseDownEvent>((e) => {
                if (e.clickCount == 2 && e.button == 0)
                {
                    ActionPopupWindow.ShowWindow(Vector2.zero, node.gameObject.name,
                                                 (ref object obj) => {
                        object str = EditorGUILayout.TextField(obj as string);
                        if (obj != str)
                        {
                            obj = str;
                            node.gameObject.name = obj as string;
                            if (GUI.changed)
                            {
                                uNodeGUIUtility.GUIChanged(node);
                            }
                        }
                    }).ChangePosition(owner.GetTopMousePosition(e)).headerName = "Rename title";
                }
            });
            RegisterCallback <MouseDownEvent>((e) => {
                if (e.button == 0)
                {
                    nodes = new List <NodeComponent>(owner.graph.nodes);
                    if (owner.graph.eventNodes != null)
                    {
                        foreach (var c in owner.graph.eventNodes)
                        {
                            if (c != null)
                            {
                                nodes.Add(c);
                            }
                        }
                    }
                    nodes.RemoveAll((n) => n == null || !targetNode.editorRect.Contains(new Vector2(n.editorRect.x + (n.editorRect.width * 0.5f), n.editorRect.y + (n.editorRect.height * 0.5f))));
                }
            });

            Add(new ResizableElement());
            this.SetSize(new Vector2(node.editorRect.width, node.editorRect.height));
            Teleport(targetNode.editorRect);
            ReloadView();
            RefreshPorts();
        }
示例#3
0
        public override void Initialize(UGraphView owner, NodeComponent node)
        {
            this.owner      = owner;
            this.targetNode = node;
            title           = targetNode.GetNodeName();
            titleButtonContainer.RemoveFromHierarchy();

            this.AddStyleSheet("uNodeStyles/NativeStickyNote");
            AddToClassList("sticky-note");

            comment = new Label(node.comment);
            inputContainer.Add(comment);
            elementTypeColor = Color.yellow;

            titleContainer.RegisterCallback <MouseDownEvent>((e) => {
                if (e.clickCount == 2)
                {
                    ActionPopupWindow.ShowWindow(Vector2.zero, node.gameObject.name,
                                                 (ref object obj) => {
                        object str = EditorGUILayout.TextField(obj as string);
                        if (obj != str)
                        {
                            obj = str;
                            node.gameObject.name = obj as string;
                            if (GUI.changed)
                            {
                                uNodeGUIUtility.GUIChanged(node);
                            }
                        }
                    }).ChangePosition(owner.GetTopMousePosition(e)).headerName = "Rename title";
                }
            });
            comment.RegisterCallback <MouseDownEvent>((e) => {
                if (e.clickCount == 2)
                {
                    ActionPopupWindow.ShowWindow(Vector2.zero, node.comment,
                                                 (ref object obj) => {
                        object str = EditorGUILayout.TextArea(obj as string);
                        if (obj != str)
                        {
                            obj          = str;
                            node.comment = obj as string;
                            if (GUI.changed)
                            {
                                uNodeGUIUtility.GUIChanged(node);
                            }
                        }
                    }, 300, 200).ChangePosition(owner.GetTopMousePosition(e)).headerName = "Edit description";
                }
            });

            //this.SetSize(new Vector2(node.editorRect.width, node.editorRect.height));
            SetPosition(targetNode.editorRect);
            RefreshPorts();
        }
示例#4
0
 public override void OnDisable()
 {
     graphPanelContainer?.RemoveFromHierarchy();
     graphPanelContainer = null;
     tabbarContainer?.RemoveFromHierarchy();
     tabbarContainer = null;
     hasInitTabbar   = false;
     graphView?.RemoveFromHierarchy();
     graphView = null;
     OnNoTarget();
 }
示例#5
0
 public void InitializeGraph()
 {
     if (graphView != null && !rootView.Contains(graphView))
     {
         graphView.RemoveFromHierarchy();
     }
     if (graphView == null)
     {
         graphView = new UGraphView();
     }
     if (!rootView.Contains(graphView))
     {
         rootView.Add(graphView);
     }
     graphView.Initialize(this);
     ReloadTabbar();
 }
示例#6
0
 /// <summary>
 /// Save the temporary graph object into the original prefab
 /// </summary>
 /// <param name="graphAsset"></param>
 /// <param name="graph"></param>
 public static void SaveGraphAsset(GameObject graphAsset, GameObject graph)
 {
     if (graph != null && graphAsset != null)
     {
         uNodeEditorUtility.UnlockPrefabInstance(EditorBinding.getPrefabParent(graph) as GameObject);
         if (graphAsset.name != graph.name)                  //Ensure the name is same.
         {
             graph.name = graphAsset.name;
         }
         {                //Reset cache data
             var roots     = (graphAsset as GameObject).GetComponents <uNodeRoot>();
             var tempRoots = (graph as GameObject).GetComponents <uNodeRoot>();
             if (roots.Length != tempRoots.Length)
             {
                 UGraphView.ClearCache();
             }
             else
             {
                 for (int i = 0; i < roots.Length; i++)
                 {
                     if (roots[i].Name != tempRoots[i].Name)
                     {
                         UGraphView.ClearCache();
                         break;
                     }
                 }
             }
         }
         uNodeEditorUtility.SavePrefabAsset(graph, graphAsset);
         var graphs = (graphAsset as GameObject).GetComponents <uNodeRoot>();
         //Reset the cache data
         foreach (var r in graphs)
         {
             if (r == null)
             {
                 continue;
             }
             var rType = ReflectionUtils.GetRuntimeType(r);
             if (rType is RuntimeGraphType graphType)
             {
                 graphType.RebuildMembers();
             }
         }
     }
 }
示例#7
0
        public static PortView GetOutputPort(MemberData inputValue, UGraphView graphView)
        {
            var outputNode = inputValue.GetTargetNode();

            if (outputNode != null)
            {
                if (inputValue.IsTargetingNode)
                {
                    switch (inputValue.targetType)
                    {
                    case MemberData.TargetType.FlowNode:
                        return(GetSelfPort(outputNode, Orientation.Vertical, graphView));

                    case MemberData.TargetType.ValueNode:
                        PortView port;
                        if (graphView.portValueNodeAliases.TryGetValue(outputNode, out port) && port != null)
                        {
                            return(port);
                        }
                        return(GetSelfPort(outputNode, Orientation.Horizontal, graphView));
                    }
                }
                UNodeView nodeView;
                if (graphView.nodeViewsPerNode.TryGetValue(outputNode, out nodeView))
                {
                    foreach (var p in nodeView.outputPorts)
                    {
                        if (p.portData.portID == inputValue.startName)
                        {
                            return(p);
                        }
                    }
                }
            }
            return(null);
        }
 public AutoHideGraphElement(UGraphView graphView)
 {
     this.graphView = graphView;
 }
示例#9
0
        protected void Initialize(UGraphView owner)
        {
            this.owner = owner;
            this.AddToClassList("node-view");
            if (!ShowExpandButton())             //Hides colapse button
            {
                m_CollapseButton.style.position = Position.Absolute;
                m_CollapseButton.style.width    = 0;
                m_CollapseButton.style.height   = 0;
                m_CollapseButton.visible        = false;
            }
            base.expanded = true;
            RegisterCallback <MouseDownEvent>(evt => {
                var mPos = (evt.currentTarget as VisualElement).GetScreenMousePosition(evt.localMousePosition, graph.window);
                if (evt.button == 0 && evt.shiftKey && !evt.altKey)
                {
                    ActionPopupWindow.ShowWindow(Vector2.zero, () => {
                        CustomInspector.ShowInspector(new GraphEditorData(graph.editorData)
                        {
                            selected = targetNode
                        });
                    }, 300, 300).ChangePosition(mPos);
                }
            });
            RegisterCallback <MouseOverEvent>((e) => {
                for (int i = 0; i < inputPorts.Count; i++)
                {
                    var edges = inputPorts[i].GetEdges();
                    foreach (var edge in edges)
                    {
                        if (edge == null)
                        {
                            continue;
                        }
                        if (edge.isProxy)
                        {
                            edge.edgeControl.visible = true;
                        }
                    }
                }
                for (int i = 0; i < outputPorts.Count; i++)
                {
                    var edges = outputPorts[i].GetEdges();
                    foreach (var edge in edges)
                    {
                        if (edge == null)
                        {
                            continue;
                        }
                        if (edge.isProxy)
                        {
                            edge.edgeControl.visible = true;
                        }
                    }
                }
            });
            RegisterCallback <MouseLeaveEvent>((e) => {
                for (int i = 0; i < inputPorts.Count; i++)
                {
                    var edges = inputPorts[i].GetEdges();
                    foreach (var edge in edges)
                    {
                        if (edge == null)
                        {
                            continue;
                        }
                        if (edge.isProxy)
                        {
                            edge.edgeControl.visible = false;
                        }
                    }
                }
                for (int i = 0; i < outputPorts.Count; i++)
                {
                    var edges = outputPorts[i].GetEdges();
                    foreach (var edge in edges)
                    {
                        if (edge == null)
                        {
                            continue;
                        }
                        if (edge.isProxy)
                        {
                            edge.edgeControl.visible = false;
                        }
                    }
                }
            });
            RegisterCallback <GeometryChangedEvent>(evt => {
                if (evt.oldRect != Rect.zero && evt.oldRect.width != evt.newRect.width)
                {
                    Teleport(new Rect(evt.newRect.x + (evt.oldRect.width - evt.newRect.width), evt.newRect.y, evt.newRect.width, evt.newRect.height));
                }
            });

            border = this.Q("node-border");
            {            //Flow inputs
                flowInputContainer      = new VisualElement();
                flowInputContainer.name = "flow-inputs";
                flowInputContainer.AddToClassList("flow-container");
                flowInputContainer.AddToClassList("input");
                flowInputContainer.pickingMode = PickingMode.Ignore;
                border.Insert(0, flowInputContainer);
            }
            {            //Flow outputs
                flowOutputContainer      = new VisualElement();
                flowOutputContainer.name = "flow-outputs";
                flowOutputContainer.AddToClassList("flow-container");
                flowOutputContainer.AddToClassList("output");
                flowOutputContainer.pickingMode = PickingMode.Ignore;
                Add(flowOutputContainer);
            }

            controlsContainer = new VisualElement {
                name = "controls"
            };
            mainContainer.Add(controlsContainer);

            titleIcon = new Image()
            {
                name = "title-icon"
            };
            titleContainer.Add(titleIcon);
            titleIcon.SendToBack();

            OnSetup();
        }
示例#10
0
 /// <summary>
 /// Initialize once on created.
 /// </summary>
 /// <param name="owner"></param>
 /// <param name="node"></param>
 public virtual void Initialize(UGraphView owner, NodeComponent node)
 {
     targetNode = node;
     Initialize(owner);
     ReloadView();
 }
示例#11
0
        public static PortView GetSelfPort(NodeComponent node, Orientation orientation, UGraphView graphView)
        {
            UNodeView nodeView;

            if (graphView.nodeViewsPerNode.TryGetValue(node, out nodeView))
            {
                if (orientation == Orientation.Horizontal)
                {
                    foreach (var p in nodeView.outputPorts)
                    {
                        if (p.orientation == orientation && p.portData.portID == UGraphView.SelfPortID)
                        {
                            return(p);
                        }
                    }
                }
                else
                {
                    foreach (var p in nodeView.inputPorts)
                    {
                        if (p.orientation == orientation && p.portData.portID == UGraphView.SelfPortID)
                        {
                            return(p);
                        }
                    }
                }
            }
            return(null);
        }
示例#12
0
 public override void Initialize(UGraphView owner, TransitionEvent transition)
 {
     handler = new BlockNodeHandler(this);
     base.Initialize(owner, transition);
 }