Exemple #1
0
    void RemoveNode(BeeHiveNode node)
    {
        node.bottonConnectorClick -= OnBottonConnectorClicked;

        node.NodeDeleted();
        nodes.Remove(node);

        selectedNode = null;
    }
Exemple #2
0
    void CreateNewNode(BH_Node nodeClass, Vector2 position)
    {
        BeeHiveNode node = ScriptableObject.CreateInstance <BeeHiveNode>();

        node.BuildNode(nodeClass, position);
        nodes.Add(node);

        node.bottonConnectorClick += OnBottonConnectorClicked;
    }
Exemple #3
0
    bool CheckForClickOnNode()
    {
        for (int i = 0; i < nodes.Count; i++)
        {
            if (nodes[i].windowRect.Contains(mousePosition))
            {
                selectedNode = nodes[i];
                return(true);
            }
        }

        return(false);
    }
Exemple #4
0
    public void Callback(object obj)
    {
        string callback = obj.ToString();

        switch (callback)
        {
        case "Selector":
            CreateNewNode(new BH_Selector(), mousePosition);
            break;

        case "Sequencer":
            CreateNewNode(new BH_Sequence(), mousePosition);
            break;

        case "Inverter":
            CreateNewNode(new BH_Inverter(), mousePosition);
            break;

        case "Succeder":
            CreateNewNode(new BH_Succeeder(), mousePosition);
            break;

        case "Repeater":
            CreateNewNode(new BH_Repeater(), mousePosition);
            break;

        case "RepeatTilFail":
            CreateNewNode(new BH_RepeatUntilFail(), mousePosition);
            break;

        case "Leaf":
            CreateNewNode(new BH_Leaf(), mousePosition);
            break;

        case "makeLink":
            makeTransitionMode = true;
            break;

        case "delete":
            RemoveNode(selectedNode);
            selectedNode = null;
            break;
        }
    }
Exemple #5
0
    void CreateNewNode(BlueprintNode bpNode)
    {
        BeeHiveNode node = ScriptableObject.CreateInstance <BeeHiveNode>();

        Vector2 position = new Vector2(bpNode.xPos, bpNode.yPos);

        node.methodName = string.Copy(bpNode.methodName);

        if (bpNode.nodeType == E_NodeType.selector)
        {
            node.BuildNode(new BH_Selector(), position);
        }
        else if (bpNode.nodeType == E_NodeType.sequencer)
        {
            node.BuildNode(new BH_Sequence(), position);
        }
        else if (bpNode.nodeType == E_NodeType.inverter)
        {
            node.BuildNode(new BH_Inverter(), position);
        }
        else if (bpNode.nodeType == E_NodeType.succeder)
        {
            node.BuildNode(new BH_Succeeder(), position);
        }
        else if (bpNode.nodeType == E_NodeType.repeater)
        {
            node.BuildNode(new BH_Repeater(), position);
        }
        else if (bpNode.nodeType == E_NodeType.repeatTilFail)
        {
            node.BuildNode(new BH_RepeatUntilFail(), position);
        }
        else if (bpNode.nodeType == E_NodeType.leaf)
        {
            node.BuildNode(new BH_Leaf(), position);
        }



        nodes.Add(node);

        node.bottonConnectorClick += OnBottonConnectorClicked;
    }
Exemple #6
0
    public BlueprintNode(BeeHiveNode bhNode)
    {
        if (bhNode.myNode is BH_Selector)
        {
            nodeType = E_NodeType.selector;
        }
        else if (bhNode.myNode is BH_Sequence)
        {
            nodeType = E_NodeType.sequencer;
        }
        else if (bhNode.myNode is BH_Inverter)
        {
            nodeType = E_NodeType.inverter;
        }
        else if (bhNode.myNode is BH_Succeeder)
        {
            nodeType = E_NodeType.succeder;
        }
        else if (bhNode.myNode is BH_Repeater)
        {
            nodeType = E_NodeType.repeater;
        }
        else if (bhNode.myNode is BH_RepeatUntilFail)
        {
            nodeType = E_NodeType.repeatTilFail;
        }
        else if (bhNode.myNode is BH_Leaf)
        {
            nodeType = E_NodeType.leaf;
        }

        methodName = string.Copy(bhNode.methodName);

        xPos = bhNode.windowRect.position.x;
        yPos = bhNode.windowRect.position.y;
    }
Exemple #7
0
 public void OnBottonConnectorClicked(object source, EventArgs args)
 {
     selectedNode       = source as BeeHiveNode;
     makeTransitionMode = true;
 }
Exemple #8
0
    void HandleInput()
    {
        Event e = Event.current;

        mousePosition = e.mousePosition;


        if (e.button == 1 && !makeTransitionMode)
        {
            if (e.type == EventType.MouseDown)
            {
                bool clickedOnNode = CheckForClickOnNode();

                if (!clickedOnNode)
                {
                    GenericMenu menu = new GenericMenu();
                    menu.AddItem(new GUIContent("Add selector"), false, Callback, "Selector");
                    menu.AddItem(new GUIContent("Add sequencer"), false, Callback, "Sequencer");
                    menu.AddItem(new GUIContent("Add inverter"), false, Callback, "Inverter");
                    menu.AddItem(new GUIContent("Add succeder"), false, Callback, "Succeder");
                    menu.AddItem(new GUIContent("Add repeater"), false, Callback, "Repeater");
                    menu.AddItem(new GUIContent("Add repeater until fail"), false, Callback, "RepeatTilFail");
                    menu.AddItem(new GUIContent("Add leaf"), false, Callback, "Leaf");
                    menu.ShowAsContext();
                    e.Use();
                }
                else
                {
                    GenericMenu menu = new GenericMenu();
                    if (!(selectedNode.myNode is BH_Leaf))
                    {
                        menu.AddItem(new GUIContent("Make link"), false, Callback, "makeLink");
                    }
                    menu.AddItem(new GUIContent("Delete"), false, Callback, "delete");
                    menu.ShowAsContext();
                    e.Use();
                }
            }
        }

        else if (e.button == 0)
        {
            if (e.type == EventType.MouseDown)
            {
                BeeHiveNode oldNode = selectedNode;

                bool clickedOnNode = CheckForClickOnNode();

                if (makeTransitionMode)
                {
                    if (clickedOnNode)
                    {
                        oldNode.AddChild(selectedNode);
                    }
                    makeTransitionMode = false;
                    e.Use();
                }
                else if (!clickedOnNode)
                {
                    dragMode     = true;
                    dragDeltaPos = e.mousePosition;
                }
            }
            if (e.type == EventType.MouseUp)
            {
                dragMode = false;

                if (selectedNode != null)
                {
                    selectedNode.SortSiblings();
                }
            }
        }

        if (makeTransitionMode && selectedNode != null)
        {
            Rect mouseRect = new Rect(e.mousePosition.x, e.mousePosition.y, 1, 1);

            DrawNodeCurve(mouseRect, selectedNode.GetBottonRect());

            Repaint();
        }
    }