示例#1
0
    private void OnMouseOver()
    {
        Vector2Int oldPosition;

        if (Input.GetMouseButtonDown(1))//right Click
        {
            myEncounter.SelectTileOnRightClick(MapPosition);
        }

        if (Input.GetMouseButtonDown(0))
        {//For Left Clicks
            switch (myTileState)
            {
            case TileState.Empty:
                break;

            case TileState.Blocked:
                break;

            case TileState.Ally:
                break;

            case TileState.Enemy:
                myEncounter.OnEnemyTileClick(MapPosition);
                break;

            case TileState.Deployable:
                oldPosition = myEncounter.Friends[myEncounter.SelectedFriendIndex].MapPosition;
                if (oldPosition.x >= 0)
                {
                    myEncounter.BattleFieldTiles[oldPosition.x, oldPosition.y].ChangeState(4);    // make the old position available.
                }
                myEncounter.MoveSelectedCharacterTo(MapPosition, 0);
                ChangeState(2);    //Place Ally here
                myEncounter.CycleSelFriend(true);
                break;

            case TileState.ThreatenedAndMovable:
            case TileState.Movable:
                oldPosition = myEncounter.Friends[myEncounter.SelectedFriendIndex].MapPosition;
                if (oldPosition.x >= 0)
                {
                    myEncounter.BattleFieldTiles[oldPosition.x, oldPosition.y].ChangeState(0);    // make the old position available.
                }
                myEncounter.MoveSelectedCharacterTo(MapPosition, 0);
                int movementTotal = Mathf.Abs(oldPosition.x - MapPosition.x) + Mathf.Abs(oldPosition.y - MapPosition.y);
                myEncounter.Friends[myEncounter.SelectedFriendIndex].Movement -= movementTotal;
                myEncounter.OnPlayerMovement();
                ChangeState(2);    //Place Ally here
                break;

            case TileState.Threatened:
                mySR.color = Color.yellow;
                break;

            case TileState.Attackable:
                if (myEncounter.Friends[myEncounter.SelectedFriendIndex].Movement > 0)
                {
                    myEncounter.AttackFoeAt(MapPosition);
                    myEncounter.OnPlayerMovement();
                    mySR.color = Color.magenta;
                }
                else
                {
                    Debug.Log("not Enough Movement Left.");
                }
                break;

            case TileState.InRange:

                mySR.color = Color.Lerp(Color.red, Color.white, .5f);
                break;

            default:
                break;
            }
        }
    }