示例#1
0
 public StateNodeCreatDropdown(StateGraphView view, StateNodeRef node, bool isOut, bool isChild) : base(view)
 {
     this.node    = node;
     this.isChild = isChild;
     this.isOut   = isChild? true : isOut;
     pos          = view.Canvas.MouseInWorld;
 }
示例#2
0
    public void OnDragEnd(StateGraphView view, Vector2 ptInWorld)
    {
        HashSet <ulong> handleNodes = new HashSet <ulong>();

        foreach (var node in view.Selecteds)
        {
            var parent = node.Node.Parent;
            if (!parent)
            {
                handleNodes.Add(node.Id);
                node.Node.SortIndex = ++view.SelectIndex;
            }
            else if (!handleNodes.Contains(parent.Id))
            {
                handleNodes.Add(parent.Id);
                parent.Node.SortIndex = ++view.SelectIndex;
                foreach (var link in view.Graph.Links)
                {
                    if (link.IsChild && link.From == parent)
                    {
                        link.To.Node.SortIndex = ++view.SelectIndex;
                    }
                }
            }
        }
        if (view.Selecteds.Count > 0)
        {
            view.SortNodes();
        }
    }
示例#3
0
 private void AddNode(StateGraphView view, StateNodeRef nodeRef)
 {
     if (movedNodes.Contains(nodeRef))
     {
         return;
     }
     movedNodes.Add(nodeRef);
     if (nodeRef.Node.Parent)
     {
         AddNode(view, nodeRef.Node.Parent);
     }
     else
     {
         foreach (var link in view.Graph.Links)
         {
             if (link.IsChild && link.From == nodeRef)
             {
                 if (!movedNodes.Contains(link.To))
                 {
                     movedNodes.Add(link.To);
                 }
             }
         }
     }
 }
示例#4
0
 public void Draw(StateGraphView view)
 {
     if (Vector2.Distance(startPos, currentPos) > 1)
     {
         view.Canvas.DrawStraightLine(startPos, currentPos, Color.yellow, 3);
         var currNode = view.HitTest(currentPos);
         if (currNode != null && currNode != node)
         {
             StateNode from;
             StateNode to;
             if (isOut)
             {
                 from = node.Node;
                 to   = currNode;
             }
             else
             {
                 to   = node.Node;
                 from = currNode;
             }
             if (view.Graph.CheckLink(from, to, isChild))
             {
                 view.Canvas.DrawArea(currNode.Bounds, Color.yellow);
             }
         }
     }
 }
示例#5
0
    public void Draw(StateGraphView view)
    {
        Vector2 size = Area.size;

        if (size.x > 2 || size.y > 2)
        {
            view.Canvas.DrawArea(Area, RectColor);
        }
    }
示例#6
0
 public ViewNormalMoveMode(StateGraphView view, Vector2 ptInWorld)
 {
     view.RegistUndo("move");
     Start = ptInWorld;
     //如果选择的节点有父节点则记录父节点,否则记录自己,方便后续移动处理
     foreach (var node in view.Selecteds)
     {
         AddNode(view, node);
     }
 }
示例#7
0
    public void OnDrag(StateGraphView view, Vector2 ptInWorld)
    {
        Vector2 offset = ptInWorld - Start;

        Start = ptInWorld;
        foreach (var node in movedNodes)
        {
            node.Node.Bounds.position += offset;
        }
    }
示例#8
0
    public void OnDrag(StateGraphView view, Vector2 ptInWorld)
    {
        view.Selecteds.Clear();
        Area.min = new Vector2(Mathf.Min(ptInWorld.x, Start.x), Mathf.Min(ptInWorld.y, Start.y));
        Area.max = new Vector2(Mathf.Max(ptInWorld.x, Start.x), Mathf.Max(ptInWorld.y, Start.y));

        view.Selecteds.Clear();
        foreach (var node in view.Graph.Nodes)
        {
            if (node.Bounds.Overlaps(Area))
            {
                view.Selecteds.Add(node);
            }
        }
    }
