Exemplo n.º 1
0
 public override bool InteractDragBegin(EMouseButton button, Vector2 mousePosition)
 {
     if (!IsSelected)
     {
         return(false);
     }
     if (button == EMouseButton.left)
     {
         mDragEnd = false;
         mWindow.SelectComment(this, IsSelected);
         if (mBoarders == EDragBoarder.none)
         {
             for (int i = 0; i < mWindow.CommentCanvas.ElementCount; i++)
             {
                 BehaviourCommentGUI com = mWindow.CommentCanvas.GetElement <BehaviourCommentGUI>(i);
                 if (com != null && com.IsSelected)
                 {
                     com.GetContainsTarget();
                 }
             }
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 2
0
        void ImportTreeData()
        {
            for (int i = 0; i < BehaviourAsset.m_Datas.Length; i++)
            {
                BehaviourNodeGUI node = NewNode(BehaviourAsset.m_Datas[i]);
                if (node != null)
                {
                    TreeGraph.AddNode(node);
                    TreeCanvas.AddElement(node);
                }
            }
            int id = 0;
            FilterDelegate <PaintElement> filter = (x) =>
            {
                BehaviourNodeGUI bx = x as BehaviourNodeGUI;
                return(bx != null && bx.Self.BTId == id);
            };

            for (int i = 0; i < BehaviourAsset.m_Datas.Length; i++)
            {
                BTData data = BehaviourAsset.m_Datas[i];
                id = data.m_Id;
                BehaviourNodeGUI gnode = TreeGraph.FindNode(filter) as BehaviourNodeGUI;
                if (gnode == null)
                {
                    continue;
                }
                int len = data.m_Children == null ? 0 : data.m_Children.Length;
                for (int j = 0; j < len; j++)
                {
                    id = data.m_Children[j];
                    BehaviourNodeGUI gchild = TreeGraph.FindNode(filter) as BehaviourNodeGUI;
                    if (gchild != null)
                    {
                        TreeGraph.AddPath(0, gnode, gchild);
                    }
                }
            }
            id = BehaviourAsset.m_RootNodeId;
            BehaviourNodeGUI root = TreeGraph.FindNode(filter) as BehaviourNodeGUI;

            if (root != null)
            {
                TreeGraph.AddPath(0, mRootGUI, root);
            }

            for (int i = 0; i < BehaviourAsset.m_Comments.Length; i++)
            {
                BehaviourCommentGUI comment = new BehaviourCommentGUI(this);
                comment.Comment   = BehaviourAsset.m_Comments[i].m_Comment;
                comment.LocalRect = BehaviourAsset.m_Comments[i].m_Rect;
                CommentCanvas.AddElement(comment);
            }
        }
Exemplo n.º 3
0
 public override bool InteractDrag(EMouseButton button, Vector2 mousePosition, Vector2 mouseDelta)
 {
     if (!IsSelected || EditorApplication.isPlayingOrWillChangePlaymode)
     {
         return(false);
     }
     if (button == EMouseButton.left)
     {
         Vector2 delta = mouseDelta / GlobalScale;
         if (mBoarders == EDragBoarder.none)
         {
             for (int i = 0; i < mWindow.CommentCanvas.ElementCount; i++)
             {
                 BehaviourCommentGUI com = mWindow.CommentCanvas.GetElement <BehaviourCommentGUI>(i);
                 if (com != null && com.IsSelected)
                 {
                     com.Move(delta);
                 }
             }
         }
         else if (!mEditMode)
         {
             Rect rect = LocalRect;
             if ((mBoarders & EDragBoarder.left) != 0)
             {
                 rect.xMin += delta.x;
             }
             if ((mBoarders & EDragBoarder.right) != 0)
             {
                 rect.xMax += delta.x;
             }
             if ((mBoarders & EDragBoarder.top) != 0)
             {
                 rect.yMin += delta.y;
             }
             if ((mBoarders & EDragBoarder.bottom) != 0)
             {
                 rect.yMax += delta.y;
             }
             if (rect.width > 30 && rect.height > 30)
             {
                 LocalRect = rect;
             }
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 4
0
        void ExportTreeData()
        {
            List <BTData>       nodes    = new List <BTData>();
            List <PaintElement> children = new List <PaintElement>();
            int rootId = 0;

            for (int i = 0; i < TreeCanvas.ElementCount; i++)
            {
                BehaviourNodeGUI bnode = TreeCanvas.GetElement <BehaviourNodeGUI>(i);
                if (bnode == null)
                {
                    continue;
                }
                if (TreeGraph.GetParent(0, bnode) == mRootGUI)
                {
                    rootId = bnode.Self.BTId;
                }
                BTData data = bnode.ExportNodeData(nodes);

                children.Clear();
                TreeGraph.GetAllChildren(0, bnode, children);
                GlobalUtil.Sort(children, (x, y) => x.LocalRect.center.x <= y.LocalRect.center.x ? -1 : 1);
                data.m_Children = new int[children.Count];
                for (int j = 0; j < children.Count; j++)
                {
                    BehaviourNodeGUI child = children[j] as BehaviourNodeGUI;
                    data.m_Children[j] = child == null ? 0 : child.Self.BTId;
                }
            }
            BehaviourAsset.m_RootNodeId = rootId;
            GlobalUtil.Sort(nodes, (x, y) => x.m_Id - y.m_Id);
            BehaviourAsset.m_Datas  = nodes.ToArray();
            BehaviourAsset.m_Sorted = true;

            BehaviourTreeAsset.Comment[] comments = new BehaviourTreeAsset.Comment[CommentCanvas.ElementCount];
            for (int i = 0; i < comments.Length; i++)
            {
                comments[i] = new BehaviourTreeAsset.Comment();
                BehaviourCommentGUI com = CommentCanvas.GetElement <BehaviourCommentGUI>(i);
                if (com != null)
                {
                    comments[i].m_Rect    = com.LocalRect;
                    comments[i].m_Comment = com.Comment ?? "";
                }
            }
            BehaviourAsset.m_Comments = comments;
            EditorUtility.SetDirty(BehaviourAsset);
        }
Exemplo n.º 5
0
 public void SelectComment(BehaviourCommentGUI target, bool multiselect)
 {
     for (int i = 0; i < CommentCanvas.ElementCount; i++)
     {
         BehaviourCommentGUI com = CommentCanvas.GetElement <BehaviourCommentGUI>(i);
         if (com == null)
         {
             continue;
         }
         if (com == target)
         {
             com.IsSelected = true;
         }
         else if (!multiselect)
         {
             com.IsSelected = false;
         }
     }
 }
Exemplo n.º 6
0
 bool OnGraphKeyUp(KeyCode key)
 {
     if (IsPlaying)
     {
         return(false);
     }
     if (key == KeyCode.Delete)
     {
         List <BehaviourNodeGUI> nodes = new List <BehaviourNodeGUI>();
         EditNodes((x) => { if (x.IsSelected)
                            {
                                nodes.Add(x);
                            }
                   });
         for (int i = 0; i < nodes.Count; i++)
         {
             TreeCanvas.RemoveElement(nodes[i]);
             TreeGraph.RemoveNode(nodes[i]);
         }
         return(true);
     }
     if (key == KeyCode.C)
     {
         float w  = Mathf.Abs(SelectionRect.GlobalRect.width);
         float dx = SelectionRect.GlobalRect.width < 0 ? -w : 0;
         float h  = Mathf.Abs(SelectionRect.GlobalRect.height);
         float dy = SelectionRect.GlobalRect.height < 0 ? -h : 0;
         if (w > 40 && h > 30)
         {
             Rect rect = new Rect(SelectionRect.GlobalRect.xMin + dx, SelectionRect.GlobalRect.yMin + dy, w, h);
             BehaviourCommentGUI comment = new BehaviourCommentGUI(this);
             comment.LocalRect = CommentCanvas.CalculateLocalRect(rect);
             CommentCanvas.AddElement(comment);
             SelectNodes((x) => false);
         }
     }
     return(false);
 }
Exemplo n.º 7
0
 public override bool InteractDragEnd(EMouseButton button, Vector2 mousePosition)
 {
     if (!IsSelected)
     {
         return(false);
     }
     if (button == EMouseButton.left)
     {
         mDragEnd = true;
         for (int i = 0; i < mWindow.CommentCanvas.ElementCount; i++)
         {
             BehaviourCommentGUI com = mWindow.CommentCanvas.GetElement <BehaviourCommentGUI>(i);
             if (com != null && com.IsSelected)
             {
                 com.targets.Clear();
             }
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }