예제 #1
0
    public void Update()
    {
        //Parse input from the user.
        float horiz = Input.GetAxis("Horizontal");
        float vert  = Input.GetAxis("Vertical");
        float jump  = Input.GetAxis("Jump");
        float fire  = Input.GetAxis("Close");

        float horiz_mag = Mathf.Abs(horiz);
        float vert_mag  = Mathf.Abs(vert);

        if (horiz_mag < Mathf.Abs(oldHoriz))
        {
            horiz_hasFallen = true;
        }

        if (vert_mag < Mathf.Abs(oldVert))
        {
            vert_hasFallen = true;
        }

        Direction dir = Direction.None;

        if (horiz_mag > .5 && vert_mag < .5 && horiz_hasFallen)
        {
            if (horiz > 0 && horiz > oldHoriz)
            {
                dir             = Direction.Right;
                horiz_hasFallen = false;
            }
            else if (horiz < 0 && horiz < oldHoriz)
            {
                dir             = Direction.Left;
                horiz_hasFallen = false;
            }
        }
        else if (horiz_mag < .5 && vert_mag > .5 && vert_hasFallen)
        {
            if (vert > 0 && vert > oldVert)
            {
                dir            = Direction.Up;
                vert_hasFallen = false;
            }
            else if (vert < 0 && vert < oldVert)
            {
                dir            = Direction.Down;
                vert_hasFallen = false;
            }
        }

        if (dir != Direction.None)
        {
            currentMenu.GetComponent <MoveSelector_Child>().input(dir);

            //Process change in description if it's needed.

            updateDescription();
        }

        if (jump < oldJump)
        {
            jump_hasFallen = true;
        }

        if (jump > oldJump && oldJump == 0 && takeControl)
        {
            jump_hasFallen = false;
            int          sel = currentMenu.GetComponent <MoveSelector_Child>().currentSelection;
            SelectorNode selected;

            try
            {
                selected = current.children[sel];
            }
            catch (ArgumentOutOfRangeException e)
            {
                selected = current.children[0];
            }

            if (selected.hasChildren())
            {
                if (selected.children.Count > 0)
                {
                    current = selected;
                    updateDisplay();
                }
            }
            else
            {
                if (selected.name == "run")
                {
                    GameController.player.addSelectedMove("Run");
                    return;
                }
                object selectedObj = selections[selected.name];

                if (types[selected.name] == "item")
                {
                    Item selectedItem = (Item)selections[selected.name];
                    selectedItem.affectPlayer(GameController.player);

                    GameController.player.removeItemByName(selectedItem.getName());
                    items.removeChildByName(selectedItem.getName());

                    GameController.player.addSelectedMove("Item Use");

                    current = root;
                }
                else if (types[selected.name] == "move")
                {
                    Debug.Log(selected.name);
                    GameController.player.addSelectedMove(selected.name);

                    current = root;
                }

                updateDisplay();
            }
        }

        if (fire < oldFire)
        {
            fire_hasFallen = true;
        }

        if (fire > oldFire && fire_hasFallen)
        {
            fire_hasFallen = false;
            if (current != root)
            {
                current = current.parent;
            }
            updateDisplay();
        }

        oldHoriz = horiz;
        oldVert  = vert;
        oldJump  = jump;
        oldFire  = fire;

        if (currentMenu.GetComponent <MoveSelector_Child>().type != currentType)
        {
            updateDisplay();
        }
    }