コード例 #1
0
    public void OnEndDrag()
    {
        isInmotion = false;
        // Grab all nearby for this.depth() - 1, then this.depth()
        List <NodeControl> leavesOnVertical;
        List <NodeControl> leavesOnHorizontal;

        if (!CheckConstraints())
        {
            Debug.Log("Did not add skill");
            if (!CheckChildren())
            {
                this.transform.position = initPos;
            }
            else
            {
                this.transform.position = currPos;
            }
            return;
        }

        int depth = TreeEditor.S.GetDepthOf(this);

        //Debug.Log(TreeEditor.S.GetDepthOf(this));

        // Check to insert above... on success, quit out to prevent execution of anything else
        if (TreeEditor.S.leaves.TryGetValue(depth - 1, out leavesOnVertical) && leavesOnVertical.Count > 0 && this.parent == -1)
        {
            //Debug.Log("Found leaves on vertical");
            NodeControl vertNode = GetNearestNode(leavesOnVertical);
            if (!vertNode.CheckChildren((int)Constants.Branch.DOWN))
            {
                vertNode.SetChild(this);
                drawLine(vertNode, this);
                bbc.AddSkill(this.abilityName);
                return;
            }
        }

        // Check to insert left or right... on success, quit out to prevent execution of anything else
        if (TreeEditor.S.leaves.TryGetValue(depth, out leavesOnHorizontal) && leavesOnHorizontal.Count > 0 && this.parent == -1)
        {
            //Debug.Log("Found leaves on horizontal");
            NodeControl horizNode = GetNearestNode(leavesOnHorizontal);
            switch (this.CheckLeft(horizNode))
            {
            case true:
                if (!horizNode.CheckChildren((int)Constants.Branch.LEFT))
                {
                    horizNode.SetChild(this, (int)Constants.Branch.LEFT);
                    drawLine(horizNode, this);
                    bbc.AddSkill(this.abilityName);
                }

                return;

            default:
                if (!horizNode.CheckChildren((int)Constants.Branch.RIGHT) && this.parent == -1)
                {
                    horizNode.SetChild(this, (int)Constants.Branch.RIGHT);
                    drawLine(horizNode, this);
                    bbc.AddSkill(this.abilityName);
                }

                return;
            }
        }

        // On default, kick back to original position
        Debug.Log("No leaves found");
        if (!CheckChildren())
        {
            this.transform.position = initPos;
        }
        else
        {
            this.transform.position = currPos;
        }
    }