示例#9
0
    public void OnDragEnd(StateGraphView view, Vector2 ptInWorld)
    {
        var currNode = view.HitTest(ptInWorld);

        if (currNode == node)
        {
            if (!isChild)
            {
                return;
            }
            currNode = null;
        }
        if (currNode != null)
        {
            StateNode from;
            StateNode to;
            if (isOut)
            {
                from = node.Node;
                to   = currNode;
            }
            else
            {
                to   = node.Node;
                from = currNode;
            }
            view.CreateLink(from, to, isChild);
            view.SelectNode(currNode);
        }
        else
        {
            //此处弹出创建节点下拉窗口
            StateNodeCreatDropdown dropDown = new StateNodeCreatDropdown(view, node, isOut, isChild);
            dropDown.Show(new Rect(view.Canvas.MouseInView, new Vector2(250, 0)));
        }
    }
示例#10
0
 public StateNodeTypeDropDown(StateGraphView view) : base(new AdvancedDropdownState())
 {
     View        = view;
     minimumSize = new Vector2(300, 400);
 }
示例#11
0
    public void Draw(StateGraphView view)
    {
        ScrollPos = GUILayout.BeginScrollView(ScrollPos);
        using (new GUILayout.HorizontalScope())
        {
            GUILayout.Label("Name");
            InputName = GUILayout.TextField(InputName);
            if (!string.IsNullOrWhiteSpace(InputName) && GUILayout.Button("创建"))
            {
                if (view.Graph.Blackboard.HasName(InputName))
                {
                    EditorUtility.DisplayDialog("错误", string.Format("创建失败:已经存在 {0} 变量", InputName), "确定");
                }
                else
                {
                    view.RegistUndo("add variable");
                    view.Graph.Blackboard.Add(InputName);
                }
            }
        }

        for (int i = 0; i < view.Graph.Blackboard.Variables.Count; ++i)
        {
            using (new GUILayout.HorizontalScope("Box"))
            {
                var variable = view.Graph.Blackboard.Variables[i];
                if (!variable.ReadOnly && GUILayout.Button("", "SearchCancelButton"))
                {
                    view.RegistUndo("remove variable");
                    view.Graph.Blackboard.RemoveAt(i);
                    i--;
                    continue;
                }
                using (new GUILayout.VerticalScope())
                {
                    using (new GUILayout.HorizontalScope())
                    {
                        GUILayout.Label(variable.Name);
                        if (variable.ReadOnly)
                        {
                            GUILayout.Label(variable.DefultValue.ToString());
                        }
                        else
                        {
                            double val = EditorGUILayout.DoubleField(variable.DefultValue);
                            if (val != variable.DefultValue)
                            {
                                view.RegistUndo("modify variable defult value");
                                variable.DefultValue = val;
                            }
                        }
                    }
                    using (new GUILayout.HorizontalScope())
                    {
                        GUILayout.Label("备注", GUILayout.ExpandWidth(false));
                        if (variable.ReadOnly)
                        {
                            GUILayout.Label(variable.Commit, EditorStyles.wordWrappedLabel);
                        }
                        else
                        {
                            string commit = EditorGUILayout.TextArea(variable.Commit);
                            if (commit != variable.Commit)
                            {
                                view.RegistUndo("modify variable commit");
                                variable.Commit = commit;
                            }
                        }
                    }
                }
            }
        }
        GUILayout.EndScrollView();
    }
示例#12
0
 public ViewAreaSelectMode(StateGraphView view, Vector2 ptInWorld)
 {
     view.Selecteds.Clear();
     Area.size = Vector2.zero;
     Start     = ptInWorld;
 }
示例#13
0
 public void OnDragEnd(StateGraphView view, Vector2 ptInWorld)
 {
 }
示例#14
0
 public void Draw(StateGraphView view)
 {
 }
 public StateNodeReplaceDropdown(StateGraphView view, StateNodeRef replaceNode) : base(view)
 {
     node = replaceNode;
 }
示例#16
0
 public void OnDrag(StateGraphView view, Vector2 ptInWorld)
 {
     currentPos = ptInWorld;
 }