Пример #1
0
    private static void SetHight(NodeValue nodeValue)
    {
        RectT rect = nodeValue.position;

        rect.height        = 95;
        nodeValue.position = rect;
    }
Пример #2
0
        private Rect GetChildBound()
        {
            Vector2 min = new Vector2(float.MaxValue, float.MaxValue);
            Vector2 max = new Vector2(float.MinValue, float.MinValue);

            for (int i = 0, imax = RectT.childCount; i < imax; i++)
            {
                RectTransform child = RectT.GetChild(i) as RectTransform;
                if (child == outline)
                {
                    continue;
                }
                Vector3[] corners = new Vector3[4];
                child.GetWorldCorners(corners);
                min.x = Mathf.Min(min.x, corners[0].x, corners[2].x);
                min.y = Mathf.Min(min.y, corners[0].y, corners[2].y);
                max.x = Mathf.Max(max.x, corners[0].x, corners[2].x);
                max.y = Mathf.Max(max.y, corners[0].y, corners[2].y);
            }
            Vector3 lmin = RectT.InverseTransformPoint(min);
            Vector3 lmax = RectT.InverseTransformPoint(max);

            lmin.x = Mathf.Min(lmin.x, 0f);
            lmin.y = Mathf.Min(lmin.y, 0f) - gaping.y;
            lmax.x = Mathf.Max(lmax.x, 0f) + gaping.x;
            lmax.y = Mathf.Max(lmax.y, 0f);
            return(new Rect(lmin.x, lmin.y, lmax.x - lmin.x, lmax.y - lmin.y));
        }
        public void OnEndDrag(PointerEventData data)
        {
            IsBeingDragged = false;
            // Reset the scale, because there seems to be a bug that alters the scale when the element is reparented.
            RectT.localScale = Vector3.one;
            RectT.sizeDelta  = originalSize;
            var slot = GetNearestAllowedSlot();

            if (slot != null)
            {
                var slotT    = useSlotParentForOverlapChecks ? slot.parent as RectTransform : slot.transform as RectTransform;
                var slotRect = slotT.GetScreenRect(GUIManager.DefaultCanvas);
                var iconRect = RectT.GetScreenRect(GUIManager.DefaultCanvas);
                if (slotRect.Overlaps(iconRect) || RectTransformUtility.RectangleContainsScreenPoint(slotT, Input.mousePosition))
                {
                    PlaceIntoSlot(slot);
                }
                else
                {
                    Restore();
                }
            }
            else
            {
                Restore();
            }
        }
    // 绘制线
    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);
        Handles.color = Color.white;
    }
Пример #5
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)
                    {
                        if (null != BehaviorManager.behaviorNodeAddChild)
                        {
                            BehaviorManager.behaviorNodeAddChild(currentNode.id, nodeValue.id);
                        }
                    }

                    // 取消连线状态
                    makeTransitionMode = false;
                }
                else
                {
                    NodeValue nodeValue = GetMouseInNode(nodeList);
                    if (BehaviorManager.behaviorChangeSelectId != null)
                    {
                        int nodeId = (null != nodeValue) ? nodeValue.id : -1;
                        BehaviorManager.behaviorChangeSelectId(nodeId);
                    }
                }
            }

            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);
        }
    }
Пример #6
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);
    }
Пример #7
0
    // 添加节点
    private void AddNode(Node_Draw_Info_Item info, Vector3 mousePosition, int openSubTreeId)
    {
        NodeValue newNodeValue = new NodeValue();

        newNodeValue.id = GetNewNodeId();
        if (_behaviorTreeData.rootNodeId < 0)
        {
            _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;

        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);
            }
        }
    }
        public void OnBeginDrag(PointerEventData data)
        {
            if (allowOnlyLeftClickDragging && data.button != PointerEventData.InputButton.Left)
            {
                return;
            }
            IsBeingDragged = true;
            RemoveFromSlot();
            // This hack prevents the grid layout from messing up with the position when the item is reparented.
            var gridLayout = RectT.parent.GetComponent <GridLayoutGroup>();

            if (gridLayout != null)
            {
                gridLayout.enabled = false;
            }
            RectT.SetParent(GUIManager.DefaultCanvas.transform, worldPositionStays: true);
            if (gridLayout != null)
            {
                gridLayout.enabled = true;
            }
            RectT.SetToScreenPosition(GUIManager.DefaultCanvas, data.position);
            RectT.sizeDelta = originalSize * sizeMultiplier;
        }
 protected void Reparent(Transform parent)
 {
     RectT.SetParent(parent, worldPositionStays: false);
     RectT.Center();
 }