Пример #1
0
        public RectT Clone()
        {
            RectT rectT = new RectT();

            rectT.x      = this.x;
            rectT.y      = this.y;
            rectT.width  = this.width;
            rectT.height = this.height;
            return(rectT);
        }
Пример #2
0
        private RectT GetPosition(JsonData data)
        {
            float x      = int.Parse(data["x"].ToString());
            float y      = int.Parse(data["y"].ToString());
            float width  = int.Parse(data["width"].ToString());
            float height = int.Parse(data["height"].ToString());

            RectT position = new RectT(x, y, width, height);

            return(position);
        }
Пример #3
0
        // 绘制线
        public static void DrawNodeCurve(RectT start, RectT end)
        {
            Handles.color = Color.black;
            Vector3 startPos = new Vector3(start.x + start.width / 2, start.y + start.height, 0);
            Vector3 endPos   = new Vector3(end.x + end.width / 2, end.y, 0);
            //Handles.DrawLine(startPos, endPos);

            Vector3 middle = (startPos + endPos) * 0.5f;

            DrawArrow(startPos, endPos, Color.black);
            Handles.color = Color.white;
        }
Пример #4
0
        public static void DrawLabel(string msg, RectT start, RectT end)
        {
            Vector3 startPos = new Vector3(start.x + start.width / 2, start.y + start.height, 0);
            Vector3 endPos   = new Vector3(end.x + end.width / 2, end.y, 0);

            Vector2 pos = (startPos + endPos) * 0.5f;// + (endPos - startPos) * 0.1f;

            GUIStyle style = new GUIStyle();

            style.fontSize         = 20;
            style.normal.textColor = Color.green;
            Handles.Label(pos, msg, style);
        }
Пример #5
0
        // 添加节点
        public void AddNode(Node_Draw_Info_Item info, Vector3 mousePosition, int openSubTreeId)
        {
            NodeValue newNodeValue = new NodeValue();

            newNodeValue.id = GetNewNodeId();

            if (BehaviorDataController.Instance.BehaviorTreeData.rootNodeId < 0)
            {
                BehaviorDataController.Instance.BehaviorTreeData.rootNodeId = newNodeValue.id;
                newNodeValue.isRootNode = true;
            }

            newNodeValue.nodeName           = info._nodeName;
            newNodeValue.identificationName = info._identificationName;
            newNodeValue.NodeType           = (int)info._nodeType;
            newNodeValue.parentNodeID       = -1;
            newNodeValue.function           = NodeDescript.GetFunction((NODE_TYPE)info._nodeType);

            RectT rectT = new RectT();
            Rect  rect  = new Rect(mousePosition.x, mousePosition.y, rectT.width, rectT.height);

            newNodeValue.position = RectTool.RectToRectT(rect);

            newNodeValue.parentSubTreeNodeId = openSubTreeId;

            List <NodeValue> NodeList = BehaviorDataController.Instance.NodeList;

            NodeList.Add(newNodeValue);

            if (openSubTreeId >= 0)
            {
                bool hasEntryNode = false;
                for (int i = 0; i < NodeList.Count; ++i)
                {
                    if (NodeList[i].parentSubTreeNodeId == openSubTreeId &&
                        (NodeList[i].subTreeEntry))
                    {
                        hasEntryNode = true;
                        break;
                    }
                }
                if (!hasEntryNode)
                {
                    ChangeSubTreeEntryNode(newNodeValue.parentSubTreeNodeId, newNodeValue.id);
                }
            }
        }
Пример #6
0
        private void NodeMakeTransition(NodeValue currentNode, List <NodeValue> nodeList)
        {
            Event _event = Event.current;

            mousePosition = _event.mousePosition;

            if (_event.type == EventType.MouseDown)
            {
                if (_event.button == 0)  // 鼠标左键
                {
                    if (makeTransitionMode)
                    {
                        NodeValue nodeValue = GetMouseInNode(nodeList);
                        // 如果按下鼠标时,选中了一个节点,则将 新选中根节点 添加为 selectNode 的子节点
                        if (null != nodeValue && currentNode.id != nodeValue.id)
                        {
                            DataNodeHandler dataNodeHandler = new DataNodeHandler();
                            dataNodeHandler.NodeAddChild(currentNode.id, nodeValue.id);
                        }

                        // 取消连线状态
                        makeTransitionMode = false;
                    }
                    else
                    {
                        NodeValue nodeValue = GetMouseInNode(nodeList);
                        ClickNode(nodeValue);
                    }
                }

                if (_event.button == 1)  // 鼠标右键
                {
                    if ((!makeTransitionMode))
                    {
                        NodeValue nodeValue = GetMouseInNode(nodeList);
                        ShowMenu(currentNode, nodeValue);
                    }
                }
            }

            if (makeTransitionMode && currentNode != null)
            {
                RectT mouseRect = new RectT(mousePosition.x, mousePosition.y, 10, 10);
                DrawNodeCurve(currentNode.position, mouseRect);
            }
        }
Пример #7
0
 public static Rect RectTToRect(RectT rectT)
 {
     return(new Rect(rectT.x, rectT.y, rectT.width, rectT.height));
 }