Exemple #1
0
    public void OnClickNode(TreeNode node)
    {
        _Tree.Bank += 1;

        List <int> slots = node.GetFreeSlots();

        if (slots.Count == 0)
        {
            return;
        }

        BaseNode parent_node = node.Node.GetComponent <BaseNode>();

        if (parent_node.IsCreating())
        {
            return;
        }

        if (_Tree.Bank < NodeSettings[_NodeType].Price)
        {
            return;
        }
        _Tree.Bank -= NodeSettings[_NodeType].Price;

        Vector3    position = parent_node.GenerateChildPosition(slots[0]);
        Quaternion rotation = parent_node.GenerateChildRotation(slots[0]);

        TreeNode child = TreeNode.Create(_Tree, _NodeType, position, rotation);

        node.Children[slots[0]] = child.ID;
        CreateTreeNode(child, node.Node.transform);

        BaseNode base_node = child.Node.GetComponent <BaseNode>();

        child.CreateChildren(base_node.GetChildCount());

        base_node.Create();

        if (slots.Count == 1)
        {
            parent_node.OnChildFull();
        }
    }