예제 #1
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();
        }
예제 #2
0
        string GetNodePath(Object obj, uNodeRoot owner, bool fullPath = false)
        {
            string path = "";

            if (obj != null && owner != null)
            {
                path = obj.name;
                Transform transform = null;
                if (obj is GameObject)
                {
                    transform = (obj as GameObject).transform;
                }
                else if (obj is Component)
                {
                    transform = (obj as Component).transform;
                }
                if (transform != null)
                {
                    Transform parent = transform.parent;
                    while (parent != owner.transform && parent.parent != null)
                    {
                        if (parent.gameObject == owner.RootObject)
                        {
                            if (transform.parent == parent)
                            {
                                path = path.Insert(0, "StateFlow : ");
                            }
                            if (fullPath)
                            {
                                path = path.Insert(0, owner.DisplayName + " : ");
                                path = path.Insert(0, owner.gameObject.name + " : ");
                            }
                            break;
                        }
                        NodeComponent nc = parent.GetComponent <NodeComponent>();
                        if (nc != null)
                        {
                            path = path.Insert(0, nc.GetNodeName() + " : ");
                        }
                        else
                        {
                            RootObject ro = parent.GetComponent <RootObject>();
                            if (ro != null)
                            {
                                path = path.Insert(0, ro.Name + " : ");
                            }
                            else
                            {
                                path = path.Insert(0, parent.gameObject.name + " : ");
                            }
                        }
                        parent = parent.parent;
                    }
                }
            }
            return(path);
        }
예제 #3
0
        string GetNodePath(NodeComponent node, bool fullPath = false)
        {
            string path = "";

            if (node != null && node.owner != null)
            {
                path = node.GetNodeName();
                Transform parent = node.transform.parent;
                while (parent != node.owner.transform && parent.parent != null)
                {
                    if (parent.gameObject == node.owner.RootObject)
                    {
                        if (node.transform.parent == parent)
                        {
                            path = path.Insert(0, "StateFlow : ");
                        }
                        if (fullPath)
                        {
                            path = path.Insert(0, node.owner.DisplayName + " : ");
                            path = path.Insert(0, node.owner.gameObject.name + " : ");
                        }
                        break;
                    }
                    NodeComponent nc = parent.GetComponent <NodeComponent>();
                    if (nc != null)
                    {
                        path = path.Insert(0, nc.GetNodeName() + " : ");
                    }
                    else
                    {
                        RootObject ro = parent.GetComponent <RootObject>();
                        if (ro != null)
                        {
                            path = path.Insert(0, ro.Name + " : ");
                        }
                        else
                        {
                            path = path.Insert(0, parent.gameObject.name + " : ");
                        }
                    }
                    parent = parent.parent;
                }
            }
            return(path);
        }
예제 #4
0
 /// <summary>
 /// Get invoke node code.
 /// </summary>
 /// <param name="target"></param>
 /// <param name="forcedNotGrouped"></param>
 /// <returns></returns>
 public static string GetInvokeNodeCode(NodeComponent target, bool forcedNotGrouped = false)
 {
     if (target == null)
     {
         throw new System.Exception();
     }
     if (target is Node && !(target as Node).IsFlowNode())
     {
         throw new System.Exception();
     }
     if (!forcedNotGrouped && !IsUngroupedNode(target))
     {
         return(GenerateNode(target));
     }
     if (forcedNotGrouped && !generatorData.ungroupedNode.Contains(target))
     {
         throw new uNodeException($"Forbidden to generate state code because the node: {target.GetNodeName()} is not registered as State Node.\nEnsure to register it using {nameof(CodeGenerator)}.{nameof(CodeGenerator.RegisterAsStateNode)}", target);
     }
     return(RunEvent(target));
 }
예제 #5
0
        /// <summary>
        /// Compare node state, The compared node will automatic placed to new generated function.
        /// </summary>
        /// <param name="target">The target node to compare</param>
        /// <param name="state">The compare state</param>
        /// <returns></returns>
        public static string CompareNodeState(NodeComponent target, bool?state, bool invert = false)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            string s = GetCoroutineName(target);

            if (!string.IsNullOrEmpty(s))
            {
                string result = s.Access(state == null ? "IsRunning" : state.Value ? "IsSuccess" : "IsFailure");
                if (invert)
                {
                    result = result.NotOperation();
                }
                if (!generatorData.ungroupedNode.Contains(target))
                {
                    throw new uNodeException($"Forbidden to generate state code because the node: {target.GetNodeName()} is not registered as State Node.\nEnsure to register it using {nameof(CodeGenerator)}.{nameof(CodeGenerator.RegisterAsStateNode)}", target);
                }
                return(result);
            }
            return(null);
        }